To add a wheel to the robot we can use the cylinder shape to create the wheel shape.

The modified code is the following:

<?xml version="1.0"?>
<robot name="my_robot">

    <material name="blue">
        <color rgba="0 0 0.5 1" />
    </material>

    <material name="grey">
        <color rgba="0.5 0.5 0.5 1" />
    </material>

    <link name="base_link">
        <visual>
            <geometry>
                <box size="0.6 0.4 0.2" />
            </geometry>
            <origin xyz="0 0 0.1" rpy="0 0 0" />
            <material name="blue" />
        </visual>
    </link>

    <link name="right_wheel_link">
        <visual>
            <geometry>
                <cylinder radius="0.1" length="0.05" />
            </geometry>
            <origin xyz="0 0 0" rpy="0 0 0" />
            <material name="grey" />
        </visual>
    </link>

    <joint name="base_right_wheel_joint" type="continuous">
        <parent link="base_link" />
        <child link="right_wheel_link" />
        <origin xyz="0 0 0" rpy="0 0 0" />
        <axis xyz="1 0 0" />
    </joint>

</robot>

The Result of RViz is the following:

image.png


We want to place the wheel on the left side of the box. To achieve this, the joint must first move in the negative x-axis direction, followed by a movement in the negative y-axis direction.

Given that the rectangular box dimensions are 0.6, 0.4, and 0.2 along the x, y, and z axes respectively, the box extends 0.3, 0.2, and 0.1 units along the x, y, and z axes respectively from the origin. Since the wheel shares the same origin as the box, the joint origin must move by -0.15, -0.2, and 0 along the x, y, and z axes respectively to reach the desired position.

The modified code is the following:

<?xml version="1.0"?>
<robot name="my_robot">

    <material name="blue">
        <color rgba="0 0 0.5 1" />
    </material>

    <material name="grey">
        <color rgba="0.5 0.5 0.5 1" />
    </material>

    <link name="base_link">
        <visual>
            <geometry>
                <box size="0.6 0.4 0.2" />
            </geometry>
            <origin xyz="0 0 0.1" rpy="0 0 0" />
            <material name="blue" />
        </visual>
    </link>

    <link name="right_wheel_link">
        <visual>
            <geometry>
                <cylinder radius="0.1" length="0.05" />
            </geometry>
            <origin xyz="0 0 0" rpy="0 0 0" />
            <material name="grey" />
        </visual>
    </link>

    <joint name="base_right_wheel_joint" type="continuous">
        <parent link="base_link" />
        <child link="right_wheel_link" />
        <origin xyz="-0.15 -0.2 0" rpy="0 0 0" />
        <axis xyz="1 0 0" />
    </joint>

</robot>

The Result on RViz is the following:

image.png

image.png


Now we must determine about which axis must the joint rotate. It is obvious that we want the joint to rotate about the y-axis.

The modified code is the following:

<?xml version="1.0"?>
<robot name="my_robot">

    <material name="blue">
        <color rgba="0 0 0.5 1" />
    </material>

    <material name="grey">
        <color rgba="0.5 0.5 0.5 1" />
    </material>

    <link name="base_link">
        <visual>
            <geometry>
                <box size="0.6 0.4 0.2" />
            </geometry>
            <origin xyz="0 0 0.1" rpy="0 0 0" />
            <material name="blue" />
        </visual>
    </link>

    <link name="right_wheel_link">
        <visual>
            <geometry>
                <cylinder radius="0.1" length="0.05" />
            </geometry>
            <origin xyz="0 0 0" rpy="0 0 0" />
            <material name="grey" />
        </visual>
    </link>

    <joint name="base_right_wheel_joint" type="continuous">
        <parent link="base_link" />
        <child link="right_wheel_link" />
        <origin xyz="-0.15 -0.2 0" rpy="0 0 0" />
        <axis xyz="0 1 0" />
    </joint>

</robot>