직접 패키지를 만들고, 이동 로봇을 만들어서 키보드를 활용해 맵에서 움직여보자.

스크린샷 2024-04-01 오후 7.03.29.png

body.xacro

URDF의 확장으로 사용되며, XML 형식을 통해 로봇 모델을 더 간결하고 가독성이 높게 표현할 수 있도록 도와준다. Xacro 파일은 XML 형식을 가지고 있지만, 일반적으로 URDF 파일에서 반복되는 부분을 매크로로 정의하여 재사용할 수 있다.

URDF vs SDF

  1. URDF (Unified Robot Description Format):
  2. SDF (Simulation Description Format):

Code

<?xml version="1.0"?>

    <robot xmlns:xacro="<http://www.ros.org/wiki/xacro>" name="mobile_robot">

    <link name="body">
        <visual>
            <geometry>
                <box size="2 1 0.7"/>
            </geometry>
        </visual>

        <collision>
            <geometry>
                <box size="2 1 0.7"/>
            </geometry>
        </collision>

        <inertial>
          <mass value="4"/>
          <inertia ixx="0.4967" ixy="0.0" ixz="0" iyy="1.4967" iyz="0" izz="1.6667"/>
        </inertial>
    </link>

<!--............................................rf_wheel...................................................... -->  

    <link name= "rf_wheel">
        <visual>
	        <origin rpy="1.570795 0 0" xyz="0 0 0"/>
	        <geometry>
	            <cylinder length="0.2" radius="0.5"/>
	        </geometry>
        </visual>
      
        <collision>
	        <origin rpy="1.570795 0 0" xyz="0 0 0"/>
	            <geometry>
	                <cylinder length="0.2" radius="0.5"/>
	            </geometry>
        </collision>

        <inertial>
	        <origin rpy="1.570795 0 0" xyz="0 0 0"/> 
            <mass value="1"/>
            <inertia ixx="0.06583" ixy="0.0" ixz="0.0" iyy="0.06583" iyz="0.0" izz="0.125"/>
        </inertial>
    </link>

    <joint name="body_rf_wheel" type="continuous">
        <axis xyz="0 1 0"/>
        <parent link="body"/>
        <child link="rf_wheel"/>
        <origin rpy="0 0 0" xyz="0.7 -0.6 0"/>
        <limit effort="100" velocity="1.0"/>  
    </joint>

<!--............................................rb_wheel...................................................... -->        

    <link name= "rb_wheel">
        <visual>
	        <origin rpy="1.570795 0 0" xyz="0 0 0"/>
	        <geometry>
	            <cylinder length="0.2" radius="0.5"/>
	        </geometry>
        </visual>
      
        <collision>
	        <origin rpy="1.570795 0 0" xyz="0 0 0"/>
	        <geometry>
	            <cylinder length="0.2" radius="0.5"/>
	        </geometry>
        </collision>

        <inertial>
	        <origin rpy="1.570795 0 0" xyz="0 0 0"/> 
            <mass value="1"/>
            <inertia ixx="0.06583" ixy="0.0" ixz="0.0" iyy="0.06583" iyz="0.0" izz="0.125"/>
        </inertial>
    </link>

    <joint name="body_rb_wheel" type="continuous">
        <axis xyz="0 1 0"/>
        <parent link="body"/>
        <child link="rb_wheel"/>
        <origin rpy="0 0 0" xyz="-0.7 -0.6 0"/>
        <limit effort="100" velocity="1.0"/>
    </joint>

<!--............................................lf_wheel...................................................... -->      

    <link name= "lf_wheel">
        <visual>
	        <origin rpy="1.570795 0 0" xyz="0 0 0"/>
	        <geometry>
	            <cylinder length="0.2" radius="0.5"/>
	        </geometry>
        </visual>
      
        <collision>
	        <origin rpy="1.570795 0 0" xyz="0 0 0"/>
	        <geometry>
	            <cylinder length="0.2" radius="0.5"/>
	        </geometry>
        </collision>

        <inertial>
	        <origin rpy="1.570795 0 0" xyz="0 0 0"/> 
            <mass value="1"/>
            <inertia ixx="0.06583" ixy="0.0" ixz="0.0" iyy="0.06583" iyz="0.0" izz="0.125"/>
        </inertial>
    </link>

    <joint name="body_lf_wheel" type="continuous">
        <axis xyz="0 1 0"/>
        <parent link="body"/>
        <child link="lf_wheel"/>
        <origin rpy="0 0 0" xyz="0.7 0.6 0"/>
        <limit effort="100" velocity="1.0"/>
    </joint>

<!--............................................lb_wheel...................................................... -->  

    <link name= "lb_wheel">
        <visual>
	        <origin rpy="1.570795 0 0" xyz="0 0 0"/>
	        <geometry>
	            <cylinder length="0.2" radius="0.5"/>
	        </geometry>
        </visual>
      
        <collision>
	        <origin rpy="1.570795 0 0" xyz="0 0 0"/>
	        <geometry>
	            <cylinder length="0.2" radius="0.5"/>
	        </geometry>
        </collision>

        <inertial>
	        <origin rpy="1.570795 0 0" xyz="0 0 0"/> 
            <mass value="1"/>
            <inertia ixx="0.06583" ixy="0.0" ixz="0.0" iyy="0.06583" iyz="0.0" izz="0.125"/>
        </inertial>
    </link>

    <joint name="body_lb_wheel" type="continuous">
        <axis xyz="0 1 0"/>
        <parent link="body"/>
        <child link="lb_wheel"/>
        <origin rpy="0 0 0" xyz="-0.7 0.6 0"/>
        <limit effort="100" velocity="1.0"/>
    </joint>

<!--............................................trnasmission...................................................... -->  

    <transmission name="rf_transmission">
        <type>transmission_interface/SimpleTransmission</type>
        <actuator name="rf_motor">
            <mechanicalReduction>1</mechanicalReduction>
        </actuator>
        <joint name="body_rf_wheel">
            <hardwareInterface>hardware_interface/PositionJointInterface</hardwareInterface>
        </joint>
    </transmission>

    <transmission name="rb_transmission">
        <type>transmission_interface/SimpleTransmission</type>
        <actuator name="rb_motor">
            <mechanicalReduction>1</mechanicalReduction>
        </actuator>
        <joint name="body_rb_wheel">
            <hardwareInterface>hardware_interface/PositionJointInterface</hardwareInterface>
        </joint>
    </transmission>

    <transmission name="lf_transmission">
        <type>transmission_interface/SimpleTransmission</type>
        <actuator name="lf_motor">
            <mechanicalReduction>1</mechanicalReduction>
        </actuator>
        <joint name="body_lf_wheel">
            <hardwareInterface>hardware_interface/PositionJointInterface</hardwareInterface>
        </joint>
    </transmission>

    <transmission name="lb_transmission">
        <type>transmission_interface/SimpleTransmission</type>
        <actuator name="lb_motor">
            <mechanicalReduction>1</mechanicalReduction>
        </actuator>
        <joint name="body_lb_wheel">
            <hardwareInterface>hardware_interface/PositionJointInterface</hardwareInterface>
        </joint>
    </transmission>

    <gazebo>
        <plugin name="skid_steer_drive_controller" filename="libgazebo_ros_skid_steer_drive.so">
   	        <updateRate>100.0</updateRate>
   	        <robotNamespace>/</robotNamespace>
   	        <leftFrontJoint>body_lf_wheel</leftFrontJoint>
   	        <rightFrontJoint>body_rf_wheel</rightFrontJoint>
   	        <leftRearJoint>body_lb_wheel</leftRearJoint>
   	        <rightRearJoint>body_rb_wheel</rightRearJoint>
  	        <wheelSeparation>0.2</wheelSeparation>
  	        <wheelDiameter>0.4</wheelDiameter>
	        <torque>100</torque>
  	        <robotBaseFrame>body</robotBaseFrame>
  	        <topicName>cmd_vel</topicName>
  	        <broadcastTF>false</broadcastTF>
  	    </plugin>
    </gazebo>

</robot>