ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Why can't my URDF be like my SDF in rviz?

asked 2021-08-13 14:28:55 -0600

kak13 gravatar image

updated 2022-03-25 17:41:10 -0600

lucasw gravatar image

So, basically...I learned that ROS2 foxy does not support SDF with plugins and ROS2. So, I had to re-update one for URDF instead of SDF. I made SDF enitrely from Gazebo11.

So, the question is why can't I put wheels on the box? Take a look at this URDF code:

<?xml version="1.0"?>
<robot name="my_robot" xmlns:xacro="http://ros.org/wiki/xacro">

  <!-- Define robot constants -->
  <xacro:property name="base_width" value="0.2159"/>
  <xacro:property name="base_length" value="0.1524"/>
  <xacro:property name="base_height" value="0.10795"/>

  <xacro:property name="wheel_radius" value="0.0325"/>
  <xacro:property name="wheel_width" value="0.02"/>
  <xacro:property name="wheel_ygap" value="0.088"/>
  <xacro:property name="wheel_zoff" value="0.05"/>
  <xacro:property name="wheel_xoff" value="0.1"/>

  <xacro:property name="caster_xoff" value="0.14"/>

 <!-- Robot Base -->
  <link name="base_link">
    <visual>
      <geometry>
    <box size="0.2159 0.1524 0.10795"/>
      </geometry>
      <material name="Cyan">
    <color rgba="0 1.0 1.0 1.0"/>
      </material>
    </visual>
  </link>

  <!-- Robot Footprint -->
  <link name="base_footprint"/>

  <joint name="base_joint" type="fixed">
    <parent link="base_link"/>
    <child link="base_footprint"/>
    <origin xyz="0.0 0.0 ${-(wheel_radius+wheel_zoff)}" rpy="0 0 0"/>
  </joint>

    <!-- Wheels -->
  <xacro:macro name="wheel" params="prefix x_reflect y_reflect">
    <link name="${prefix}_link">
      <visual>
    <origin xyz="0 0 0" rpy="${pi/2} 0 0"/>
    <geometry>
        <cylinder radius="${wheel_radius}" length="${wheel_width}"/>
    </geometry>
    <material name="Gray">
      <color rgba="0.5 0.5 0.5 1.0"/>
    </material>
      </visual>
    </link>


    <joint name="${prefix}_joint" type="continuous">
      <parent link="base_link"/>
      <child link="${prefix}_link"/>
      <origin xyz="${x_reflect*wheel_xoff} ${y_reflect*(base_width/6+wheel_ygap)} ${-wheel_zoff}" rpy="0 0 0"/>
      <axis xyz="0 1 0"/>
    </joint>
  </xacro:macro>

  <xacro:wheel prefix="drivewhl_rl" x_reflect="-1" y_reflect="1" />
  <xacro:wheel prefix="drivewhl_rr" x_reflect="-1" y_reflect="-1" />
  <xacro:wheel prefix="drivewhl_fl" x_reflect="1" y_reflect="1" />
  <xacro:wheel prefix="drivewhl_fr" x_reflect="1" y_reflect="-1" /> 



</robot>

The model look like this

image description

As for my SDF code and picture like this:

        <link name='chassis'>
        <pose>0 0 .1 0 0 0</pose>
        <inertial>
        <inertia>
        <ixx>1.000000</ixx>
        <ixy>0.000000</ixy>
        <ixz>0.000000</ixz>
        <iyy>1.000000</iyy>
        <iyz>0.000000</iyz>
        <izz>1.000000</izz>
        </inertia>
        <mass>1</mass>
        </inertial>
        <collision name='collision'>
          <geometry>
            <box>
              <size>0.2159 0.1524 0.10795</size>
            </box>
          </geometry>
        </collision>

        <visual name='visual'>
          <geometry>
            <box>
              <size>0.2159 0.1524 0.10795</size>
            </box>
          </geometry>
        </visual>
      </link>

    <link name="front_left_wheel">
    <pose>0.1 0.088 0.05 0 1.5707 1.5707</pose>
    <mass>0.75</mass>
    <collision name="collision">
      <geometry>
        <cylinder>
          <radius>0.0325</radius>
          <length>.02</length>
        </cylinder>
      </geometry>
    </collision>
    <visual name="visual">
      <geometry>
        <cylinder>
          <radius>0.0325</radius>
          <length> ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-08-16 08:00:45 -0600

Delb gravatar image

The wheels aren't attached to the box on your urdf because this formula is wrong :

y_reflect*(base_width/6+wheel_ygap) = +/- 0.12398333333

The correct way to calculate y_wheel is :

y_wheel =  y_reflect * (base_length/2 + wheel_width/2) = +/- 0.0862

Which is almost equal to your wheel_ygap (0.088) which is the same value for the link you've defined in the sdf file :

<pose>0.1 0.088 0.05 0 1.5707 1.5707</pose>
edit flag offensive delete link more

Comments

Oh my god! You have a beautiful soul!

It worked! (for some reason, it wouldn't let me upload the image but its literally same as SDF now)

I have another question if you don't mind :)

How do you set variable in urdf for ros to control single joint using python?

kak13 gravatar image kak13  ( 2021-08-16 10:55:56 -0600 )edit
1

Glad it worked. If you have another question you should create a new one to explain your issue, what you want to achieve and what you've tried so far.

Delb gravatar image Delb  ( 2021-08-17 02:22:45 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2021-08-13 14:28:55 -0600

Seen: 293 times

Last updated: Aug 16 '21