Posts

Improving dcservo accuracy

Image
Not being an expert in motor control, I created dcservo project to make a basic platform to create cheap servomotors that could replace stepper motors on certain systems, like 3D printers. I chose to implement a full PID controller but that might have been a bit overkill.

I was talking today to a more knowledgeable colleague who asked me why I needed a PID. My answer was that without the integral action I was getting a significant position error in the steady state, and the derivative action, though a really small value, was needed to keep the system from overshooting. However, he suggested me to focus only on a simpler, proportional controller with a twist: most of my position error is coming from the fact that there is a dead zone where motor does not respond to control action.

It is true, though the motor will move faster the higher the PWM value it is applied to the motor drive, it is also true that low values (between 1 and 50 in my test system) do not cause the motor to move.

I …

Marlin's Bézier vs sinusoidal speed profile

Image
Bugfix-1.1 branch of Marlin firmware does include a fifth-degree (quintic) Bézier polynomial for the speed profile. If you want to use it enable S_CURVE_ACCELERATION define. You can have a look at the source code, luckily well commented so we can understand where it is coming from.

I was curious to check how different that curve was from the sinusoidal speed profile I mentioned in a previous entry. Although the source code comments are very thorough on how they reach their expression, in layman's terms is something the speed along a move is

s(t)= (6*t5-15*t4+10*t3)*|v1-v0|+v0
where v1 is the final speed, v0 is the initial speed and t varies from 0 to 1 to trace the motion.

I was surprised on how it looked quite similar to the sinusoidal case, so I went on and did a comparison with the sinusoidal s-curve:

And the result is that there is not much of a difference so I don't expect much different behavior when using one or the other. 

Too much pressure

Image
A local company built a ram extruder for us. Not very different from a syringe extruder but massive in terms of size and pressure.

Our assumption was that parts had been sized properly, so we did not question the 8.7Nm NEMA34 stepper, nor the 5mm-thick acrylic tube with a 60mm internal diameter. After all, it was not the first time they have built a similar contraption to be used with clay.

Unfortunately, though we try to be very gentle on the extrusion test, we manage to break the tube in a few minutes. Luckily for us, it cracked without sending debris around. We did not expect that at all and when we contacted the seller all sorts of questions were asked, questions we did not have an answer for, like "what was the operating pressure?". I did not have a clue as I was just trying to get the stepper rotating very slowly. Their diagnose was we did it wrong as we set the nominal current (6A) for the stepper driver.

From torque to pressure So I was determined to figure out how …

One table to run them all

Image
In previous entries, I have delved into the idea of using different shapes for the speed pattern for a motion using steppers and have presented how the timing can be based on a look-up table. Such a table would be pre-calculated and flashed with the firmware. But a single table provides a pattern for a given max speed, acceleration, number of steps and speed shape.


You can use that for timing the steps of the motor and it will accelerate properly as many steps as entries on your table. But it won't be practical if we want to change any of these parameters for other movements.
The idea I am not yet sure this works as expected, but first tests look ok, finally, as it took me a while to figure this out.
I have created a lookup table as the graph above, where each entry contains the delay needed for each step, for a movement of 1000 steps total, where speed will increase to 2Π while time goes till 2Π too. Maximum speed for each different motion pattern will be different though, but th…

More experiments with motion curves for steppers

Image
Though I have been experimenting with Arduino, I realize that as soon as the computing requirements grow a bit the results quickly show the processor is actually slowing down my results. So now I am using a DOIT Espduino featuring an ESP32 processor that makes that sensitivity go away.

It was a bit of a challenge to get this board to work with CNCshield v3. The culprit was resistor R1 (enable pin) that would affect the booting capability of the ESP32. Once R1 was removed (brutally destroyed with a wire cutter in my case) the problem was gone and I could upload and run code with the Arduino IDE.

I created a simple program that uses some pre-calculated delays to perform the motion using different expressions for the acceleration. Four have been used and shown in the video below:

Uniform acceleration a=kSinusoidal acceleration a=1-cos(t)Exponential a=(e^(cos(t/2)-1)*sin(t/2))/2Exponential2 a=(e^(-(t-sin(t))/pi)*(1-cos(t)))/pi The expectation from a former entry was that adding the exponen…

Stepper motor step signal timing calculation

Image
While we use stepper motors in many devices, the timing of the step signals is not always well understood. Most of us can see how a fixed speed is a bad idea unless the speed of motion is really slow, but it is fixed speed what is really to generate with simple code. You just can use the Arduino Blink example to send a fixed frequency of pulses to a stepper motor driver. If too slow, just reduce the delay value.

But for most real-life applications variable speed controls will perform better. These systems will speed up the motor to a given maximum speed and it will slow it down to stop at the desired step count. But understanding the math behind this process is sometimes not obvious.

Let us start with the simple case of the so-called trapezoidal speed motion profile. Here motion takes place in three phases: acceleration, constant speed (cruising) and deceleration. But the point is how can our code create such a behavior.

Stepper motor drivers usually accept two signals to control moto…

A better stepper drive s-curve?

Image
One of the not so desirable features of stepper motors is the fact that output torque falls quickly with shaft speed. This is one of the reasons these motors cannot reach high speeds.

So I was thinking that when we use a s-curve to drive them, instead of choosing a symmetric one, where acceleration is is max in the middle of the acceleration section (as speed raises), I could try one where higher accelerations happen to lower speeds. However, in order to still keep the s-curve shape instead of a sawtooth, I would use the following expression: 1-e^(cos(t/2)-1)and it is shown in blue in the graph.

This will produce a s-curve shape, but modulated with the exponential behavior. Resulting signal will grow faster as the beginning (where more torque is available) and more slowly at the end (where faster speeds are reached and less torque is available).

A first test shows me that, for a bare motor, a faster move can be achieved, more reliably (no missed steps), using this pattern instead of …