The Firmware Realm : From GCode to PID or the (left,right,z) and (x,y,z) alternate worlds

Step 4

Now is the time to hash the action is a series of time slices called the “TIME LOOP INTERVAL”. The arduino will then change the x, y, z sled and router bit position in a series of small intermediate steps. Each step to be executed into exactly one “TIME LOOP INTERVAL” period.

Now remember that motors don’t do (x, y, z.) moves in the MaslowCNC: They do (l, r, z). That is why we need…

Step 5

So at every “TIME LOOP INTERVAL” period, the (x,y,z) target slice is converted into an (l, r, z) target slice with a little computation involving all the delicate physical details of the chain lenght calculations. And this is nicely called Reverse Kinematics

Into the arduino, the computations are split in two blocks:

  • block one is the one we have described up to now in the “TIME LOOP INTERVAL”. It finds the target (l, r, z) slice then waits to be asked for the next slice.
  • block two works much faster to control the motor dynamics, and that brings us to …

Step 6

The current motor shaft rotation angle relates to an ideal chain length, and that is compared to the Forward Kinematics (l, r, z) position to be met.

That is compared a thousand times per second.

The observed difference is called the “error”. Now the next step is going to deal with the “error”.

Step 7

The error is a very interesting beast: It may be changing slowly, or fast, may be small or large, may be stalled and require some kicking to go away. And that depends partly on the motor physics, and partly on where the sled is on the workspace, how much force it has to pull to get the routing bit pass through the wood. Motors might have it easy when giving chain to let the sled go down, or tough when pulling up center that brick loaded sled.

So here a PID rule is applied to decide how to kick the motor. It is actually a position and speed combined PID rule. To keep things simple, let’s point out what PID means.
+P says “scale the error value” that much and send for this amount of error as much power to the motor.
+I says “the error is stalled since a while.” Scale this “amount of time” and send that much power to the motor.
+D says “the error is changing that fast”. Scale this rate of change and pull back that much on the power demand to prevent motor position overshoot.

And now let’s code this “amount of power” in …