printipi icon indicating copy to clipboard operation
printipi copied to clipboard

Emulate M20-M32

Open Wallacoloo opened this issue 10 years ago • 2 comments

M.S. via e-mail, reproduced here:

What if we emulated M20-M32 (all of the sdcard functionality) using the filesystem? It would allow the use of the standard octoprint front end, but would allow the firmware to parse, validate, pre-compute acceleration and inverse kinematics, and encode the print as a nice binary stream. All of the IO and trajectory planning overhead should pretty much go away...

The major downside to such a scheme is a somewhat inefficient use of disk space (octoprint already saves things to disk...) but a judicious application of zlib could solve that, at the expense of cpu overhead.

Wallacoloo avatar Sep 26 '14 07:09 Wallacoloo

Emulating M20-M32 would be fairly trivial. You could even set it to read from the same directory where Octoprint stores its files (~/.octoprint/uploads) to avoid some unnecessary disk usage.

One downside to this is that you no longer have the gcode visualizer that Octoprint provides.

The upside (among others) is that you bypass a fairly significant overhead which Octoprint introduces when streaming gcode to the host - it has its own gcode parser, because it needs to keep track of which coordinate modes you're using in order to allow to manually control the printer correctly - thus, when you command the printer to move a relative distance, Octoprint won't know whether to set the mode back to absolute or relative after the motion is complete. A pretty minor loss, if you ask me.

So yes, I think implementing M20-M32 is a good idea for the immediate performance gains. I'm not sure what the cpu usage of Octoprint gcode streaming is, but I will benchmark it later.

So your idea - is it to pre-process the entire file before even beginning a print? Or to essentially cache the computations to disk in real-time during a print in order to reduce cpu load whenever the part is re-printed?

Wallacoloo avatar Sep 26 '14 07:09 Wallacoloo

Began implementing M20 today, and somewhat surprisingly, C++ still has no standard interface for listing a directory. Opening and reading files can be done cross-platform. Looks like the best way to do directory iteration is to use the posix interface and just use dirent.h (a posix file interface emulator for Windows, and potentially other OS's?) on other systems. There's also https://github.com/cxong/tinydir/blob/master/tinydir.h

Wallacoloo avatar Oct 04 '14 03:10 Wallacoloo