The custom control is eliminate in version 3.5

Typically: "How do I... ", "How can I... " questions
Post Reply
xzbreeze
Posts: 11
Joined: 05 Dec 2016, 16:21

The custom control is eliminate in version 3.5

Post by xzbreeze » 05 Mar 2018, 04:12

Dear Administrator

I just installed the lastest version 3.5, but the custom control in the Joint Dynamic Properities is lost. Would you please tell whether it is a bug of new version or you just eliminate this function.

Many Thanks,

xzbreeze

fferri
Posts: 246
Joined: 09 Sep 2013, 19:28

Re: The custom control is eliminate in version 3.5

Post by fferri » 05 Mar 2018, 06:24

From V-REP manual (Joint control callback script):
Joint control callback scripts are deprecated. Instead, joint callback functions should be used. Already in place joint control callback scripts will however still operate, but edition is disabled. To temporarily enabled edition of the deprecated joint control callback scripts, edit value enableOldJointCallbackScriptEdition to true in file system/usrset.txt.

xzbreeze
Posts: 11
Joined: 05 Dec 2016, 16:21

Re: The custom control is eliminate in version 3.5

Post by xzbreeze » 07 Mar 2018, 04:01

fferri wrote:
05 Mar 2018, 06:24
From V-REP manual (Joint control callback script):
Joint control callback scripts are deprecated. Instead, joint callback functions should be used. Already in place joint control callback scripts will however still operate, but edition is disabled. To temporarily enabled edition of the deprecated joint control callback scripts, edit value enableOldJointCallbackScriptEdition to true in file system/usrset.txt.
Thanks fferri. However, I just installed 3.4 to use my joint custom scripts. It doesn't make sense why this function is disabled. I really need this to achieve joint force control.

Best Regards,

xzbreeze

coppelia
Site Admin
Posts: 6867
Joined: 14 Dec 2012, 00:25

Re: The custom control is eliminate in version 3.5

Post by coppelia » 07 Mar 2018, 11:31

Hello,

if you read again carefully fferri's reply, you will notice that there is a better solution, which is to use joint callback functions (which are exactly what you need). Everything that you could do with joint callback script can also be done with joint callback functions.

Simply add a non-threaded child script to your joint, and set your joint in force/torque mode, enable the motor and the control loop. Then add following function inside of your child script:

Code: Select all

function sysCall_jointCallback(inData)
    -- This function gets called often, so it might slow down the simulation
    --     (this is called at each dynamic simulation step, by default 10x more often than a child script)
    -- We have:
    -- inData.first : whether this is the first call from the physics engine, since the joint
    --                was initialized (or re-initialized) in it.
    -- inData.revolute : whether the joint associated with this script is revolute or prismatic
    -- inData.cyclic : whether the joint associated with this script is cyclic or not
    -- inData.handle : the handle of the joint associated with this script
    -- inData.lowLimit : the lower limit of the joint associated with this script (if the joint is not cyclic)
    -- inData.highLimit : the higher limit of the joint associated with this script (if the joint is not cyclic)
    -- inData.passCnt : the current dynamics calculation pass. 1-10 by default. See next item for details.
    -- inData.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)
    -- inData.currentPos : the current position of the joint
    -- inData.targetPos : the desired position of the joint
    -- inData.errorValue : targetPos-currentPos (with revolute cyclic joints we take the shortest cyclic distance)
    -- inData.effort : the last force or torque that acted on this joint along/around its axis. With Bullet,
    --                 torques from joint limits are not taken into account
    -- inData.dynStepSize : the step size used for the dynamics calculations (by default 5ms)
    -- inData.targetVel : the joint target velocity (as set in the user interface)
    -- inData.maxForce : the joint maximum force/torque (as set in the user interface)
    -- inData.velUpperLimit : the joint velocity upper limit (as set in the user interface)

    if inData.first then
        PID_P=0.1
        PID_I=0
        PID_D=0
        pidCumulativeErrorForIntegralParam=0
    end
    
    -- The control happens here:
    -- 1. Proportional part:
    local ctrl=inData.errorValue*PID_P
    
    -- 2. Integral part:
    if PID_I~=0 then
        pidCumulativeErrorForIntegralParam=pidCumulativeErrorForIntegralParam+inData.errorValue*inData.dynStepSize
    else
        pidCumulativeErrorForIntegralParam=0
    end
    ctrl=ctrl+pidCumulativeErrorForIntegralParam*PID_I
    
    -- 3. Derivative part:
    if not inData.first then
        ctrl=ctrl+(inData.errorValue-pidLastErrorForDerivativeParam)*PID_D/inData.dynStepSize
    end
    pidLastErrorForDerivativeParam=inData.errorValue
    
    -- 4. Calculate the velocity needed to reach the position in one dynamic time step:
    local maxVelocity=ctrl/inData.dynStepSize -- max. velocity allowed.
    if (maxVelocity>inData.velUpperLimit) then
        maxVelocity=inData.velUpperLimit
    end
    if (maxVelocity<-inData.velUpperLimit) then
        maxVelocity=-inData.velUpperLimit
    end
    local forceOrTorqueToApply=inData.maxForce -- the maximum force/torque that the joint will be able to exert

    -- 5. Following data must be returned to V-REP:
    firstPass=false
    local outData={}
    outData.velocity=maxVelocity
    outData.force=forceOrTorqueToApply
    return outData
end
If you read here, you will also notice that you can temporarily enable the joint callback scripts in V-REP V3.5.0.

So enable the UI to access the joint callback scripts, remove the joint callback scripts, then disable the UI to access the joint callback scripts, and use joint callback functions.

Cheers

Post Reply