Hello everyone
I have been very busy lately rewriting the RepRap Arduino G-code firmware for purposes in fact not directly related to RepRap (PCB milling and other subtractive processes), but which I think will be interesting and useful to people here. Therefore I am posting my efforts. The main improvements are as follows;
1. Stepper control is done in an interrupt routine controlled by a hardware timer, allowing for smoother stepping with more accurate feedrates. Most importantly, this means stepping is synchronous whereas reading and interpreting G-code is synchronous. This is important for point (3) below.
2. Acceleration - the steppers will smoothly accelerate from a standing stop up to the desired speed, at a rate set in the _init.pde file. They will also decelerate at the end of the move. This means much smoother movement and fewer lost steps when moving at high velocities (most of all with G0 moves).
3. Lookahead - the system will read and process the next move while a move is being made. If the next move is reasonably parallel with the preceding move (decided by looking at the change in velocity in each axis and comparing with a constant in _init.pde) then it will not decelerate but continue in one smooth move. This means that something like
G0 X10
G0 X20
G0 X30
will execute as one move equivalent to
G0 X30
with minimal pausing between moves.
4. Improved arcs - I was rather stung by some criticism that I received for my earlier G2 and G3 (arc) code for the RepRap firmware. Therefore I have rewritten it using an implementation of the midpoint circle algorithm, meaning that arc moves are now true arcs with step-level accuracy. Helical moves (arc with simultaneous Z-axis movements) are also supported, and arcs work correctly with the lookahead feature.
5. Faster reading and processing of G-codes
6. True G0 moves - for G0 moves, movement will now be carried out with maximum speed in the dominant axis. Before, the maximum speed applied to the move as a whole, so that diagonal moves were being carried out at below maximum speed.
7. Completely separate metric and inch constants - all the constants in _init.pde are defined for both millimetres and inches. Of course in reality, I suppose most people will only use one or the other.
8. Various minor bugfixes etc.
There's a few things to be borne in mind. Firstly, I don't have an extruder on my machine so I have been unable to test that the extruder/fan etc. is still working. I haven't really touched much in this code but I would appreciate if someone could verify that this is OK.
Secondly, it has been a real struggle to get all this to fit inside the 14.5k or so available on the Arduino. Therefore, there some possibly hard-to-read sections of code where readability has been sacrificed for size (and sometimes speed). I have commented the code as best I can but please don't complain that it's not the neatest piece of programming ever. Also, I have included optimised versions of several routines from the Arduino code in optimal_routines.pde - by doing this, about 1k has been saved.
Thirdly, I work with metric units. I have done some basic testing with inches but not as extensively. Again I would appreciate feedback here.
Fourthly, make sure to set up the constants in _init.pde properly. For example, if you had a maximum feedrate of 1000mm/min with the old firmware, it will not actually have gone that fast because the delay between steps would have been smaller than the time to take them. With the new code, the hardware timer will actually try to take steps at this rate and your motors will very likely stall. So be prepared to adjust your settings. My motors stall in any case at anything faster that about 300mm/min so I have no idea if the code can handle anything faster than that.
Please, please, please try this out and give some (constructive) feedback. I can understand if people say "half of this is quite unnecessary for RepRap" but it is all things which I have needed for my own work, and which perhaps might be useful to others too.
I would recommend the most up-to-date version of the Arduino software since I had some problems with function prototypes in earlier versions.
All the best,
Chris Meighan
[
www.chrismeighan.com]