Robotics StackExchange | Archived questions

URDF not visualizing correctly in rviz2

Hi all

I am running ROS2 Foxy on Ubuntu 12.04.

I am a NEWBIE.

As my first attempt at modelling my hexapod robot, I learnt URDF and XACRO and I am attempting to now visualize my robot in RVIZ2. - As part of learning my 'orientations' of joints, I throught that I could use the visualization to check design - so some orientations are probably still wrong as I learn how joints work! First problems first though!

After I launch RVIZ2 (launch file included later) and add the RobotModel component, I change the RobotModel/Description Source to 'file' and the description file to my urdf file, and my GlobalOptions/Fixed Frame to base_link. RVIZ now displays the 'body' of my robot only. When I look at the RobotModel/Links it lists all of the links. When I ask to show any of the child link axes it shows them at the center of my robot 'body'.

I appreciate any pointers on how to continue to troubleshoot this!

[launch file]

import os

from ament_index_python.packages import get_package_share_directory

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, ExecuteProcess, IncludeLaunchDescription
from launch.conditions import IfCondition
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration, PythonExpression
from launch_ros.actions import Node


def generate_launch_description():
    # Get the launch directory
    bringup_dir = get_package_share_directory('hex1')
    launch_dir = os.path.join(bringup_dir, 'launch')

    # Launch configuration variables specific to simulation
    rviz_config_file = LaunchConfiguration('rviz_config_file')
    use_robot_state_pub = LaunchConfiguration('use_robot_state_pub')
    use_joint_state_pub = LaunchConfiguration('use_joint_state_pub')
    use_rviz = LaunchConfiguration('use_rviz')
    urdf_file= LaunchConfiguration('urdf_file')


    declare_rviz_config_file_cmd = DeclareLaunchArgument(
        'rviz_config_file',
        default_value=os.path.join(bringup_dir, 'rviz', 'view.rviz'),
        description='Full path to the RVIZ config file to use')  
    declare_use_robot_state_pub_cmd = DeclareLaunchArgument(
        'use_robot_state_pub',
        default_value='True',
        description='Whether to start the robot state publisher')
    declare_use_joint_state_pub_cmd = DeclareLaunchArgument(
        'use_joint_state_pub',
        default_value='True',
        description='Whether to start the joint state publisher')
    declare_use_rviz_cmd = DeclareLaunchArgument(
        'use_rviz',
        default_value='True',
        description='Whether to start RVIZ')


    declare_urdf_cmd = DeclareLaunchArgument(
        'urdf_file',
        default_value=os.path.join(bringup_dir, 'urdf', 'hex1.xacro'),
        description='Whether to start RVIZ')


    start_robot_state_publisher_cmd = Node(
        condition=IfCondition(use_robot_state_pub),
        package='robot_state_publisher',
        executable='robot_state_publisher',
        name='robot_state_publisher',
        output='screen',
        #parameters=[{'use_sim_time': use_sim_time}],
        arguments=[urdf_file])

    start_joint_state_publisher_cmd = Node(
        condition=IfCondition(use_joint_state_pub),
        package='joint_state_publisher_gui',
        executable='joint_state_publisher_gui',
        name='joint_state_publisher_gui',
        output='screen',
        arguments=[urdf_file])

    rviz_cmd = Node(
        condition=IfCondition(use_rviz),
        package='rviz2',
        executable='rviz2',
        name='rviz2',
        arguments=['-d', rviz_config_file],
        output='screen')


    # Create the launch description and populate
    ld = LaunchDescription()

    # Declare the launch options
    ld.add_action(declare_rviz_config_file_cmd)
    ld.add_action(declare_urdf_cmd)
    ld.add_action(declare_use_robot_state_pub_cmd)
    ld.add_action(declare_use_joint_state_pub_cmd)
    ld.add_action(declare_use_rviz_cmd)


    # Add any conditioned actions
    ld.add_action(start_joint_state_publisher_cmd)
    ld.add_action(start_robot_state_publisher_cmd)
    ld.add_action(rviz_cmd)

    return ld   

[urdf file]

<?xml version="1.0" ?>
<!-- =================================================================================== -->
<!-- |    This document was autogenerated by xacro from hex1.xacro                     | -->
<!-- |    EDITING THIS FILE BY HAND IS NOT RECOMMENDED                                 | -->
<!-- =================================================================================== -->
<robot name="hex1">
  <material name="blue">
    <color rgba="0 0 0.8 1"/>
  </material>
  <material name="white">
    <color rgba=" 1 1 1 1"/>
  </material>
  <material name="black">
    <color grba="0 0 0 1"/>
  </material>
  <material name="grey">
    <color rgba="0.4 0.4 0.4 1.0"/>
  </material>
  <link name="base_link">
    <visual>
      <geometry>
        <box size="0.001 0.001 0.001"/>
      </geometry>
      <material name="black"/>
    </visual>
    <collision>
      <geometry>
        <box size="0.001 0.001 0.001"/>
      </geometry>
    </collision>
  </link>
  <link name="body_link">
    <visual>
      <geometry>
        <box size="0.16 0.16 0.045 "/>
      </geometry>
      <material name="white"/>
    </visual>
    <collision>
      <geometry>
        <box size="0.16 0.16 0.045 "/>
      </geometry>
    </collision>
  </link>
  <joint name="base_link_to_body_link" type="fixed">
    <parent link="base_link"/>
    <child link="body_link"/>
    <origin rpy="0.0 0.0 0.0" xyz="0.0 0.0 0.0"/>
  </joint>
  <link name="legFR_coxa_link">
    <visual>
      <geometry>
        <box size="0.065 0.04 0.04 "/>
      </geometry>
      <material name="blue"/>
    </visual>
    <collision>
      <geometry>
        <box size="0.065 0.04 0.04 "/>
      </geometry>
    </collision>
    <inertial>
      <mass value="10.0"/>
      <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" yz="0.0" zz="1.0"/>
    </inertial>
  </link>
  <joint name="body_to_legFR_coxa" type="revolute">
    <parent link="body_link"/>
    <child link="legFR_coxa_link"/>
    <limit effort="30" lower="1.0472" upper="2.43346" velocity="1.0"/>
    <origin rpy="0.0 0.0 0.0" xyz="0.08 0.08 0.0"/>
  </joint>
  <link name="legFR_femur_link">
    <visual>
      <geometry>
        <box size="0.085 0.041 0.025 "/>
      </geometry>
      <material name="white"/>
    </visual>
    <collision>
      <geometry>
        <box size="0.085 0.041 0.025 "/>
      </geometry>
    </collision>
    <inertial>
      <mass value="10.0"/>
      <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" yz="0.0" zz="1.0"/>
    </inertial>
  </link>
  <joint name="legFR_coxa_to_legFR_femur" type="revolute">
    <parent link="legFR_coxa_link"/>
    <child link="legFR_femur_link"/>
    <limit effort="30" lower="0.349066" upper="2.79254" velocity="1.0"/>
    <origin rpy="0 1.5708 0" xyz="0.0 0.065 0.0"/>
  </joint>
  <link name="legFR_tibia_link">
    <visual>
      <geometry>
        <cylinder length="0.18" radius="0.01"/>
      </geometry>
      <material name="grey"/>
    </visual>
    <collision>
      <geometry>
        <cylinder length="0.18" radius="0.01"/>
      </geometry>
    </collision>
    <inertial>
      <mass value="10.0"/>
      <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" yz="0.0" zz="1.0"/>
    </inertial>
  </link>
  <joint name="legFR_femur_to_legFR_tibia" type="revolute">
    <parent link="legFR_femur_link"/>
    <child link="legFR_tibia_link"/>
    <limit effort="30" lower="0.349066" upper="2.79254" velocity="1.0"/>
    <origin rpy="0 1.5708 0" xyz="0.0 0.065 0.0"/>
  </joint>
  <link name="legFL_coxa_link">
    <visual>
      <geometry>
        <box size="0.065 0.04 0.04 "/>
      </geometry>
      <material name="blue"/>
    </visual>
    <collision>
      <geometry>
        <box size="0.065 0.04 0.04 "/>
      </geometry>
    </collision>
    <inertial>
      <mass value="10.0"/>
      <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" yz="0.0" zz="1.0"/>
    </inertial>
  </link>
  <joint name="body_to_legFL_coxa" type="revolute">
    <parent link="body_link"/>
    <child link="legFL_coxa_link"/>
    <limit effort="30" lower="1.0472" upper="2.43346" velocity="1.0"/>
    <origin rpy="3.14159 0.0 0.0" xyz="0.08 -0.08 0.0"/>
  </joint>
  <link name="legFL_femur_link">
    <visual>
      <geometry>
        <box size="0.085 0.041 0.025 "/>
      </geometry>
      <material name="white"/>
    </visual>
    <collision>
      <geometry>
        <box size="0.085 0.041 0.025 "/>
      </geometry>
    </collision>
    <inertial>
      <mass value="10.0"/>
      <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" yz="0.0" zz="1.0"/>
    </inertial>
  </link>
  <joint name="legFL_coxa_to_legFL_femur" type="revolute">
    <parent link="legFL_coxa_link"/>
    <child link="legFL_femur_link"/>
    <limit effort="30" lower="0.349066" upper="2.79254" velocity="1.0"/>
    <origin rpy="0.0 -1.5708 0.0" xyz="0.0 0.065 0.0"/>
  </joint>
  <link name="legFL_tibia_link">
    <visual>
      <geometry>
        <cylinder length="0.18" radius="0.01"/>
      </geometry>
      <material name="grey"/>
    </visual>
    <collision>
      <geometry>
        <cylinder length="0.18" radius="0.01"/>
      </geometry>
    </collision>
    <inertial>
      <mass value="10.0"/>
      <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" yz="0.0" zz="1.0"/>
    </inertial>
  </link>
  <joint name="legFL_femur_to_legFL_tibia" type="revolute">
    <parent link="legFL_femur_link"/>
    <child link="legFL_tibia_link"/>
    <limit effort="30" lower="0.349066" upper="2.79254" velocity="1.0"/>
    <origin rpy="0.0 -1.5708 0.0" xyz="0.0 0.065 0.0"/>
  </joint>
  <link name="legMR_coxa_link">
    <visual>
      <geometry>
        <box size="0.065 0.04 0.04 "/>
      </geometry>
      <material name="blue"/>
    </visual>
    <collision>
      <geometry>
        <box size="0.065 0.04 0.04 "/>
      </geometry>
    </collision>
    <inertial>
      <mass value="10.0"/>
      <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" yz="0.0" zz="1.0"/>
    </inertial>
  </link>
  <joint name="body_to_legMR_coxa" type="revolute">
    <parent link="body_link"/>
    <child link="legMR_coxa_link"/>
    <limit effort="30" lower="1.0472" upper="2.43346" velocity="1.0"/>
    <origin rpy="0.0 0.0 0.0" xyz="0.0 0.08 0.0"/>
  </joint>
  <link name="legMR_femur_link">
    <visual>
      <geometry>
        <box size="0.085 0.041 0.025 "/>
      </geometry>
      <material name="white"/>
    </visual>
    <collision>
      <geometry>
        <box size="0.085 0.041 0.025 "/>
      </geometry>
    </collision>
    <inertial>
      <mass value="10.0"/>
      <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" yz="0.0" zz="1.0"/>
    </inertial>
  </link>
  <joint name="legMR_coxa_to_legMR_femur" type="revolute">
    <parent link="legMR_coxa_link"/>
    <child link="legMR_femur_link"/>
    <limit effort="30" lower="0.349066" upper="2.79254" velocity="1.0"/>
    <origin rpy="0 1.5708 0" xyz="0.0 0.065 0.0"/>
  </joint>
  <link name="legMR_tibia_link">
    <visual>
      <geometry>
        <cylinder length="0.18" radius="0.01"/>
      </geometry>
      <material name="grey"/>
    </visual>
    <collision>
      <geometry>
        <cylinder length="0.18" radius="0.01"/>
      </geometry>
    </collision>
    <inertial>
      <mass value="10.0"/>
      <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" yz="0.0" zz="1.0"/>
    </inertial>
  </link>
  <joint name="legMR_femur_to_legMR_tibia" type="revolute">
    <parent link="legMR_femur_link"/>
    <child link="legMR_tibia_link"/>
    <limit effort="30" lower="0.349066" upper="2.79254" velocity="1.0"/>
    <origin rpy="0 1.5708 0" xyz="0.0 0.065 0.0"/>
  </joint>
  <link name="legML_coxa_link">
    <visual>
      <geometry>
        <box size="0.065 0.04 0.04 "/>
      </geometry>
      <material name="blue"/>
    </visual>
    <collision>
      <geometry>
        <box size="0.065 0.04 0.04 "/>
      </geometry>
    </collision>
    <inertial>
      <mass value="10.0"/>
      <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" yz="0.0" zz="1.0"/>
    </inertial>
  </link>
  <joint name="body_to_legML_coxa" type="revolute">
    <parent link="body_link"/>
    <child link="legML_coxa_link"/>
    <limit effort="30" lower="1.0472" upper="2.43346" velocity="1.0"/>
    <origin rpy="3.14159 0.0 0.0" xyz="0.0 -0.08 0.0"/>
  </joint>
  <link name="legML_femur_link">
    <visual>
      <geometry>
        <box size="0.085 0.041 0.025 "/>
      </geometry>
      <material name="white"/>
    </visual>
    <collision>
      <geometry>
        <box size="0.085 0.041 0.025 "/>
      </geometry>
    </collision>
    <inertial>
      <mass value="10.0"/>
      <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" yz="0.0" zz="1.0"/>
    </inertial>
  </link>
  <joint name="legML_coxa_to_legML_femur" type="revolute">
    <parent link="legML_coxa_link"/>
    <child link="legML_femur_link"/>
    <limit effort="30" lower="0.349066" upper="2.79254" velocity="1.0"/>
    <origin rpy="0.0 -1.5708 0.0" xyz="0.0 0.065 0.0"/>
  </joint>
  <link name="legML_tibia_link">
    <visual>
      <geometry>
        <cylinder length="0.18" radius="0.01"/>
      </geometry>
      <material name="grey"/>
    </visual>
    <collision>
      <geometry>
        <cylinder length="0.18" radius="0.01"/>
      </geometry>
    </collision>
    <inertial>
      <mass value="10.0"/>
      <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" yz="0.0" zz="1.0"/>
    </inertial>
  </link>
  <joint name="legML_femur_to_legML_tibia" type="revolute">
    <parent link="legML_femur_link"/>
    <child link="legML_tibia_link"/>
    <limit effort="30" lower="0.349066" upper="2.79254" velocity="1.0"/>
    <origin rpy="0.0 -1.5708 0.0" xyz="0.0 0.065 0.0"/>
  </joint>
  <link name="legBR_coxa_link">
    <visual>
      <geometry>
        <box size="0.065 0.04 0.04 "/>
      </geometry>
      <material name="blue"/>
    </visual>
    <collision>
      <geometry>
        <box size="0.065 0.04 0.04 "/>
      </geometry>
    </collision>
    <inertial>
      <mass value="10.0"/>
      <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" yz="0.0" zz="1.0"/>
    </inertial>
  </link>
  <joint name="body_to_legBR_coxa" type="revolute">
    <parent link="body_link"/>
    <child link="legBR_coxa_link"/>
    <limit effort="30" lower="1.0472" upper="2.43346" velocity="1.0"/>
    <origin rpy="0.0 0.0 0.0" xyz="-0.08 0.08 0.0"/>
  </joint>
  <link name="legBR_femur_link">
    <visual>
      <geometry>
        <box size="0.085 0.041 0.025 "/>
      </geometry>
      <material name="white"/>
    </visual>
    <collision>
      <geometry>
        <box size="0.085 0.041 0.025 "/>
      </geometry>
    </collision>
    <inertial>
      <mass value="10.0"/>
      <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" yz="0.0" zz="1.0"/>
    </inertial>
  </link>
  <joint name="legBR_coxa_to_legBR_femur" type="revolute">
    <parent link="legBR_coxa_link"/>
    <child link="legBR_femur_link"/>
    <limit effort="30" lower="0.349066" upper="2.79254" velocity="1.0"/>
    <origin rpy="0 1.5708 0" xyz="0.0 0.065 0.0"/>
  </joint>
  <link name="legBR_tibia_link">
    <visual>
      <geometry>
        <cylinder length="0.18" radius="0.01"/>
      </geometry>
      <material name="grey"/>
    </visual>
    <collision>
      <geometry>
        <cylinder length="0.18" radius="0.01"/>
      </geometry>
    </collision>
    <inertial>
      <mass value="10.0"/>
      <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" yz="0.0" zz="1.0"/>
    </inertial>
  </link>
  <joint name="legBR_femur_to_legBR_tibia" type="revolute">
    <parent link="legBR_femur_link"/>
    <child link="legBR_tibia_link"/>
    <limit effort="30" lower="0.349066" upper="2.79254" velocity="1.0"/>
    <origin rpy="0 1.5708 0" xyz="0.0 0.065 0.0"/>
  </joint>
  <link name="legBL_coxa_link">
    <visual>
      <geometry>
        <box size="0.065 0.04 0.04 "/>
      </geometry>
      <material name="blue"/>
    </visual>
    <collision>
      <geometry>
        <box size="0.065 0.04 0.04 "/>
      </geometry>
    </collision>
    <inertial>
      <mass value="10.0"/>
      <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" yz="0.0" zz="1.0"/>
    </inertial>
  </link>
  <joint name="body_to_legBL_coxa" type="revolute">
    <parent link="body_link"/>
    <child link="legBL_coxa_link"/>
    <limit effort="30" lower="1.0472" upper="2.43346" velocity="1.0"/>
    <origin rpy="3.14159 0.0 0.0" xyz="-0.08 -0.08 0.0"/>
  </joint>
  <link name="legBL_femur_link">
    <visual>
      <geometry>
        <box size="0.085 0.041 0.025 "/>
      </geometry>
      <material name="white"/>
    </visual>
    <collision>
      <geometry>
        <box size="0.085 0.041 0.025 "/>
      </geometry>
    </collision>
    <inertial>
      <mass value="10.0"/>
      <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" yz="0.0" zz="1.0"/>
    </inertial>
  </link>
  <joint name="legBL_coxa_to_legBL_femur" type="revolute">
    <parent link="legBL_coxa_link"/>
    <child link="legBL_femur_link"/>
    <limit effort="30" lower="0.349066" upper="2.79254" velocity="1.0"/>
    <origin rpy="0.0 -1.5708 0.0" xyz="0.0 0.065 0.0"/>
  </joint>
  <link name="legBL_tibia_link">
    <visual>
      <geometry>
        <cylinder length="0.18" radius="0.01"/>
      </geometry>
      <material name="grey"/>
    </visual>
    <collision>
      <geometry>
        <cylinder length="0.18" radius="0.01"/>
      </geometry>
    </collision>
    <inertial>
      <mass value="10.0"/>
      <inertia ixx="1.0" ixy="0.0" ixz="0.0" iyy="1.0" yz="0.0" zz="1.0"/>
    </inertial>
  </link>
  <joint name="legBL_femur_to_legBL_tibia" type="revolute">
    <parent link="legBL_femur_link"/>
    <child link="legBL_tibia_link"/>
    <limit effort="30" lower="0.349066" upper="2.79254" velocity="1.0"/>
    <origin rpy="0.0 -1.5708 0.0" xyz="0.0 0.065 0.0"/>
  </joint>
</robot>

Asked by JF on 2021-03-31 10:25:34 UTC

Comments

Answers