Welcome! Log In Create A New Profile


GCode Feedrate Help

Posted by ZachHoeken 
GCode Feedrate Help
February 22, 2008 08:49PM

So I'm implementing the GCode feedrate option. Basically it works like this: you can send a gcode command like this:

G1 X30 Y90 Z55 F20

Assuming we're in incremental mode as well as millimeters as units, this means:

move x+30mm, y+90mm, z+55mm at a rate of 20mm/minute on a straight line.

here are the variables i'm working with:

* steps/mm = 100 (constant in program)
* mm/minute = 20 (from the parameter)
* ticks/minute = 960,000,000 (processor ticks per minute at 16mhz (on arduino))

at the lowest level on the arduino, stepper speed is measured as processor ticks between steps. you can also do milliseconds and/or microseconds, but the ticks is the lowest common denominator.

moving on, here is the equation i came up with:

steps/minute = 100 steps/mm * 20 mm/minute = 2000 steps/minute
ticks/step = 960,000,000 ticks/minute / (2000 steps/minute) = 480,000 ticks/step

this works great... if you're only moving on one axis. however, chances are good that i will want to move in more than one axis. generally this will usually be x and y at the same time, but theres also the chance that i will need to move in all 3 directions at once.

here's where i'm hazy. my intuition tells me i need to slow down the step rate to account for the fact that multiple steppers will be going. the question is by how much.

going with my gut again, i think... well find the distance between point a and point b in 3D space. once i have that, get a ratio between the total distance and the biggest delta (ie... the axis that will be stepping each time.)

i figure once i have that, then i could do something like multiply the step delay by the ratio of line distance : max_delta to get the true stepper speed.

a quick google reveals this link that tells how to calculate the length of a 3D line: [www.ultrashock.com]

which brings me to my summary:

1. are my inital calculations for step delay correct?
2. is my intuition correct on finding that distance ratio and multiplying it with the step delay to get true delay?
3. are there any shortcuts to implementing the square and square root functions on a microprocessor? i know the arduino can handle it if needed, but i'd rather not, ya know?

thanks in advance,
Re: GCode Feedrate Help
February 22, 2008 09:55PM
Hey Zach,

To take your example, "G1 X30 Y90 Z55 F20", the line you're following will be sqrt(30^2+90^2+55^2), which is about 109.659 mm long and you want to do it at 20 mm/min, so it should take 5.483 minutes to move 30 mm in x, 90 mm in y, 55 mm in z. So just apply the fact again that it's linear motion to get a velocity and therefore a step frequency for each axis (I got 547.15 steps/minute eg for x, then keep applying the equations you gave). At that point I would think it's just a matter of watching the ticks with a trigger variable for each axis, that's incremented by the frequency when the counter triggers and steps one of the motors. I wouldn't worry about the square root and just use whatever library routine is available, since it only has to be done once for the whole operation.

Great developments with all this new software, I'm looking forward to using it!

Re: GCode Feedrate Help
February 22, 2008 10:20PM
ah yes, i like your reasoning there. it seems very solid. i think with that in mind i can figure out the step rate for the 'master' axis and from there its simply a matter of setting the right delay and doing the normal DDA motion.

next up: arc's. who wants a piece of the pi? winking smiley

Re: GCode Feedrate Help
February 23, 2008 03:20PM
I not 100% sure but i think the standard is to have the F = mm/s or inch/min depending on units used. But mm/s is more intuitive you can sort of count and see it in your mind much easier (well I can)

Re: GCode Feedrate Help
February 24, 2008 05:18PM
gcode has 2 time measurements: units/minute (mm or inch depending on which mode is set) or inverse time. i'm not sure how inverse time works (yet) but we can safely focus on teh first one for now.

if you're in units/minute mode then the gcode F20 mean 20 units/minute. its not something we can fudge... its in the spec.
Re: GCode Feedrate Help
February 24, 2008 10:12PM
A really decent implementation for sqrt is in the wikipedia @ [en.wikipedia.org]

Under the binary implementation, it's an implementation I've used on small micros for nearly 20 years so I know it's good.
Re: GCode Feedrate Help
February 25, 2008 09:58PM
good news!

1. sqrt() is a function in the arduino environment (or part of avr-gcc most likely)
2. i've got a 'first-shot' feedrate implementation that seems to work! (i timed it an it works like a charm.)

check it out via subversion.

Re: GCode Feedrate Help
April 02, 2008 10:34AM
to learn how to use g-code to programing for a jop
Cinserly Yours
joseph davides
Re: GCode Feedrate Help
April 02, 2008 10:36AM
vatnito learn how to use g-code to programing for a jop
Cinserly Yours
joseph davides
Sorry, only registered users may post in this forum.

Click here to login