How to apply a torque to Joint?

Typically: "How do I... ", "How can I... " questions
Post Reply
erpasd

How to apply a torque to Joint?

Post by erpasd » 11 Jun 2013, 07:27

Hi there, as the subject suggest I'm trying to apply a torque to a joint but I can't find any functions to do it. The two closest functions I found are:

1) simSetJointForce but it looks like it will set the maximum force the joint can exert rather then the current value.
2) simAddForce but apparently it will only work with shapes not with joints.

Maybe I misunderstood the API or I missed out something, if anyone could help me I would greatly appreciate,

Thanks!

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

Re: How to apply a torque to Joint?

Post by coppelia » 11 Jun 2013, 09:40

Hello,

the way joints operate in V-REP is directly linked to the ODE or Bullet physics engines. When in velocity control (i.e. motor is enabled, position control is disabled):
  • You specify a target velocity
  • You specify a max. torque
  • If current velocity is below the target velocity, the max. torque is applied
  • If current velocity is above the target velocity, a negative torque is applied
This means that if you want to control your joint in force/torque, just specify a target velocity very high (e.g. that will never be reached). To modulate the torque/force, use the simSetJointForce function.

Cheers

gianpaolo
Posts: 6
Joined: 26 Jul 2013, 19:50

Re: How to apply a torque to Joint?

Post by gianpaolo » 03 Sep 2013, 10:06

Hello,

I've a torque profile described by an array and i'd like to actuate a joint with that torque profile, so to do this i'm trying to command a revolute joint directly through the torque during simulation,by setting a very large target velocity through simSetJointTargetVelocity and the torque through simSetJointForce, i'm working on a c++ plugin calling these two function everytime the message sim_message_eventcallback_modulehandle is launched (exactly the same as the tutorial of the plugin on bubblerob), at the same time i'm also reading the torque applied through simJointGetForce to ensure that the torque is the one that i've specified, but it's not.

In particular i'm setting a negative torque but i'm reading a positive one.
I've also tried to set a negative target velocity with a positive torque but nothing changes.

The joint is setted on torque/force mode and all the links(shapes) attached to it are non static, i've also enabled the motor and disabled the control loop but probably i'm missing something?

Thank you.

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

Re: How to apply a torque to Joint?

Post by coppelia » 03 Sep 2013, 10:26

Hello,

I think that your approach via a plugin is not the best, since you will not have the optimal control: a joint, when dynamically enabled, is controlled at a higher frequency than the main simulation loop (10 times more frequent by default). Have a look at this topic.

You will obtain better results when doing your joint control in a joint controll callback script. At the same time, your joint will become extremely portable (you can easily copy-paste it, save it, reload it on a different platform, etc. and your sofisticated controll be automatically be copied at the same time!)

You cannot set a negative torque for your joint. But you can set a negative joint target velocity. Also, do not set unnecessary large values (torque/velocity) even, since that makes the physics engines sometimes produce strange results.

Cheers

gianpaolo
Posts: 6
Joined: 26 Jul 2013, 19:50

Re: How to apply a torque to Joint?

Post by gianpaolo » 03 Sep 2013, 11:46

Thank you!
I will try through a callback script.

I found also that setting a positive target velocity and then reading the joint torque through simJointGetForce that torque is negative, conversely when i'm setting a negative target velocity i read a positive torque, why?

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

Re: How to apply a torque to Joint?

Post by coppelia » 03 Sep 2013, 18:00

Well,

when you measure the force/torque that is applied to a joint, it always depends what is acting upon the joint and how. Let's take an example with a revolute joint:
  • the motor of the joint is disabled
  • the joint has no free movement because its lower limit is 0, and its higher limit is 0 too
  • the rotation axis of the joint lies in the x/y plane
If a mass is attached to the joint on one side, you will measure a torque of T=D*M*G (Distance*Mass*Gravity).
If the mass is attached to the joint on the other side, you will measure a torque of -T (the opposite).

In case your joint exerts a torque/force, you will also be able to measure a positive or negative torque/force, depending on the situation.

Cheers

gianpaolo
Posts: 6
Joined: 26 Jul 2013, 19:50

Re: How to apply a torque to Joint?

Post by gianpaolo » 05 Sep 2013, 19:01

ok

gianpaolo
Posts: 6
Joined: 26 Jul 2013, 19:50

Re: How to apply a torque to Joint?

Post by gianpaolo » 06 Sep 2013, 12:10

It seems that taking the torque with simJointGetForce i'm not reading the torque that the motor exert but the torque that the mass of the shape attached to it exert on it.

Well, i suppose that in absence of gravity a single joint fixed on a stationary base that moves a link with a certain acceleration(for example to reach a velocity value) exert a torque with the same sign of that acceleration.

To prove what i'm saying i've made a simple simulation with a robot composed of a static base(pure shape cuboid), a revolute joint (in force/torque mode, positioned on the top of the base with the z-axis parallel to the x/y plane) and link(pure shape cuboid, attached to the joint), then i've setted the initial position of the joint on -90° something like a reverse L, like this: (where the j letter represent the joint position)

j ____
|
|
|

here the z axis of the joint is coming out from the screen and positive velocity means a counterclockwise movement.
Now enabling the motor on the joint, setting a positive target velocity and a max torque appropriate to reach that velocity, i'm expecting that the torque will have the same sign of the target velocity until it reach the vertical position, cause it has to reach the target velocity and also to win the gravity, but i'm reading a negative torque. why?

Thank you.

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

Re: How to apply a torque to Joint?

Post by coppelia » 06 Sep 2013, 12:32

Hello,

actually we noticed that the documentation is wrong. Like you are pointing out, it should be the force/torque applied to the joint, and not the force/torque that the joint exerts. This explains the sign problem.

Thanks, we have corrected the documentation.

Cheers

Post Reply