How to set an absolute joint target velocity?

Typically: "How do I... ", "How can I... " questions
Post Reply
Posts: 17
Joined: 23 Feb 2018, 14:46

How to set an absolute joint target velocity?

Post by gvgramazio » 19 Oct 2018, 13:42

I want to control a joint in force/torque mode. The control would be done by an external python script through remote API but the following request would be the same even with a child script inside the scene.

This is what I've got from the manual so far:
- Check 'motor enabled' in the motor properties.
- Set the desired target velocity. When the joint has its motor enabled and the control loop is disabled, then it acts in velocity control. If we don't have any target velocity then this should be set to a reasonably large value.
- Control the motor force/torque through sim.setJointForce.

In my case, I want to control the motor in both directions. However, I've troubles to overcome the velocity control.

One workaround is based on the fact that even if the velocity has a sign, the maximum force/torque is an absolute value. So my guess is that I could do something like:

Code: Select all

# max_velocity is a fixed positive value
# desired_forceis a variable that could be positive or negative

if desired_force < 0:
    jointTargetVelocity <- -max_velocity
    jointForce <- -desired_force
    jointTargetVelocity <- max_velocity
    jointForce <- desired_force
Is my guess correct? Is this the right thing to do or there is a better way?

Site Admin
Posts: 7255
Joined: 14 Dec 2012, 00:25

Re: How to set an absolute joint target velocity?

Post by coppelia » 23 Oct 2018, 06:35


yes, the force or torque that you apply should always be positive. And you should alternate the sign of the target velocity.


Post Reply