# Rotate link in xacro-file for rviz

Hello,

I have a xacro file. In this file I want to rotate a link 90 degrees clockwise. How do I do that? The code is:

<!-- Mast Mount -->
<visual>
<origin rpy="0 0 0" xyz="0 0 0" />
<geometry>
<mesh filename="package://curio_description/meshes/bases/mastmount.stl" />
</geometry>
<material name="dark_gray" />
</visual>
<collision>
<origin rpy="0 0 0" xyz="0 0 0" />
<geometry>
<mesh filename="package://curio_description/meshes/bases/mastmount.stl" />
</geometry>
</collision>

edit retag close merge delete

Sort by » oldest newest most voted

When you say 90 degrees clockwise, its not giving us quite enough information to give you an exact answer. Clockwise about which axis? ROS uses a right handed coordinate system (more info here), with x = forward, y = left, z = up

URDF, SDF, and XACRO define rotations using Euler angles in radians. The rpy field in your visual and collision elements are the roll (rotation about x), pitch (rotation about y) and yaw (rotation a bout z) angles. 90 degrees in radians is approx. 1.5708rad. Whether "clockwise" means positive or negative depends on the axis you choose and the direction you are looking from.

All that aside, there are two ways you can apply a rotation to a joint.

1. in the link, you can apply a rotation to the origin of your inertial, collision, and visual fields. E.g. for 90deg clockwise about z, you'd setrpy="0 0 -1.5708"; this can be a bit tedious, and I'd only recommend it if your CAD just happened to use a different coordinate frame and you'll be including the link in different files

2. the alternative is to define the joint between your link and whatever its attached to. The joint field also lets you specify the rotation of a part relative to its parent; this way, you only have to specify it once (less error prone if you need to change it). again, you'd be setting the rpy field of the joint's origin.

As a final note, if all you want to do is have the RVIZ viewer look at your model from a different perspective, without actually changing the part's orientation with respect to the rest of the robot, then I'd suggest defining a dummy joint at 90 degrees to the mastmount_link, making sure you are publishing the tf`, and changing the reference frame in RVIZ (under the fixed frame setting)

more