(转载请注明作者和出处:https://yangningbocn.github.io 未经允许请勿用于商业用途)
本博客只是个人学习记录使用,瞎写写,内容比较粗糙。编写过程中,借鉴了古月居大神的smartcar和ROS-WIKI以及其它一些大神的内容。
引入古月居大神的链接使用smartcar进行仿真和smartcar源码上传
下面我针对自己的机器人编写的代码和文件。
launch文件
<launch>
<param name="/use_sim_time" value="false" />
<!-- Load the URDF/Xacro model of our robot -->
<arg name="urdf_file" default="$(find xacro)/xacro.py '$(find smartcar_description)/urdf/smartcar.urdf.xacro'" />
<arg name="gui" default="true" />
<param name="robot_description" command="$(arg urdf_file)" />
<param name="use_gui" value="$(arg gui)"/>
<node name="arbotix" pkg="arbotix_python" type="arbotix_driver" output="screen">
<rosparam file="$(find smartcar_description)/config/smartcar_arbotix.yaml" command="load" />
<param name="sim" value="true"/>
</node>
<node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" >
</node>
<node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher">
<param name="publish_frequency" type="double" value="20.0" />
</node>
<!-- We need a static transforms for the wheels -->
<node pkg="tf" type="static_transform_publisher" name="odom_left_wheel_broadcaster" args="0 0 0 0 0 0 /base_link /left_front_link 100" />
<node pkg="tf" type="static_transform_publisher" name="odom_right_wheel_broadcaster" args="0 0 0 0 0 0 /base_link /right_front_link 100" />
<node name="rviz" pkg="rviz" type="rviz" args="-d $(find smartcar_description)/urdf.rviz" />
</launch>
xacro文件包括三部分:
- smartcar_body
<?xml version="1.0"?>
<robot name="smartcar" xmlns:xacro="http://ros.org/wiki/xacro">
<xacro:property name="M_PI" value="3.14159"/>
<!-- Macro for SmartCar body. Including Gazebo extensions, but does not include Kinect -->
<xacro:include filename="$(find smartcar_description)/urdf/gazebo.urdf.xacro"/>
<xacro:property name="base_x" value="0.33" />
<xacro:property name="base_y" value="0.33" />
<xacro:macro name="smartcar_body">
<link name="base_footprint">
<inertial>
<mass value="0.0001" />
<origin xyz="0 0 0" />
<inertia ixx="0.0001" ixy="0.0" ixz="0.0"
iyy="0.0001" iyz="0.0"
izz="0.0001" />
</inertial>
<visual>
<origin xyz="0 0 0" rpy="0 0 0" />
<geometry>
<box size="0.001 0.001 0.001" />
</geometry>
</visual>
</link>
<joint name="base_footprint_joint" type="fixed">
<origin xyz="0 0 0" rpy="0 0 0" />
<parent link="base_footprint"/>
<child link="base_link" />
</joint>
<link
name="base_link">
<inertial>
<origin
xyz="0.0032273 -0.060593 1.3595E-05"
rpy="0 0 0" />
<mass
value="4.2623" />
<inertia
ixx="0.04568"
ixy="-0.00094545"
ixz="-8.9814E-06"
iyy="0.11402"
iyz="5.3399E-06"
izz="0.11035" />
</inertial>
<visual>
<origin
xyz="0 0 0.23"
rpy="0 0 0" />
<geometry>
<mesh
filename="package://smartcar_description/meshes/base_link.STL" />
</geometry>
<material
name="">
<color
rgba="1 1 1 1" />
</material>
</visual>
<collision>
<origin
xyz="0 0 0.23"
rpy="0 0 0" />
<geometry>
<mesh
filename="package://smartcar_description/meshes/base_link.STL" />
</geometry>
</collision>
</link>
<link
name="left_front_wheel">
<inertial>
<origin
xyz="0 -1.98217916108356E-05 0"
rpy="0 0 0" />
<mass
value="0.176438810476987" />
<inertia
ixx="8.8965933887671E-05"
ixy="-1.27636183461175E-23"
ixz="8.0831821149659E-23"
iyy="8.89898462049031E-05"
iyz="2.16519665002917E-23"
izz="0.000130905430632044" />
</inertial>
<visual>
<origin
xyz="0 0 0"
rpy="0 0 0" />
<geome