Welcome! Log In Create A New Profile

Advanced

[BETA] Lightweight command-line control software

Posted by Ralith 
[BETA] Lightweight command-line control software
July 24, 2009 09:04AM
I've long been frustrated with the high resource requirements posed by the Java control software used on the official software stack (and at least one unofficial stack, in ReplicatorG), ad my machine has only 512MB of RAM. This ultimately means I can't run both Java and my web browser in parallel; frustrating at best, and often counterproductive, such as when I want to refer to documentation. As anyone who's hung out long in IRC knows, I frequently toss around ideas for solutions to this problem, but that did't do anyone much good—so, finally, I decided to do something about it, completed an all-nighter and can now present to you my first go at a simple, straightforward, command-line tool for dumping gcode files to a RepRap machine connected via serial port, designed and implemented with the UNIX philosophy in mind—that is, optimized to do one thing and do it well, and be easily scripted and integrated with other tools. For example, I imagine it would be straightforward to add a 'print' button to Skeinforge based on this.

I've made the source code available on github for ease of access and reliability of hosting; I'm licensing it under the BSD license, which amounts to, roughly, "Do whatever you like, just give me credit for my work." Compiling and installing the tool should be simple; all you need is cmake and a system that's reasonably POSIX-compliant—that is, any Linux, most UNIXes, and probably even Mac OSX. I would be interested to hear from anyone who thinks they know how to get it onto Windows, but I unfortunately lack the knowledge to do so myself.

I've done some testing of this myself on my Ponoko RepStrap, where all appeared well, but it's perfectly possible that I've overlooked something serious; if something doesn't seem to work right, let me know and provide as much information as possible and I'll do my best to fix it. Please note that there is NO input validation; don't feed the program weird binary data and expect it to work properly, and please don't do so while aiming it at your RepRap.

The gcode dumper tool, while intended for use with RepRaps, should work on any machine which takes line-delimited instructions over a serial connection and responds "ok\r\n" when they've been executed. Put simply, this means it will probably work the same on anything that runs or behaves like recent official RepRap firmware, including McWires and Cupcakes. No promises, though, especially if your firmware's unusual.

Finally, there will be more to come. Because this one utility has already covered the fiddly bits of serial I/O, I hope to be able to take the base I've formed here and put together a complete exerciser/manual control tool to complement it, allowing these tools to be used in place of the official Java host software for everything but actual gcode generation. Because the approach I'm taking with these utilities is extremely light on resource requirements, these tools will be fully functional and responsive even on lightweight embedded hardware, allowing RepRaps to be driven from just about any device you can run Linux on—even a router or a phone, so long as you can find a way to connect the (usb)serial line. In theory, although I'm not sure this is advisable, one could even remote-control one's RepRap through standard mechanisms such as ssh, or a web interface that might take advantage of the tool's deliberately scriptable nature. Perhaps of more practical interest, this code will run quite happily on minimal hardware such as the OLPC.

I hope this is as useful to some of you as I imagine it could be. Have at it!

Here's the source code URL again in case any of you missed it in that wall of text. I'll see if I can upload Linux binaries somewhere once more testing's been done, by myself and/or whoever feels inclined to compile the code.

Edit: A few usage notes: After installation, the gcode dumper can be called as "rru-gcode dump [gcode file]" where is e.g. /dev/ttyUSB0, and [gcode file] is whatever you want to send to the machine. The tool also has some support for interactive usage; run it without a [gcode file] argument, and it will bring up a > prompt where you can enter gcode to be executed manually. For the scripting-inclined, you can also pipe gcode directly into the tool, just don't forget to specify the serial device. There are currently three other options: -s , which uses an alternate serial linespeed (the default is what works on my gen2 sanguino), -q for 'quiet' mode which prints nothing to stdout and only prints to stderr if an error is encountered, and -v for 'verbose' mode which prints everything sent to and received from the machine.

Note that pressing Ctrl-C (SIGINT) is reasonably well handled, and while the tool won't make decisions for you such as halting the extruder or turning off its heater, it will stop sending instructions, clean up after itself, and exit as quickly as possible, which, during my limited testing, resulted in the RepRap ceasing movement almost immediately. SIGTERM (what kill sends by default) is handled similarly.

Another edit: I'm not sure what's a reasonable longest-sane-operation for a RepRap. Currently, the gcode dumper will time out if the RepRap doesn't respond within 30 seconds; if 30 seconds is too short, the timeout can be changed by modifying the value of TIMEOUT_MSECS defined near the top of gcode-dump/gcode-dump.c and recompiling.



I've now completed a simple gcode generator intended for use with the dump tool. Combined, they allow one to quickly and easily issue commands to the RepRap without worrying about getting gcode syntax correct. For example, to order a linear move to coordinates 14,27,34 then zero the X and Y axes then move to 10,10,10 then back to the home position on a machine connected to /dev/ttyUSB0, one might issue:
rru-gcode-gen -l 14:27:34 -z xy -l 10:10:10 -l 0:0:0 | rru-gcode-dump /dev/ttyUSB0
Commas are now also supported for coordinate delimiters (i.e. -l 10,10,10 would be valid), but colons remain recommended as they are much harder to confuse with the period in a noninteger value.

Because the gcode is simply printed on the tool's standard output, you can omit the part after and including the | to see the gcode that would be executed instead of sending it to the machine, or even use > to redirect it to a file for easily creating reusable gcode scripts that could be later fed into rru-gcode-dump on their own, or even used as input for other gcode-related tools.

Options exist for rapid positioning (G0), linear movement and speed control (G1), dwell (G4), switching units to inches and to mm (G20, G21), switching to relative or absolute positioning (G90, G91), turning the extruder on, reverse, or off (M101, M102, M103), setting extruder temperature (M104), setting extruder speed (M108), and automatically zeroing any combination of axes (G1 + G92). I'm open to suggestions for additional functionality, as new commands can be added with relative ease at this point—and I'd certainly like to hear if I've gotten any of my gcode syntax wrong, as I'm not certain the wiki pages I referred to are at all up to date.

That covers the immediate voids I felt needed filling; if anyone has any other relatively straightforward command-line RepRap software needs, I'd be interested to hear them.



Linux binaries for both tools are now available. No installation or configuration necessary. Let me know if anything doesn't work.

Also, I've added code to rru-gcode-dump to try to automatically guess a likely USB serial device. If you have multiple USB serial devices connected, I strongly advise you explicitly specify the correct one, but if you've only got the RepRap, then it *should* find it. This means you might be able to get away without passing any arguments to rru-gcode-dump at all.

Edited 9 time(s). Last edit at 07/26/2009 10:42PM by Ralith.
Re: [BETA] Lightweight command-line control software
July 28, 2009 04:31AM
I think this is probably bump-worthy: Experimental windows binaries are now available. Please test, especially rru-gcode-dump.exe; the win32 serial comms API is rather unintuitive, and I can't easily experiment on it here. rru-gcode-gen.exe should work fine. Remember that the tools must be ran from within a console to be very useful. If anything goes wrong, post the full command line you entered and all output from the tool.

I've also updated the linux binaries with miscellaneous bugfixes. Most notably, rru-gcode-dump will now wait until it's certain the RepRap is ready to receive input before sending the data you provide. Note also that rru-gcode-dump's syntax has changes slightly; if you want to specify a file, you must now pass -f filename instead of just the filename.

Edited 2 time(s). Last edit at 07/28/2009 04:32AM by Ralith.
Sorry, only registered users may post in this forum.

Click here to login