Wallacoloo / printipi

3d printing directly through the Raspberry Pi's GPIO pins
MIT License
141 stars 43 forks source link

Make AxisHomeStepper a routine, not a type #54

Closed Wallacoloo closed 9 years ago

Wallacoloo commented 9 years ago

Homing can really be seen as a higher-level function than just stepping motors at precise intervals and watching the endstops. Instead, it should be thought of as a relative linear movement made while watching the endstops (for a delta bot, anyway).

In this case, the CoordMap should have a function called home(), which delegates the appropriate movements to the State, which in turn directs the LinearAxisSteppers (rather than AxisHomeSteppers). The LinearAxisSteppers behave almost exactly how they usually would, but the movement buffer is shortened significantly and the endstops are checked before each step.

Wallacoloo commented 9 years ago

The most difficult part of turning this into a routine is managing the asynchronous behavior in an (intentionally) single-threaded application.

A simple home routine consists of:

More complicated homing routines might home each axis individually, or even perform some auto-leveling steps.

The best way to wait for the movement to complete might actually be to make the 2nd step appear to block until the movement is complete. The state would enter another event loop (such that the stacktrace would show two different stack frames that are both in the event loop function), and set a flag instructing it to exit the event loop after the current move completes. Once it exited the second event loop, the flag would be reset and control would immediately return to the homing routine, but the homing routine would still later return control to the first event loop.

Bypassing leveling/bounds checking is best done through flags to the State's / motionPlanner's moveTo functions.

Wallacoloo commented 9 years ago

Implemented in devel & passes all tests, but not verified on an actual machine.