Code for limiting acceleration (and Jerk) on motion control

matt_sd

Member
Join Date
Jan 2007
Location
Australia
Posts
96
Hello,

I am struggling to code in Structured Text a closed loop control motion control with Acceleration and Jerk limiting. Can anyone help me out more with the formulas and logical order:-

I am using a PID function block that is working perfectly and taking in a setpoint and actual value and the output is the position.

This output position (pos_cmd_out) is then velocity limited using the code below that is working perfectly.
My query is would acceleration limiting (and Jeck) be done after the velocity limiting (taking the velocity limited position command output - velocity_lmt_pos_cmd)?
I would have 2 setpoints, maximum acceleration and maximum jerk.
Any help putting me in the right direction would be great.
Thanks

(* Calculate allowed velocity per time step. Scan time (in Secs i.e. 1ms = 0.01) * velocity limit *)
max_velocity_step:= scan_time * max_velocity;

(* Calculate the command difference from the previous step *)
cmd_diff_per_step:=ABS(pos_cmd_out - pos_cmd_prev);


(* Check to see if position command need to be velocity limited *)
IF cmd_diff_per_step > max_velocity_step THEN
(* Command Velocity is being limited *)
velocity_limiting:=1;
(* Calculate direction of position that velocity limited *)
IF pos_cmd_out > pos_cmd_prev THEN
velocity_lmt_pos_cmd:=pos_cmd_prev + max_velocity_step;
ELSE
velocity_lmt_pos_cmd:=pos_cmd_prev - max_velocity_step;
END_IF
ELSE
(* Command Velocity is not being limited *)
velocity_limiting:=0;
velocity_lmt_pos_cmd:=pos_cmd_out;
END_IF


(* Record the previous velocity *)
pos_cmd_prev:=velocity_lmt_pos_cmd
 
For a system that outputs a positioning profile to a positioning drive, the S-curve is usually done in the drive. It can be done as a simple moving average filter. I suppose it can be done with the position command, though.
 
matt_sd, you are looking at this wrong. You must calculate a motion profile where you move the set point or target position every scan. Limiting the acceleration and velocity alone will not work because you must also know when the velocity and acceleration must be decreased. I see no code for handling this situation. Actually, you are barely scratching the surface.

Then you must also handle the cases where the acceleration never gets to the maximum acceleration or those cases where the move is so short the maximum velocity is never reached.

I would listen to Highland_Controls' suggestion you rely on the s-curves in the drive.

Just so you can see what you are up against.
http://deltamotion.com/peter/Maxima/Seg1234567.html
This is just ONE simple case. What if the destination is so close the motion profile can't reach the peak velocity? There must be a lot of checking to see which case applies to the current situation.
 
I have more time now for the 'WALL OF TEXT'

matt_sd, writing a target or trajectory generator is one of the most difficult parts of writing code for a motion controller. The PID and feed forward code is trivial compared to the target generator code.

Most motion controllers start out using code similar to what I posted in the link. You can see there are 7 segments or polynomials that make up that motion profile. Each polynomial is a 3rd order polynomial. The coefficients or initial position, velocity and acceleration must be calculated for each segment/polynomial. One of the harder parts is computing the time each of the polynomial is to be used.

You must create a state machine that handles moving from one polynomial to the next.
State 0 stopped
State 1 ramping up Jerk > 0
State 2 ramping up a=amax Jerk = 0
State 3 ramping up Jerk < 0
State 4 constant velocity v=vmax a=0 J=0
State 5 ramping down Jerk < 0
State 6 ramping down a=-dmax j=0
State 7 ramping down Jerk > 0

There will be some extra states to handle some odd ball cases like when the current velocity or acceleration are greater than the new commanded max velocity, max acceleration and max deceleration.

Some of the state will be skipped depending on the parameters.

Also note. If you use 4th order polynomials you will need more states to handle ramping the jerk up and down.

matt_sd. The truth is that while I could help you it would take much more than answering a few questions. Save yourself a lot of time and money and buy a good motion controller that has these details worked out. I have been at this for years and have whole directories of Mathcad worksheets with these details worked out and I am still learning.
 

Similar Topics

Hi All, Can anyone advise me on how to determine the AN of a genie instance I writing to. I have created a genie to display a valve and some text...
Replies
0
Views
81
Hi I have been knocking my head against the wall trying to figure out why these two plcs won't talk with Produced and Consumed Tags data. The...
Replies
14
Views
417
Hello Everyone. Looking to see if any of you have encountered an issue with these drives. We have a major installation with around 30 of these...
Replies
0
Views
59
Error description: "A connection could not be established in the open process of the TCP connection." Action: •Check the operation of the...
Replies
3
Views
100
I am trying to display a variable within a cicode function onto a graphics page. This function queries a SQL database. I can get the value onto a...
Replies
3
Views
229
Back
Top Bottom