urdf 작성하여 rviz로 표시하기

tutorial site를 참조하여 실습을 했다. 로봇 살 돈이 없어 몸으로 때우는 수 밖에. 요즘 원자재와 공급망 이슈로 값도 오르고 구하기도 힘들다. 막상 사 보면 그렇게 자주 쓰이지도 않아 보인다.

https://www.notion.so/2-2-1-URDF-930e055d01ee49cd859ac02ea8770325

http://wiki.ros.org/urdf/Tutorials/Building%20a%20Visual%20Robot%20Model%20with%20URDF%20from%20Scratch

3차원 그래픽을 직접 수정하여 각 좌표를 찾으면 쉬운데, URDF 형식이 지원하지 않는다. 각 부품이 어디에 붙는지 계산하여 직접 입력해야 한다.

urdf를 수정 한 후 rviz로 보면 No transform from A to B 메세지가 나오면서 link가 표시되지 않는다. 다음 순서대로 실행하면 된다.

  1. tutorial 참조하여 launch 파일 작성. robot_state_publisher와 joint_state_publisher를 launch에 넣어야 한다.
  2. roslaunch로 launch 실행
  3. rviz 실행
<launch>
    <param name="robot_description" command="$(find xacro)/xacro $(find robot)/urdf/robot.urdf" />
<node pkg="robot_state_publisher" type="robot_state_publisher" name="robot_state_publisher"/>
<node pkg="joint_state_publisher_gui" type="joint_state_publisher_gui" name="joint_state_publisher_gui"/>

</launch>

rviz를 한버만 실행하고 launch 하면 no transform 메세지를 본다. urdf 파일 만들 때 각 수치를 정확하게 알 수 없어 귀찮아서 rviz를 한 번 켜놓고 끄질 않는데, 이 때문에 안 보인다. gui툴로 표시된 슬라이더를 돌리면 좌표가 회전됨을 확인 할 수 있다.

능력자는 잘 만들겠지만, 내 수준에서는 바퀴 두 개도 겨우 따라 했다. material은 rgb 코드를 255로 나눠줘야 한다.

<?xml version="1.0" ?>
<robot name="mobile_robot" xmlns:xacro="http://www.ros.org/wiki/xacro">
	<material name="blue">
		<color rgba = "0 0 0.8 1"/>
	</material>

	<material name="gray">
		<color rgba = "1 1 1 1"/>
	</material>

	<material name="blueviolet">
		<color rgba = "0.54 0.16 0.88 1"/>
	</material>
	<link name = "base_footprint"/>
	<link name="base_link">
		<visual>
			<origin xyz="0 0 0" rpy = "0 0 0"/>
			<geometry>
				<box size = "0.3 0.24 0.1" rpy = "0 0 0" />
			</geometry>
			<material name = "gray"/>

		</visual>
		<collision>
			<origin xyz="0 0 0.03" rpy = "0 0 0"/>
			<geometry>
				<box size = "0.3 0.25 0.1" />
			</geometry>

		</collision>
	</link>
	<joint name = "base_footprint_fixed" type = "fixed">
		<origin xyz = "0 0 0.03" rpy = "0 0 0"/>
		<parent link = "base_footprint"/>
		<child link = "base_link"/>
	</joint>


	<link name = "left_wheel">
		<visual>
			<origin xyz = "0 0 0" rpy = "1.570796 0 0" />
			<geometry>
				<cylinder length = "0.05" radius = "0.08" />
			</geometry>
			<material name ="blue"/>

		</visual>
		<collision>
			<origin xyz = "0 0 0" rpy = "1.570796 0 0" />
			<geometry>
				<cylinder length = "0.05" radius = "0.08" />
			</geometry>

		</collision>

	</link>

	<link name = "right_wheel">
		<visual>
			<origin xyz = "0 0 0" rpy = "1.570796 0 0" />
			<geometry>
				<cylinder length = "0.05" radius = "0.08" />
			</geometry>
			<material name ="blue"/>

		</visual>
		<collision>
			<origin xyz = "0 0 0" rpy = "1.570796 0 0" />
			<geometry>
				<cylinder length = "0.05" radius = "0.08" />
			</geometry>

		</collision>

	</link>


	<joint name = "left_wheel_joint" type = "continuous">
		<origin xyz = "0.1 0.15 0" rpy = "0 0 0"/>
		<parent link = "base_link"/>
		<child link = "left_wheel"/>
		<axis xyz = "0 1 0"/>

	</joint>

	<joint name = "right_wheel_joint" type = "continuous">
		<origin xyz = "0.1 -0.15 0" rpy = "0 0 0"/>
		<parent link = "base_link"/>
		<child link = "right_wheel"/>
		<axis xyz = "0 1 0" />

	</joint>

	<link name="scanner_link">
		<visual>
			<origin xyz="0 0 0" rpy = "0 0 0"/>
			<geometry>
				<cylinder length="0.05" radius="0.035"/>
			</geometry>
			<material name = "blueviolet"/>

		</visual>
		<collision>
			<origin xyz="0 0 0" rpy = "0 0 0"/>
			<geometry>
				<cylinder length="0.05" radius="0.035"/>
			</geometry>

		</collision>
	</link>

	<joint name = "head_scanner" type = "fixed">
		<origin xyz = "0.15 0 0" rpy = "0 1.5708 0"/>
		<parent link = "base_link"/>
		<child link = "scanner_link"/>
	</joint>
</robot>

코멘트

댓글 남기기

이 사이트는 Akismet을 사용하여 스팸을 줄입니다. 댓글 데이터가 어떻게 처리되는지 알아보세요.