## joint control callback script (V3.0.4)

Report crashes, strange behaviour, or apparent bugs
Ruediger
Posts: 12
Joined: 03 Aug 2013, 07:25

### joint control callback script (V3.0.4)

-- Following data is handed over from V-REP:
init,revolute,cyclic,jointHandle,passCnt,totalPasses,currentPos,targetPos,errorValue,
effort,dynStepSize,lowLimit,hightLimit,targetVel,maxForceTorque,velUpperLimit=...

It looks like, that the currentPos value has the unit 0.1 meters, or in other words:
currentPos/10 yields the correct position in meters.

PS: Whatis the exact meaning of the others values? (some are easy to understand, others are cryptic: errorValue, effort, ...)

Ruediger

coppelia
Posts: 7584
Joined: 14 Dec 2012, 00:25

### Re: joint control callback script (V3.0.4)

Hello Ruediger,

Thanks for reporting this bug. Can you confirm that this happens only with the Bullet engine?

What actually happens with Bullet in V-REP: by default, V-REP applies a scaling factor of 10 internally when using the Bullet engine (because Bullet doesn't handle small objects/masses well). It seems we forgot to scale-back some values before handing the data to the callback script.

You can manually change the scaling factor in the dynamics engine dialog. Maybe have also a look here for more detailed information about the internal scaling.

Code: Select all

-- init: true when this callback is called for the first time (if the joint is dynamically reset during the simulation, this might be true more often)
-- revolute: true if the joint is revolute
-- cyclic: true if the joint is revolute and cyclic (i.e. no lower/upper limits)
-- passCnt: the current dynamics calculation pass. 0-9 by default. See next item for details.
-- totalPasses: the number of dynamics calculation passes for each "regular" simulation pass. 10 by default (i.e. 10*5ms=50ms which is the default simulation time step)
-- currentPos: the current position of the joint
-- targetPos: the desired position of the joint
-- errorValue: targetPos-currentPos (with revolute cyclic joints we take the shortest cyclic distance)
-- effort: the last force or torque that acted on this joint along/around its axis. With Bullet, forces/torques from joint limits are not taken into account
-- dynStepSize: the step size used for the dynamics calculations (by default 5ms)
-- lowLimit: the joint lower limit
-- highLimit: the joint upper limit
-- targetVel: the joint target velocity (as set in the user interface)
-- maxForceTorque: the joint maximum force/torque (as set in the user interface)
-- velUpperLimit: the joint velocity upper limit (as set in the user interface)
Cheers

Ruediger
Posts: 12
Joined: 03 Aug 2013, 07:25

### Re: joint control callback script (V3.0.4)

Thank you for this explanation.
I have now written my velocity profile generator as call-back script.
I move the joint to the target position with a constant acc ramp up and down and a max vel limit. The target position can be set at any time, even if the joint is moving.
Now I must have a way to check, if the the joint has reached the target position (pos == target-pos AND vel = 0).
Comparing pos == target-pos is no problem, but simGetObjectFloatParameter(joint,2012) does not give the the vel value returned from the call-back script.
-- Following data must be returned to V-REP: return forceOrTorqueToApply,velocityToApply
I get always 1.0
An other possibliliy is, that the call-back skript sets a "in-pos" flag, but how to read it from the simulation skrip?
Is a signal OK to transfer information from call-back scripts?
Ruediger

coppelia
Posts: 7584
Joined: 14 Dec 2012, 00:25

### Re: joint control callback script (V3.0.4)

Hello Ruediger,

by default, the joint callback script is called 10 times for each "regular" main simulation pass. That means its frequency is higher than normal, but most simulation values and states are updated only for the main simulation pass. So is the joint velocity that you read with simGetObjectFloatParameter(jointHandle,2012).

You will have to calculate the joint velocity yourself in your callback script by comparing the current position with its previous position.

Also, when returning the velocity to apply: the physics engine will try to reach that velocity, but if the torque (or force) is not large enough, it will never be reached. So you have no guarantee to effectively see that velocity!

Cheers

Ruediger
Posts: 12
Joined: 03 Aug 2013, 07:25

### Re: joint control callback script (V3.0.4)

coppelia wrote:Hello Ruediger,

by default, the joint callback script is called 10 times for each "regular" main simulation pass. That means its frequency is higher than normal, but most simulation values and states are updated only for the main simulation pass. So is the joint velocity that you read with simGetObjectFloatParameter(jointHandle,2012).

Ruediger:
Yes, I take this in account, but I always see simGetObjectFloatParameter(jointHandle,2012) == 1.0
even when I return:
-- Following data must be returned to V-REP:
return maxForceTorque,0
(a constant 0.0 as vel)

You will have to calculate the joint velocity yourself in your callback script by comparing the current position with its previous position.

Ruediger:
The task of the callback script is to calculate the required vel for the actual target distance.

Also, when returning the velocity to apply: the physics engine will try to reach that velocity, but if the torque (or force) is not large enough, it will never be reached. So you have no guarantee to effectively see that velocity!

Ruediger:
I use a huge force - simulating a strong motor controler, which can follow a given trapezoid velocity ramp to reach the target position.

Cheers

coppelia
Posts: 7584
Joined: 14 Dec 2012, 00:25

### Re: joint control callback script (V3.0.4)

Ruediger,

from a Lua script you should read the joint velocity with:

Code: Select all

result,velocity=simGetObjectFloatParameter(jointHandle,2012)
and not

Code: Select all

velocity=simGetObjectFloatParameter(jointHandle,2012)
Cheers

Ruediger
Posts: 12
Joined: 03 Aug 2013, 07:25

Stupid mistake
Thank you,
Ruediger