I am trying to control the velocity + position of a linear actuator.
At this moment I am able to control the position or the velocity. But I'm trying to control both. What the control has to do: Let the linear actuator drive to a position i.e. 0 to 100 cm with a constant velocity of 1cm/s.
I control the actuator using a PWM signal. And I measure the velocity and position using a position sensor on the shaft.
What kind of control is preferred, PID in cascade? If so, what would the code look like? Any other kind of control would function better?
EDIT: A more describing picture.
I want a velocity controlled position controller. Hopefully this will make it clear
My first try is with a trapezoid wave. Maybe there is an easy way without too much calculation power to change it to an s-curve. Then the acceleration/jerk will be a lot smoother.
I let the microcontroller calculate 3 different formulas, afterwards it will calculate it using loop iteration. This way I can use one PID for the position. The parameters in the following code will fictional:
AccelerationLoops: 5 //[Loops] Velocity: 100 //[mm/s] DeltaPosition: 7.5 //[mm] Looptime: 5 //[ms] Loopfactor: 1000 / Looptime //[-] VelocityLoop: Velocity /Loopfactor //[mm/loop] VelocityFactor: VelocityLoop * .5 / AccelerationLoops //[mm/loop] (.5 found by integration) Loops: DeltaPosition / VelocityLoop / AccelerationLoops //[Loops]
Formula1: VelocityFactor * x^2 LastF1: Last value of Formula1 Formula1(5) Formula2: VelocityLoop * x - LastF1 Formula3: VelocityFactor * (Loops - x)^2 + DeltaPosition)
Using the parameters of above it will generate the following setpoint:
0 0,00 1 0,05 2 0,20 3 0,45 4 0,80 5 1,25 6 1,75 7 2,25 8 2,75 9 3,25 10 3,75 11 4,25 12 4,75 13 5,25 14 5,75 15 6,25 16 6,70 17 7,05 18 7,30 19 7,45 20 7,50
A big problem with the code above is that the amount of acceleration loops is a constant. It cannot be changed except when you already know the amount of loops it will take.
I will be using two separate Arduinos, they will be connected using a CAN-bus connection. Anyway, they won't communicate through it unless the load becomes too high. This will make master/slave impossible. Also the system has to be modular: adding another actuator to the circuit won't be a problem. The actuator is speed controlled by using a PWM signal. The linear sensor will deliver a 0-10v signal which i will reduce to 0-5v by a simple voltage divider. The loop will be around 5 to 10 ms, will depend on the maximum looptime.
Arduino has a 10-bit (0-1023) ADC but use of oversampling I will probably try to increase it to 12-bit. To not decrease the reading speed I will decrease the prescaler of the ADC.
The PWM output is 8-bit (0-255), I am trying to find a way to further increase. Because I think 255 steps are too low for my application.
Because the Arduino has limit internal memory, precalculating all the positions is impossible.
Thank you all for the help so far!