Torque control of joints using Remote Api Python

Typically: "How do I... ", "How can I... " questions
Post Reply
tejaswi_kk
Posts: 4
Joined: 04 Jul 2023, 09:53

Torque control of joints using Remote Api Python

Post by tejaswi_kk »

Hi,
I have multiple revolute joints in my scene and I am trying to control the joints via Legacy Remote APIs in python. My control equation consist of torque that needs to be applied on each of the joints. I am not able to find torque control remote APIs for this purpose. I can only see sim.simxSetJointTargetVelocity function which can et the desired velocity for each joints. Are there any APIs available for torque control of the joints? Are there any other methods to control the joint in torque mode?
Thanks,
Tejaswi

tejaswi_kk
Posts: 4
Joined: 04 Jul 2023, 09:53

Re: Torque control of joints using Remote Api Python

Post by tejaswi_kk »

Also I am trying to work on this Spot Robot which I found on the website.
https://drive.google.com/file/d/1hdNKzh ... drive_link
I want to use the force control mode for all the revolute joints. But As soon as I set the joints to force controlled mode, the whole simulation starts acting funny and the robot never stays in the same place. I even tried changing the Simulation dt and dynamics dt in the simulation settings to see if it made it any better, but it acts the same way. Could you please guide me as to how to solve this issue?
Thanks

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

Re: Torque control of joints using Remote Api Python

Post by coppelia »

Hello,

the best would be to use the ZeroMQ remote API, since it is much easier and flexible to use, and the legacy remote APi is deprecated. Also, use the latest CoppeliaSim (currently V4.6).

Joints when in force control mode need to be constantly controlled/adjusted, i.e. you need to write you own controller that handles each joint in each dynamic simulation pass, i.e. by default 10 times per simulation step.

If the controller sits in an external Python script, then you need to set the simulation step to the same size as the dynamics simulation step (i.e. 5ms by default) and run the simulation in stepping mode, and trigger each step individually.

Cheers

tejaswi_kk
Posts: 4
Joined: 04 Jul 2023, 09:53

Re: Torque control of joints using Remote Api Python

Post by tejaswi_kk »

Hi,
Like you suggested, I downloaded the latest version of CoppeliaSim and updated the ZeroMQ and I am able to use ZeroMQ. Also, like you suggested I have changed the simulation step to suit the dynamics dt which is 0.005(5ms).
In the joint settings, I have set it to dynamic mode and control as force control for all of the joints and set the forces to zero. Yet, once i start the simulation, it starts behaving funny and starts falling and making weird motions (I would expect it to remain stationary since all joint forces are set to zero).
But the same robot is completely stable if I set it in velocity control and set the desired velocity to zero or in position control.
I have also tried keeping it in velocity control mode and then using sim.setObjectInt32Param(elbowj4, sim.jointintparam_dynctrlmode, sim.jointdynctrl_force) function to set it to force control mode and as soon as I do tis, robot starts behaving weirdly and doesnt do the intended motion. The scene which I am using is provided in this link
https://drive.google.com/file/d/1hdNKzh ... OE86l/view
Could you please help me solve this issue?
Thanks

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

Re: Torque control of joints using Remote Api Python

Post by coppelia »

The model you shared is relatively stable here... with MuJoCo it is even very stable. Please share the equivalent scene file, since there are settings that are not stored in the model and that influence its behaviour.

Cheers

jumppy
Posts: 3
Joined: 31 May 2016, 01:41

Re: Torque control of joints using Remote Api Python

Post by jumppy »

tejaswi_kk wrote: 21 Mar 2024, 20:54 Hi,
Like you suggested, I downloaded the latest version of CoppeliaSim and updated the ZeroMQ and I am able to use ZeroMQ. Also, like you suggested I have changed the simulation step to suit the dynamics dt which is 0.005(5ms).
In the joint settings, I have set it to dynamic mode and control as force control for all of the joints and set the forces to zero. Yet, once i start the simulation, it starts behaving funny and starts falling and making weird motions (I would expect it to remain stationary since all joint forces are set to zero).
But the same robot is completely stable if I set it in velocity control and set the desired velocity to zero or in position control.
I have also tried keeping it in velocity control mode and then using sim.setObjectInt32Param(elbowj4, sim.jointintparam_dynctrlmode, sim.jointdynctrl_force) function to set it to force control mode and as soon as I do tis, robot starts behaving weirdly and doesnt do the intended motion. The scene which I am using is provided in this link
https://drive.google.com/file/d/1hdNKzh ... OE86l/view
Could you please help me solve this issue?
Thanks
I think you have a misunderstanding of the torque mode. If the joint is set to torque mode, it tries to output the commanded torque as specified by the controller. In your case, 0. However, due to gravity, the output torque cannot be zero to stay static. In other words, the joints try not to resist gravity and, hence will behave crazy, just like a multi-link pendulum does when released freely.

Post Reply