# Calculating velocity and acceleration from position inside TwinCAT PLC Control V2

## 3 posts in this topic

Hi, I am calculating velocity and acceleration from position inside TwinCAT PLC Control V2. All these equations have only one variable which is time. Below is the PLC code- (* We are using the external set point generator functionality *)NewPosition := theta_max*COS(omega*t); (* t is time in second *)NewVelocity := -theta_max*omega*SIN(omega*t);NewAcceleration := -omega*omega*theta_max*COS(omega*t);IF NewVelocity=0 AND NewAcceleration=0 THEN NewDirection := 0; (* stand still *)ELSIF NewVelocity >= 0 THEN NewDirection := 1; (* positive motion *)ELSE NewDirection := -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 := NewPosition, Velocity := NewVelocity, Acceleration := NewAcceleration, Direction := NewDirection, Axis := Joint_2);-------------------------------------------------------------(* Below parameters are defined in Global Variables file *)VAR_GLOBAL CONSTANT theta_max: INT := 60; (* in degree *) omega: REAL := 0.62; (* 2PI/Time Period=10sec *)END_VARThe MATLAB simulation of the above equations gives me following results- But this does not work in real Beckhoff motor. Please suggest.

##### Share on other sites
I suggest that you contact your local Beckhoff support.

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account