Followers 0

# Using time as a variable in TwinCAT 2 PLC

## 3 posts in this topic

Hi, I am trying to run the Beckhoff Motor (reference velocity 900mm/s and maximum velocity 810mm/) in a sinusoidal trajectory. Following is the snippet of the PLC code- (* Joint 2 is using the external set point generator functionality *)ExtPosition := theta_max*COS(omega*t); (* t is time in second *)ExtVelocity := -theta_max*omega*SIN(omega*t);ExtAcceleration := -omega*omega*theta_max*COS(omega*t);IF ExtVelocity=0 AND ExtAcceleration=0 THEN ExtDirection := 0; (* stand still *)ELSIF ExtVelocity >= 0 THEN ExtDirection := 1; (* positive motion *)ELSE ExtDirection := -1; (* negative motion *)END_IFt:=t+0.01; (* The task is called at every 10 ms = 0.01sec *)(* feed the dynamic data into the external setpoint generator interface of axis *)MC_ExtSetPointGenFeed( Position := ExtPosition, Velocity := ExtVelocity, Acceleration := ExtAcceleration, Direction := ExtDirection, Axis := Joint_2);The global constants are defined as following- VAR_GLOBAL CONSTANT theta_max: INT := 60; (* in degree *) omega: REAL := 0.62; (* 2PI/Time Period=10sec *)END_VARWhen I set Position Lag Monitoring to TRUE, I get error 17744(0x4550). When Position Lag Monitoring is set to FALSE, the motor moves but not continuous. Also the motion is neither smooth nor instantaneous. I think the way, I am using time variable t is not correct. Somebody please help me to overcome with this problem. Edited by ravi.joshi53

##### Share on other sites
Okay, you 177744 is a following error - Meaning your target position is outside the range of the estimated position. First check on you TwinCAT System Manager by clicking on axis to see what size of window is set. Adjusting that window should help a little bit. Also you can set your Jerk (m/s2/s) to have a smoother movement.

good