Skip to content

로봇 모델 시각화

Indy Description 패키지

indy_description 패키지는 RVizGazebo 시뮬레이터에서 사용할 모델 파일(URDF)을 포함하고 있습니다.

├── indy_description
    ├── urdf
    ├── launch
    ├── rviz_config
    ├── meshes
    └──  ...

로봇 모델

  • URDF (The Universal Robotic Description Format): 로봇의 기구학 및 동역학적 요소를 기술하는 XML 형식 파일입니다.
  • Xacro: XML + Macro의 합성어로 로봇모델을 간단하게 메크로를 사용하여 XML 파일을 생성 할 수 있게 해줍니다.

indy_description 패키지의 urdf 폴더에는 Indy 모델(Indy7, Indy7v2, Indy12, Indy12v2, IndyRP, IndyRPv2)의 모든 구성을 포함하는 config 폴더가 있습니다. 다른 xacro 파일은 config 폴더의 파일을 읽고 로봇을 구성합니다.

아래 다이어그램은 파일 간의 관계를 보여줍니다.

joint_limits ────────┐
kinematics ──────────┤
physical_parameters ─┤
visual_parameters ───┴─ indy_common ─┐
                  indy.ros2_control ─┤
                  indy_transmission ─┤
                          materials ─┴─ indy_macro─indy.urdf

urdf 및 xacro에 대한 자세한 정보는 아래 링크를 참고하십시오.

RViz 실행

Indy 모델은 RViz2를 통해 시각화 될 수 있습니다. launch 파일은 한 번에 여러 ROS 노드를 시작하는 파일입니다. 다음 명령어를 통해 ROS2에서 Indy7 로봇 모델을 시각화 할 수 있습니다.

$ ros2 launch indy_description indy_display.launch.py indy_type:=indy7

indy_type을 "indy7"로 지정하면, launch 파일이 적절한 구성 파일을 로드하고 RViz와 같은 시각화 도구에 로봇을 표시하는 데 필요한 노드를 실행합니다.


아래와 같이 indy_eye 옵션을 true로 하게될 경우 IndyEye 모델 로봇을 시각화 할 수 있습니다.

$ ros2 launch indy_description indy_display.launch.py indy_type:=indy7 indy_eye:=true


joint_states_publisher의 관절 위치 값을 조정함으로써, RViz에서의 로봇의 위치를 변경할 수 있습니다.

Launch 파일

아래의 코드는 위의 명령에서의 indy_display.launch.py입니다.

#!/usr/bin/python3
#-*- coding: utf-8 -*-

from launch_ros.actions import Node
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch_ros.substitutions import FindPackageShare
from launch.substitutions import Command, FindExecutable, LaunchConfiguration, PathJoinSubstitution


def generate_launch_description():
    # Declare arguments
    declared_arguments = []

    declared_arguments.append(
        DeclareLaunchArgument(
            "name",
            default_value="indy"
        )
    )

    declared_arguments.append(
        DeclareLaunchArgument(
            "indy_type",
            default_value="indy7",
            description="Type of Indy robot.",
            choices=["indy7", "indy7_v2" , "indy12", "indy12_v2", "indyrp2", "indyrp2_v2"]
        )
    )

    declared_arguments.append(
        DeclareLaunchArgument(
            "indy_eye",
            default_value="false",
            description="Work with Indy Eye",
        )
    )

    declared_arguments.append(
        DeclareLaunchArgument(
            "prefix",
            default_value='""',
            description="Prefix of the joint names, useful for \
            multi-robot setup. If changed than also joint names in the controllers configuration \
            have to be updated."
        )
    )

    # Initialize Arguments
    name = LaunchConfiguration("name")
    indy_type = LaunchConfiguration("indy_type")
    indy_eye = LaunchConfiguration("indy_eye")
    prefix = LaunchConfiguration("prefix")

    description_package = FindPackageShare('indy_description')

    robot_description_content = Command(
        [
            PathJoinSubstitution([FindExecutable(name="xacro")]),
            " ",
            PathJoinSubstitution([description_package, "urdf", 'indy.urdf.xacro']),
            " ",
            "name:=",
            name,
            " ",
            "indy_type:=",
            indy_type,
            " ",
            "indy_eye:=",
            indy_eye,
            " ",
            "prefix:=",
            prefix
        ]
    )

    robot_description = {"robot_description": robot_description_content}

    rviz_config_file = PathJoinSubstitution(
        [description_package, "rviz_config", "indy.rviz"]
    )

    robot_state_publisher_node = Node(
        package="robot_state_publisher",
        executable="robot_state_publisher",
        output="screen",
        parameters=[robot_description]
    )

    joint_state_publisher_gui_node = Node(
        package='joint_state_publisher_gui',
        executable='joint_state_publisher_gui'
    )

    rviz_node = Node(
        package="rviz2",
        executable="rviz2",
        name="rviz2",
        output="log",
        arguments=["-d", rviz_config_file]
    )

    nodes = [
        joint_state_publisher_gui_node,
        robot_state_publisher_node,
        rviz_node,
    ]

    return LaunchDescription(declared_arguments + nodes)
  • robot_description: indy.urdf.xacro를 읽고, joint_state_publisher 노드에 대한 파라미터입니다.
  • joint_state_publisher: robot_description의 관절 위치를 /joint_states 토픽으로 게시합니다.
  • robot_state_publisher: /joint_states 토픽을 구독하고 각 링크의 transform을 게시합니다.
  • rviz : RViz 노드를 실행하고 rviz 설정 파일 (indy_description/rviz_config/indy.rviz)을 로드합니다. robot_state_publisher 노드에서 게시된 tf를 구독하고 시각화합니다.