Skip to content

로봇 모델 시각화

Indy Description 패키지

1
2
3
4
5
6
├── indy_description
    ├── urdf
    ├── launch
    ├── rviz_config
    ├── meshes
    └──  ...

indy_description 패키지는 RViz와 Gazebo 시뮬레이터를 사용하기 위한 모델 파일 (URDF)을 포함하고 있습니다.

로봇 모델

URDF (Universal Robotic Description Format)는 로봇의 운동학적 및 동력학적 요소를 설명하는 XML 형식의 파일입니다. Xacro는 더 큰 XML 표현식으로 확장되는 매크로를 사용하여 더 짧고 읽기 쉬운 XML 파일을 구성하는 XML 매크로 언어입니다. indy_description 패키지의 urdf 폴더에는 Indy 모델 (Indy7, Indy7 V2, Indy12, Indy12 v2, IndyRP, IndyRP V2)에 대한 모든 설정을 포함하는 config 폴더가 있습니다. 다른 xacro 파일들은 설정 파일을 읽고 로봇의 설명을 작성합니다.

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

1
2
3
4
5
6
7
joint_limits ────────┐
kinematics ──────────┤
physical_parameters ─┤
visual_parameters ───┴─ indy_common ─┐
                  indy.ros2_control ─┤
                  indy_transmission ─┤
                          materials ─┴─ indy_macro─indy.urdf

urdf 및 xacro에 대한 자세한 정보는 ROS2 build model tutorial를 참조하세요.

RViz 실행

Indy 모델은 RViz2를 통해 시각화 될 수 있습니다. launch 파일은 한 번에 여러 ROS 노드를 시작하는 파일입니다. 아래의 명령어는 Indy7 로봇 모델에 대한 로봇 설명과 시각화를 실행하는 데 사용됩니다.

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

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

이제 창이 실행되는 것을 볼 수 있습니다.


indy eye 옵션과 함께 실행합니다.

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


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

Launch 파일

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

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
#!/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를 구독하고 시각화합니다.