joostn/Firmware — pull request #1 by joostn (2014-08-21 11:19:55+00:00)
Title: Fixed the ORIGIN function

And this pull requests fixes the other problem I'm encountering with the current firmware: the ORIGIN function did not work. After setting the origin, the head would crash into the top when running a file or during subsequent MOVEs.

Now I'm aware this is a large patch, and it's never funny if anyone completely messes up your own code. But I had to do some refactorings in order to get this to work and make the code understandable:

In LaosMotion I've made a clear distinction between relative and absolute coordinates. For example, moveTo() has been split into two functions:
moveToAbsolute(x,y,z) moves to an absolute coordinate
and
moveToRelativeToOrigin(x,y,z) moves to a coordinate relative to the set origin.

Similarly I've added getCurrentPositionRelativeToOrigin() and getCurrentPositionAbsolute(),
getPlannedPositionRelativeToOrigin() and getPlannedPositionAbsolute().

Initially home coordinate and origin are the same. Pressing the ORIGIN button changes this, as if the current position is the home position. This effectively means that the current position becomes the top left coordinate of the workpiece, i.e. (0,0) in VisiCut.

Secondly, LaosMotion::write() no longer directly calls into the planner to make moves, but rather uses the above moveToRelativeToOrigin(). In other words all simplecode is now interpreted relative to the set origin.

Finally I couldn't resist to do a bit of cleanup by removing some static/global variables. For example, LaosMenu maintained its own x,y,z variables to keep the position of the head during MOVE. I've changed this into calls to LaosMotion to get the current position and then move to the new position, thus no longer maintaining its own state.