URDF import: joint rotation direction

Report crashes, strange behaviour, or apparent bugs
Post Reply
Steve

URDF import: joint rotation direction

Post by Steve »

Hi,
I'm importing some urdf models and I'm quite confused about the rotation direction of the joints.
Indeed, in the urdf we can define the rotation (clockwise or anticlockwise) by changing the sign on the axis (eg: <axis xyz="0 0 1" />). The problem is that vrep doesn't seem to take that into account. Whatever the sign I put, the rotation direction stay the same.
Is it a bug in the plugin? Is there another way to do that?

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

Re: URDF import: joint rotation direction

Post by coppelia »

Hello,

the orientation of the joint will be different. The objects attached to the joint will not have a different orientation or position, if this is what you are trying to reach.

Cheers

Steve

Re: URDF import: joint rotation direction

Post by Steve »

What I want is just to change the clockwise/anticlockwise rotation for a joint without changing the position/orientation of its reference frame.
Normally it is done through the "axis" urdf tag of the joint definition (which indicates the distribution of the rotation along axes) by changing:
<joint
...
<avix xyz="0 0 1" />
...
>/joint>

into:

<joint
...
<avix xyz="0 0 -1" />
...
>/joint>

It works well in ROS/Gazebo, doing so, the rotation is inverted when I control the joint, it turns in the clockwise direction with <avix xyz="0 0 -1" /> while it turns in the anticlockwise direction with <avix xyz="0 0 1" /> with the same command.

This doesn't work when I import the model in VREP. Changing from <avix xyz="0 0 -1" /> to <avix xyz="0 0 1" /> doesn't change the rotation sign.
Of course I could do it in software by changing the sign of the command but it would be quite dirty...
It would be much better to be able to fix that in the urdf.

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

Re: URDF import: joint rotation direction

Post by coppelia »

Steve,

can you post a minimalistic URDF file example where this happens?

Thanks

Steve

Re: URDF import: joint rotation direction

Post by Steve »

Hi,
Ok so here is a simple example:

URDF with a single positive rotation axis:

Code: Select all

<robot
    name="origins">
  <link name="base_link">
  <inertial>
      <origin
        xyz="0.0 0.0 0.3"
        rpy="0 0 0" />
      <mass
        value="1" />
      <inertia
        ixx="0.00015494485478976"
        ixy="-1.3487523250186E-08"
        ixz="4.38412007017049E-06"
        iyy="0.000114480125738892"
        iyz="-1.23848284201495E-05"
        izz="9.78230753966605E-05" />
    </inertial>
    <visual>
      <geometry>
        <cylinder length="0.6" radius="0.1"/>
      </geometry>
      <origin rpy="0 0 0" xyz=" 0 0 0"/>
    </visual>
  </link>
  <link name="right_leg">
  <inertial>
      <origin
        xyz="0.3 0.1 0.05"
        rpy="0 0 0" />
      <mass
        value="1" />
      <inertia
        ixx="0.00015494485478976"
        ixy="-1.3487523250186E-08"
        ixz="4.38412007017049E-06"
        iyy="0.000114480125738892"
        iyz="-1.23848284201495E-05"
        izz="9.78230753966605E-05" />
    </inertial>
    <visual>
      <geometry>
        <box size="0.6 .2 .1"/>
      </geometry>
      <origin rpy="0 0 0" xyz="0 0 0"/>
    </visual>
  </link>
  <joint name="base_to_right_leg" type="revolute">
    <parent link="base_link"/>
    <child link="right_leg"/>
    <origin
    xyz="0 0 .35"
    rpy="0 0 0"
    />
    <axis xyz="0 0 1"/>
  </joint>
</robot>
(you may have to put the base_link in static)
Here is a minimal python code to move the joint towards a positive angle:

Code: Select all

import time
import vrep
vrep.simxFinish(-1)
clientID=vrep.simxStart('127.0.0.1',19997,True,True,6000,5)
res, joint_h= vrep.simxGetObjectHandle(clientID, 'base_to_right_leg', vrep.simx_opmode_oneshot_wait)
#turn to positive angle
res = vrep.simxSetJointTargetPosition(clientID,joint_h,3.0,vrep.simx_opmode_oneshot)
time.sleep(3)
vrep.simxFinish(clientID)
So here with a positive command, the joint moves in the counterclockwise direction.
Now if I change the axis tag in the urdf with <axis xyz="0 0 -1"/>, the same code should turn the joint in the clockwise direction, but it won't.
At least, is there a way to invert the direction directly in the the vrep model?

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

Re: URDF import: joint rotation direction

Post by coppelia »

When you import the file you provided, and you select the joint, you are able to read in the information text in the upper part of the screen:

Last selected object orientation: x: +000.00 b: +000.00 g: +000.00

When you set the negative axis in your file and import it again, your joint will display following orientation:

Last selected object orientation: x: +000.00 b: +000.00 g: -180.00

The import is not the problem. When you set your joint position from Python, you set a position of 3.0 Radians, which is 3*180/3.1415 degrees. Which might give you the impression of wrong direction?!

Cheers

Steve

Re: URDF import: joint rotation direction

Post by Steve »

Hi,

Interesting, I didn't notice that change in orientation.
So as you said, changing the axis of rotation of the joint from <axis xyz="0 0 1"/> to <axis xyz="0 0 -1"/> seems to rotate the joint frame of 180° along its z axis.
I don't really understand why putting a negative value here adds a 180° offset on the rotation axis? This has no effect, does it?
As I have seen on the documentation, rotational joints rotates along the z axis so changing the orientation of the other axes has no effect on the joint?

I think It should invert this axis and not just rotate it. At least it is what happens when I'm doing that in ROS.
Which means going from that: Image
to something like that: Image
Then, it will rotate in the opposite direction like mentioned in the urdf.

I've found that I can modify the joint frame orientation by hand *without* braking my model by moving everything connected to the joint somewhere else in the hierarchy, then rotate the joint frame and finally reconnect the hierarchy.
This is quite painful to do but if I don't move the hierarchy, changing the joint frame also changes everything connected to it.
As a side question is there a better way to do that? ie. wihtout having to move disconnect/reconnect the objects from the joint?

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

Re: URDF import: joint rotation direction

Post by coppelia »

For revolute and psismatic joints, what matters is the orientation (or direction) of the Z axis, which is the blue arrow and the rotational/translational axis of the joint. So if the Z axis points up, the rotation direction will be different than if the Z axis points down, it is like a screw.

If you want to reorient a joint without moving things attached to it, you'll have to first detach everything from it, as you mentioned. There is no other way for now.

In next release there will be a new functionality that will allow you to greatly customize every aspect of the simulator, and then you could quickly build such a functionality.

Cheers

Post Reply