Rather than Arduino and ESP8266, I wonder if ESP14 might work as a GCODE interpreter. Mmm...looks like a job for Forth, so I got hold of eForth (for the STM8) from another hackaday.io project (thanks to Thomas @TG9541 - see https://hackaday.io/project/16097-eforth-for-cheap-stm8s-value-line-gadgets). It looks like the GCODE interpreter is going to be about 3K of code on top of about 4.5K of eForth. Not a fancy interpreter by any means but it'll work (I believe).
I decided to implement each GCODE command as a Forth word. For example, the GCODE M17 command is to enable the motors, and has no parameters. Its implementation is trivial, as follows:
: M17;
\ enable motors
motorsOn
;
GCODE interpretation rules generally say to quietly ignore any GCODE command that does not apply to the particular machine, but Forth typically aborts operation if an unknown command is received. So, we want to change the outer interpreter. This is easy in eForth, thus:
\ GCODE interpreter
\ no prompt; ignore undefined words
: GEV ( -- )
NAME? IF EXECUTE ELSE DROP THEN ;
and include the following in the initialisation routine \ change interpreter over for GCODE
' GEV 'EVAL !
The forward kinematics and reverse kinematics routines are coded but untested. I've had a lot of fun with VARIABLEs and have finally reached a good way forward for this project. Just a little more coding and then some serious testing on ESP14, with both CPUs running Forth. Now that will be fun!
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.
A really smart idea of re-using the Forth outer interpreter! Nice!
Edit: if you use this method on STM8EF, please be aware of COMPIQ which tests if 'EVAL points to $INTERPRET :-)
Are you sure? yes | no
@Thomas, thanks for heads up. I had to dig to find out why prompt disappeared after using another interpreter and that's when I found COMPIQ. The good news is that using FILE means that the prompt reappears (as 0x0b, of course). Maybe consider removing the state-dependent test in .OK and making the relevant routines change the prompt to do-nothing.
Are you sure? yes | no
Re-using composing words of the interpreter can be complicated by the HAS_CPNVM feature. I guess that some words, like COMPIQ, will require minor changes, e.g. test for "not $COMPILE" instead of "$INTERPRET".
Are you sure? yes | no