1. 관련 패키지 설치
sudo apt install liburdfdom-tools ros-melodic-joint-state-publisher-gui
2. 패키지 및 작업 폴더 생성
cd ~/${workspack_name}/src # cd ~/ros_ws/src
catkin_create_pkg ${package_name} roscpp tf geometry_msgs urdf rviz xacro # catkin_create_pkg urdf_example roscpp tf geometry_msgs urdf rviz xacro
cd ../ && catkin_make
rospack find ${package_name} # rospack find urdf_example
cd src/${package_name} # cd src/urdf_example
mkdir urdf
mkdir launch
3. urdf 파일 작성하기
cd urdf
로 경로를 이동한다
vi my_robot.urdf
로 파일을 오픈한 뒤, 아래의 내용을 작성한다<robot name="test_robot"> <link name="link1" /> <link name="link2" /> <link name="link3" /> <link name="link4" /> <joint name="joint1" type="continuous"> <parent link="link1"/> <child link="link2"/> <origin xyz="5 3 0" rpy="0 0 0" /> <axis xyz="-0.9 0.15 0" /> </joint> <joint name="joint2" type="continuous"> <parent link="link1"/> <child link="link3"/> <origin xyz="-2 5 0" rpy="0 0 1.57" /> <axis xyz="-0.707 0.707 0" /> </joint> <joint name="joint3" type="continuous"> <parent link="link3"/> <child link="link4"/> <origin xyz="5 0 0" rpy="0 0 -1.57" /> <axis xyz="0.707 -0.707 0" /> </joint> </robot>
4. launch 파일 작성 및 실행
cd ../launch
경로로 이동한다
vi view_my_robot.launch
로 파일을 생성한 뒤, 아래의 내용을 작성한다<launch> <arg name="model" /> <param name="robot_description" textfile="$(find urdf_example)/urdf/my_robot.urdf" /> <param name="use_gui" value="true"/> <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" /> <node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher" /> <node name="rviz" pkg="rviz" type="rviz" args="-d $(find urdf_example)/urdf.rviz" required="True" /> </launch>
5. RVIZ 속성 변경
6. 참고
urdf/Tutorials/Create your own urdf file - ROS Wiki
urdf/Tutorials/Parse a urdf file - ROS Wiki
ros_ws/src/urdf_example at master · SwimingKim/ros_ws
Contribute to SwimingKim/ros_ws development by creating an account on GitHub.
