Torque control

Typically: "How do I... ", "How can I... " questions
jesusmartinb
Posts: 8
Joined: 25 Sep 2015, 11:47

Re: Torque control

Post by jesusmartinb »

Hi everyone,

I'm trying to managed a robot by torque control, I have conected V-REP with Simulink, I set to Simulink one target position, and this send to V-REP one torque, which is calculated in Simulink to get this position.

I have read all the post, and i have changed the parameters in my joint as you said before, the control loop is disable, but I set 0[deg/s] as target velocity, because the behavior is better in this way, but I,m not able to get the desired behavior. How can I improve the torque control?

Thanks

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

Re: Torque control

Post by coppelia »

Hello,

torque control is difficult. It becomes a little bit more difficult if you try to do it from an external application, since you need to have V-REP synchronized with your aplication. There are many things you should watch out for. Make sure you read this section very carefully.

Cheers

jesusmartinb
Posts: 8
Joined: 25 Sep 2015, 11:47

Re: Torque control

Post by jesusmartinb »

I have already read this section, and I operate in force/torque mode with motor enable but with control loop disable, and I also changed the time step to 5 ms instead of 50 ms, because I managed the simulation by the child script.

I send a signal to V-rep from Simulink, but I don't use remote API funtions because I have connected them by shared memory plugin.

Thanks

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

Re: Torque control

Post by coppelia »

Setting the target velocity to zero might give better results, but in that case you are not doing torque control. For torque control, you need to set the target velocity quite high, otherwise the joint will never exert the torque you want to apply. Torque control is actually difficult, and you need a good controller on your Simulink side.

Cheers

jesusmartinb
Posts: 8
Joined: 25 Sep 2015, 11:47

Re: Torque control

Post by jesusmartinb »

I'm still trying to solve the torque control to get a desired behavior but thanks for all

dds
Posts: 76
Joined: 20 Mar 2014, 14:35

Re: Torque control

Post by dds »

Hi. I made a very simple experiment to test torque control which consist on PD regulator for the PhantomX model. Here is the attached code to the phantom child Script. (Also Joints control loops were disabled)

Code: Select all

if (sim_call_type==sim_childscriptcall_initialization) then
    jointHandles={-1,-1,-1,-1}
    jointPosition={.0,.0,.0,.0}
    jointVelocities={.0,.0,.0,.0}
    jointControl={.0,.0,.0,.0}
    maxJointVel=1000

    for i=1,4,1 do
        jointHandles[i]=simGetObjectHandle('PhantomXPincher_joint'..i)
    end
end


if (sim_call_type==sim_childscriptcall_actuation) then

    pi=math.pi
    ref={pi/4,pi/4,pi/4,pi/4}
    P={6,6,6,6}
    D={0.1,.1,.1,.1}
    for i=1,4,1 do
        jointControl[i]=P[i]*(ref[i]-jointPosition[i])-D[i]*jointVelocities[i]
        if(jointControl[i]<0) then
            simSetJointTargetVelocity(jointHandles[i],-maxJointVel) 
            simSetJointForce(jointHandles[i],math.abs(jointControl[i]))
        elseif jointControl[i]>0 then
            simSetJointTargetVelocity(jointHandles[i],maxJointVel)
            simSetJointForce(jointHandles[i],math.abs(jointControl[i]))
        else
            simSetJointTargetVelocity(jointHandles[i],0)
            simSetJointForce(jointHandles[i],10) 
        end
    end
end


if (sim_call_type==sim_childscriptcall_sensing) then

	for i=1,4,1 do
        jointPosition[i]=simGetJointPosition(jointHandles[i])
        result,jointVelocities[i]=simGetObjectFloatParameter(jointHandles[i],2012)
    end

end


if (sim_call_type==sim_childscriptcall_cleanup) then

	-- Put some restoration code here

end
Whit custom Simulation Parameters (Accurate and dt=50ms) I get a very strange behavior when the maximum joint speed is set hi, in fact the system becomes unstable. I figure out that the problem is that simulation step time differs from Dynamic engine step time. Setting Dynamic engine step time closer to simulation time (Very Accurate and dt=5ms) the system behavior is the expected but unfortunately the simulation won't run in real time for slightly more complex scenes.
Apparently the dynamic engine continuously calculates the dynamics of the actuator by an outdated torque value, which causes instability, but when I set the Dynamic step to 10 ms and the simulation step to 10 ms the system does not behave properly. ¿why?

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

Re: Torque control

Post by coppelia »

Hello,

torque/force values are accumulated and averaged over one simulation step (i.e. typically 50ms in simulation time). This is because the physics engine can (and should run) more often than 20 times per second. So typically, be default we have:

1 simulation time (50ms) is executed --> the physics engine is executed 10 times (at 5ms).

The main reason is that you need a physics frequ. around 200 Hz, but reading all the sensors and doing the other stuff at 200 Hz would be overkill.
If you need to read the non-averaged torque in a joint for instance, then you have 2 possibilities:

1. As you suggest, you set the simulation step the same as the physics engine step (e.g. 5ms). This makes everything slower
2. You can use a joint control callback script. The joint control callback script will be called-back from the physics engine in each physics engine calculation step

Also, in your example, the joint velocity is a calculated value. Can you try to compute that joint velocity yourself (based on its position in the various time steps) and see what happens? From the top of my head I can't tell you when that joint velocity value is updated.

Cheers

dds
Posts: 76
Joined: 20 Mar 2014, 14:35

Re: Torque control

Post by dds »

Hello, thanks for the answer.
In my final application I need to send torque commands from simulink.It is feasible to perform any communication from a Joint control callback scripts ?

I do not understand what you mean with
the joint velocity is a calculated value
. As you mentioned in several posts, to control the torque I leave fixed the joint speed reference in a high value (just change the sign in the direction of rotation).

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

Re: Torque control

Post by coppelia »

If you need to provide control commands from the outside (e.g. a remote API client), then you will need to:

1. Set the simulation time step to the same value as the physics engine time step. Otherwise you would skip control steps. Some details can be found here. Then, in order to not slow down the rest of the simulation, you can explicitely handle sensors and other things, by checking them only when really needed, and not in each simulation step.

2. Run in synchronous mode, i.e. your external application will trigger each simulation step individually.

About the velocity: you are right, I didn't try to look deeper into your code in your previous post..

Cheers

sade
Posts: 6
Joined: 08 Nov 2015, 13:04

Re: Torque control

Post by sade »

Hello,

I am using matlab/vrep to develop a position control loop of the end effector of a serial link robot.

The control algorithm directly uses the difference between the desired and actual positions and velocities so as to create the required joint torques to drive joint motors. To apply the torque I use a similar code as following:

Code: Select all

for i=1:7          
                if( torque(i)>0.0 )
                    velocity(i) = 9999.0;
                elseif (torque(i) <0.0)
                    velocity(i) = -9999.0;
                else
                    velocity(i) = 0.0;
                end        
end
Here, there is a problem. When the end effector comes to the desired position exactly, torque and velocity take negative values. But motor continues to move in the previous direction and it can not stop for a long duration even the controller applys a torque to it in reverse direction.

Briefly, when the sign of torque changes, I want to stop the joint motor and so it can take directly the torques in negative direction. Using the code above, it can not stop for a long time when the sign of velocity (torque) is change. How can I fix it?
Last edited by sade on 28 Sep 2016, 15:35, edited 1 time in total.

Post Reply