Effect of lengthening the servo thread period?

More
17 May 2025 18:00 #328644 by pgf
I'm using a Raspberry Pi 4 to drive a Mesa 7i96.   For unknown (as yet) reasons, I can't reliably run without errors unless I bump SERVO_PERIOD to 2000000 (i.e., 2ms).

What affect will this have on machine operation?  I sort of understand what's scheduled to run in the base thread, which of course is largely (completely?) irrelevant now that I have the Mesa.  But I don't have a good mental model for what runs in the servo thread, so I don't have a good understanding of what happens to operation/performance if it only runs half as often as usual.  Where would the difference show up?

Until recently my mill maxed out at about 40ipm, so absolute performance wasn't really a consideration.  I've upgraded to a machine capable of at least 80ipm using Grbl, and initial tests with LinuxCNC and the Mesa card indicate 100ipm may be fine.  So now I'm wondering if I need to start worrying more about that servo thread.

paul

Please Log in or Create an account to join the conversation.

  • tommylight
  • tommylight's Avatar
  • Away
  • Moderator
  • Moderator
More
17 May 2025 19:08 #328649 by tommylight
Replied by tommylight on topic Effect of lengthening the servo thread period?
I do not think you have to worry about it, it just updates everything 500 times per second instead of the usual 1000 times per second. Probably changes nothing in the step generation part as it's done on the Mesa, but might raise the time to halt the machine from 1ms theoretically (practically 2-3ms) to 2ms theoretically (guessing 4 to 6ms), and since those are still way to short time intervals, i do not think there is a situation where one would save the machine and the other would break it.
Either way reaction time of normal mortals is in the half second to a full second range, minus the Formula 1 drivers, those must be gifted with some fast reflexes, otherwise the Formula 1 would be a race to who crashes last, not 2 hours of extreme stress, be if physical or mental. :)

Please Log in or Create an account to join the conversation.

More
17 May 2025 19:47 #328650 by pgf
Okay. I wasn't sure whether it could cause stuttering of some sort, if the commands to the Mesa weren't sent in time.

My naive mental image is that the Mesa service routine is called from the servo thread, and it sends multiple commands like "Step X +25 times and Y +10 times" during each call. And I assume the Mesa maintains a queue of such commands, and the servo thread needs to run often enough for that queue to never become empty prematurely.

So the answer might involve knowing how big a buffer the Mesa has for that queue, and whether the minimum execution time for a bunch of very quick commands in that queue is shorter than the servo period.

Please Log in or Create an account to join the conversation.

More
17 May 2025 19:50 #328651 by pgf
I meant to add:

But I'm more than happy with your answer! :-)

Please Log in or Create an account to join the conversation.

  • tommylight
  • tommylight's Avatar
  • Away
  • Moderator
  • Moderator
More
17 May 2025 19:59 #328652 by tommylight
Replied by tommylight on topic Effect of lengthening the servo thread period?
You will most probably get stuttering if you do not also set the P value to 500 for each joint/axis in the ini file.
Those two are strictly related for normal stepper systems, for 1 million servo period the P value is 1000, for 2 million servo period the P value is 500, for half million servo period the P value is 2000, and so on.
And i am pretty sure Mesa controllers do not use buffers for the motion control in the normal sense of "mach3" boards, might use for IO, but i never checked, after over 10 years of using Mesa boards (probably over 80 by now) and never ever having a single issue with them, and most are on industrial machines in use 10 hours a day every day (never turn off, though), and having tailor made firmware to my needs, and having the best support on Earth, i absolutely stopped worrying about it.
:)
The following user(s) said Thank You: pgf

Please Log in or Create an account to join the conversation.

More
17 May 2025 20:45 - 17 May 2025 22:25 #328657 by PCW
With Mesa hardware (and most external hardware step/dir interfaces
or even EtherCAT drives), the velocity (step rate in this case) is updated
every servo thread.

This means that there is a constant velocity between updates. This constant
velocity means that that you will  have a small error (chord error) between a
desired curved path and the actual (linear interpolated) path.

This error is usually insignificant for most CNC machines at a 1 or 2 ms
servo thread period and typical CNC machine acceleration values.

For machines that are precise and fast (say with linear motors) you would likely
need  a faster than 1 KHz servo thread (or parabolic or cubic interpolation)

If you want to calculate the chord error here are some equations (at least for circles)

Chord error polygon vs circle =
R (1-cos(180/N))

R = radius
N = sides

R = Minimum Radius= V^2/A
N  = Sides = T_Circle/T_Sample

(a minimum radius circle at full speed is the worst case)

Using an example of 1 IPS (~25 mm/s) cutting speed and 40 IPS/S
acceleration (~ 1000 mm/s/s) and 2 ms servo thread,  the chord
error is about 0.00002" or 0.5 u.

If you increase the servo thread much longer you will start to have
issues on acceleration due to jumps between velocity steps, which
will limit your maximum acceleration setting.





 
Last edit: 17 May 2025 22:25 by PCW.
The following user(s) said Thank You: pgf, tommylight

Please Log in or Create an account to join the conversation.

More
17 May 2025 21:30 #328658 by Hakan
Another way is to take a feedrate say 200 mm/min and divide that by 60 for seconds and 1000 for servo thread speed and you get 3.3 micrometers between position updates. 500 Hz servo thread gives 6.6 micrometers between position updates. No buffering, all real time.
I guess there are situations where this can make a difference, but normally not I would say.
The following user(s) said Thank You: tommylight

Please Log in or Create an account to join the conversation.

More
18 May 2025 12:06 #328687 by pgf

With Mesa hardware (and most external hardware step/dir interfaces
or even EtherCAT drives), the velocity (step rate in this case) is updated
every servo thread.

This means that there is a constant velocity between updates. This constant
velocity means that that you will  have a small error (chord error) between a
desired curved path and the actual (linear interpolated) path.
 


Okay, that's interesting, and of course I have more questions.

First, does the Mesa know how many steps it should count?  Will the longer period introduce greater error in the length of each chord?  I.e.,  might it overshoot by 1ms worth of steps, vs. just 500ns worth of steps?   Or is the command to the Mesa really just "start moving at N steps/second"? (rather than "start moving at N steps/second, for 10500 steps")

Second, the chord error you describe would only occur for a curved path.  If the G-code is written completely using straight-line approximation (which of course introduces its own chord errors), it seems like the longer servo period wouldn't introduce any more error at all.  True?

In any case, it sounds like I can stop worrying about my 2ms servo period for the time being.

paul

Please Log in or Create an account to join the conversation.

More
18 May 2025 14:07 - 18 May 2025 14:09 #328693 by PCW
For Mesa step generation (others are similar) LinuxCNC creates a local feedback loop
where at every servo thread invocation, LinuxCNC reads the current stepgen position
and then sets a new velocity based on the current commanded velocity and with a small
correction based on the current position error. That is, at every servo thread invocation,
LinuxCNC generates a new position. Based on that new position and the current stepgen position
a new velocity is calculated to meet that new position at the next servo thread invocation.

With Mesa hardware the precision of the control loop is 1/65536s of a step, so typically
the error between the commanded position and the stepgen position is never more than
a fraction of a step.

Here is a plot of stepgen error at:

10 ms servo thread
1 IPS cutting speed
5 IPS rapid
50 IPS/S accelration

Note that Velocity is in IPS  per division and error is in 20 uinch  (~0.5 u) per division

The residual noise in the error is caused by timing uncertainty in the position sampling.
This is about 2 usec at a 10 ms servo thread but about 400 ns at a 2 ms servo thread

 

Even the chord error is nothing to worry about as long as you do not have extreme
acceleration (say > 1G)

 
Attachments:
Last edit: 18 May 2025 14:09 by PCW.
The following user(s) said Thank You: pgf, tommylight

Please Log in or Create an account to join the conversation.

More
18 May 2025 16:35 #328701 by pgf
Thanks! That first paragraph was gold. My understanding of how the whole thing works just went *way* up!

Please Log in or Create an account to join the conversation.

Time to create page: 0.220 seconds
Powered by Kunena Forum