计算机视觉
图像处理

ROS探索总结(六)——使用smartcar进行仿真

文章目录

之前的博客中,我们使用rviz进行了TurtleBot的仿真,而且使用urdf文件建立了自己的机器人smartcar,本篇博客是将两者进行结合,使用smartcar机器人在rviz中进行仿真。

一、模型完善

        之前我们使用的都是urdf文件格式的模型,在很多情况下,ROS对urdf文件的支持并不是很好,使用宏定义的.xacro文件兼容性更好,扩展性也更好。所以我们把之前的urdf文件重新整理编写成.xacro文件。
.xacro文件主要分为三部分:

1、机器人主体

  1. <?xml version=”1.0″?>
  2. <robot name=”smartcar” xmlns:xacro=”http://ros.org/wiki/xacro”>
  3.   <property name=”M_PI” value=”3.14159″/>
  4.   <!– Macro for SmartCar body. Including Gazebo extensions, but does not include Kinect –>
  5.   <include filename=”$(find smartcar_description)/urdf/gazebo.urdf.xacro”/>
  6.   <property name=”base_x” value=”0.33″ />
  7.   <property name=”base_y” value=”0.33″ />
  8.   <xacro:macro name=”smartcar_body”>
  9.     <link name=”base_link”>
  10.     <inertial>
  11.       <origin xyz=”0 0 0.055″/>
  12.       <mass value=”1.0″ />
  13.       <inertia ixx=”1.0″ ixy=”0.0″ ixz=”0.0″ iyy=”1.0″ iyz=”0.0″ izz=”1.0″/>
  14.     </inertial>
  15.     <visual>
  16.       <geometry>
  17.         <box size=”0.25 .16 .05″/>
  18.       </geometry>
  19.       <origin rpy=”0 0 0″ xyz=”0 0 0.055″/>
  20.       <material name=”blue”>
  21.       <color rgba=”0 0 .8 1″/>
  22.       </material>
  23.    </visual>
  24.    <collision>
  25.       <origin rpy=”0 0 0″ xyz=”0 0 0.055″/>
  26.       <geometry>
  27.         <box size=”0.25 .16 .05″ />
  28.       </geometry>
  29.     </collision>
  30.   </link>
  31.  <link name=”left_front_wheel”>
  32.     <inertial>
  33.       <origin  xyz=”0.08 0.08 0.025″/>
  34.       <mass value=”0.1″ />
  35.        <inertia ixx=”1.0″ ixy=”0.0″ ixz=”0.0″ iyy=”1.0″ iyz=”0.0″ izz=”1.0″/>
  36.     </inertial>
  37.     <visual>
  38.       <geometry>
  39.         <cylinder length=”.02″ radius=”0.025″/>
  40.       </geometry>
  41.       <material name=”black”>
  42.         <color rgba=”0 0 0 1″/>
  43.       </material>
  44.     </visual>
  45.     <collision>
  46.       <origin rpy=”0 1.57075 1.57075″ xyz=”0.08 0.08 0.025″/>
  47.       <geometry>
  48.          <cylinder length=”.02″ radius=”0.025″/>
  49.       </geometry>
  50.     </collision>
  51.   </link>
  52.   <joint name=”left_front_wheel_joint” type=”continuous”>
  53.     <axis xyz=”0 0 1″/>
  54.     <parent link=”base_link”/>
  55.     <child link=”left_front_wheel”/>
  56.     <origin rpy=”0 1.57075 1.57075″ xyz=”0.08 0.08 0.025″/>
  57.     <limit effort=”100″ velocity=”100″/>
  58.     <joint_properties damping=”0.0″ friction=”0.0″/>
  59.   </joint>
  60.   <link name=”right_front_wheel”>
  61.     <inertial>
  62.       <origin xyz=”0.08 -0.08 0.025″/>
  63.       <mass value=”0.1″ />
  64.        <inertia ixx=”1.0″ ixy=”0.0″ ixz=”0.0″ iyy=”1.0″ iyz=”0.0″ izz=”1.0″/>
  65.     </inertial>
  66.     <visual>
  67.       <geometry>
  68.         <cylinder length=”.02″ radius=”0.025″/>
  69.       </geometry>
  70.       <material name=”black”>
  71.         <color rgba=”0 0 0 1″/>
  72.       </material>
  73.     </visual>
  74.     <collision>
  75.       <origin rpy=”0 1.57075 1.57075″ xyz=”0.08 -0.08 0.025″/>
  76.       <geometry>
  77.          <cylinder length=”.02″ radius=”0.025″/>
  78.       </geometry>
  79.     </collision>
  80.   </link>
  81.   <joint name=”right_front_wheel_joint” type=”continuous”>
  82.     <axis xyz=”0 0 1″/>
  83.     <parent link=”base_link”/>
  84.     <child link=”right_front_wheel”/>
  85.     <origin rpy=”0 1.57075 1.57075″ xyz=”0.08 -0.08 0.025″/>
  86.     <limit effort=”100″ velocity=”100″/>
  87.     <joint_properties damping=”0.0″ friction=”0.0″/>
  88.  </joint>
  89.  <link name=”left_back_wheel”>
  90.     <inertial>
  91.       <origin xyz=”-0.08 0.08 0.025″/>
  92.       <mass value=”0.1″ />
  93.        <inertia ixx=”1.0″ ixy=”0.0″ ixz=”0.0″ iyy=”1.0″ iyz=”0.0″ izz=”1.0″/>
  94.     </inertial>
  95.     <visual>
  96.       <geometry>
  97.         <cylinder length=”.02″ radius=”0.025″/>
  98.       </geometry>
  99.       <material name=”black”>
  100.         <color rgba=”0 0 0 1″/>
  101.       </material>
  102.    </visual>
  103.    <collision>
  104.        <origin rpy=”0 1.57075 1.57075″ xyz=”-0.08 0.08 0.025″/>
  105.       <geometry>
  106.          <cylinder length=”.02″ radius=”0.025″/>
  107.       </geometry>
  108.     </collision>
  109.   </link>
  110.   <joint name=”left_back_wheel_joint” type=”continuous”>
  111.     <axis xyz=”0 0 1″/>
  112.     <parent link=”base_link”/>
  113.     <child link=”left_back_wheel”/>
  114.     <origin rpy=”0 1.57075 1.57075″ xyz=”-0.08 0.08 0.025″/>
  115.     <limit effort=”100″ velocity=”100″/>
  116.     <joint_properties damping=”0.0″ friction=”0.0″/>
  117.   </joint>
  118.   <link name=”right_back_wheel”>
  119.     <inertial>
  120.        <origin xyz=”-0.08 -0.08 0.025″/>
  121.        <mass value=”0.1″ />
  122.        <inertia ixx=”1.0″ ixy=”0.0″ ixz=”0.0″ iyy=”1.0″ iyz=”0.0″ izz=”1.0″/>
  123.     </inertial>
  124.     <visual>
  125.       <geometry>
  126.         <cylinder length=”.02″ radius=”0.025″/>
  127.       </geometry>
  128.       <material name=”black”>
  129.         <color rgba=”0 0 0 1″/>
  130.       </material>
  131.    </visual>
  132.    <collision>
  133.       <origin rpy=”0 1.57075 1.57075″ xyz=”-0.08 -0.08 0.025″/>
  134.       <geometry>
  135.          <cylinder length=”.02″ radius=”0.025″/>
  136.       </geometry>
  137.     </collision>
  138.   </link>
  139.   <joint name=”right_back_wheel_joint” type=”continuous”>
  140.     <axis xyz=”0 0 1″/>
  141.     <parent link=”base_link”/>
  142.     <child link=”right_back_wheel”/>
  143.     <origin rpy=”0 1.57075 1.57075″ xyz=”-0.08 -0.08 0.025″/>
  144.     <limit effort=”100″ velocity=”100″/>
  145.     <joint_properties damping=”0.0″ friction=”0.0″/>
  146.   </joint>
  147.   <link name=”head”>
  148.     <inertial>
  149.       <origin xyz=”0.08 0 0.08″/>
  150.       <mass value=”0.1″ />
  151.       <inertia ixx=”1.0″ ixy=”0.0″ ixz=”0.0″ iyy=”1.0″ iyz=”0.0″ izz=”1.0″/>
  152.     </inertial>
  153.     <visual>
  154.       <geometry>
  155.         <box size=”.02 .03 .03″/>
  156.       </geometry>
  157.       <material name=”white”>
  158.         <color rgba=”1 1 1 1″/>
  159.       </material>
  160.      </visual>
  161.      <collision>
  162.       <origin xyz=”0.08 0 0.08″/>
  163.       <geometry>
  164.          <cylinder length=”.02″ radius=”0.025″/>
  165.       </geometry>
  166.     </collision>
  167.   </link>
  168.   <joint name=”tobox” type=”fixed”>
  169.     <parent link=”base_link”/>
  170.     <child link=”head”/>
  171.     <origin xyz=”0.08 0 0.08″/>
  172.   </joint>
  173.   </xacro:macro>
  174. </robot>

2、gazebo属性部分

  1. <?xml version=”1.0″?>
  2. <robot xmlns:controller=”http://playerstage.sourceforge.net/gazebo/xmlschema/#controller”
  3.     xmlns:interface=”http://playerstage.sourceforge.net/gazebo/xmlschema/#interface”
  4.     xmlns:sensor=”http://playerstage.sourceforge.net/gazebo/xmlschema/#sensor”
  5.     xmlns:xacro=”http://ros.org/wiki/xacro”
  6.     name=”smartcar_gazebo”>
  7. <!– ASUS Xtion PRO camera for simulation –>
  8. <!– gazebo_ros_wge100 plugin is in kt2_gazebo_plugins package –>
  9. <xacro:macro name=”smartcar_sim”>
  10.     <gazebo reference=”base_link”>
  11.         <material>Gazebo/Blue</material>
  12.     </gazebo>
  13.     <gazebo reference=”right_front_wheel”>
  14.         <material>Gazebo/FlatBlack</material>
  15.     </gazebo>
  16.     <gazebo reference=”right_back_wheel”>
  17.         <material>Gazebo/FlatBlack</material>
  18.     </gazebo>
  19.     <gazebo reference=”left_front_wheel”>
  20.         <material>Gazebo/FlatBlack</material>
  21.     </gazebo>
  22.     <gazebo reference=”left_back_wheel”>
  23.         <material>Gazebo/FlatBlack</material>
  24.     </gazebo>
  25.     <gazebo reference=”head”>
  26.         <material>Gazebo/White</material>
  27.     </gazebo>
  28. </xacro:macro>
  29. </robot>

3、主文件

  1. <span style=”font-size:14px;”><?xml version=”1.0″?>
  2. <robot name=”smartcar”
  3.     xmlns:xi=”http://www.w3.org/2001/XInclude”
  4.     xmlns:gazebo=”http://playerstage.sourceforge.net/gazebo/xmlschema/#gz”
  5.     xmlns:model=”http://playerstage.sourceforge.net/gazebo/xmlschema/#model”
  6.     xmlns:sensor=”http://playerstage.sourceforge.net/gazebo/xmlschema/#sensor”
  7.     xmlns:body=”http://playerstage.sourceforge.net/gazebo/xmlschema/#body”
  8.     xmlns:geom=”http://playerstage.sourceforge.net/gazebo/xmlschema/#geom”
  9.     xmlns:joint=”http://playerstage.sourceforge.net/gazebo/xmlschema/#joint”
  10.     xmlns:controller=”http://playerstage.sourceforge.net/gazebo/xmlschema/#controller”
  11.     xmlns:interface=”http://playerstage.sourceforge.net/gazebo/xmlschema/#interface”
  12.     xmlns:rendering=”http://playerstage.sourceforge.net/gazebo/xmlschema/#rendering”
  13.     xmlns:renderable=”http://playerstage.sourceforge.net/gazebo/xmlschema/#renderable”
  14.     xmlns:physics=”http://playerstage.sourceforge.net/gazebo/xmlschema/#physics”
  15.     xmlns:xacro=”http://ros.org/wiki/xacro”>
  16.   <include filename=”$(find smartcar_description)/urdf/smartcar_body.urdf.xacro” />
  17.   <!– Body of SmartCar, with plates, standoffs and Create (including sim sensors) –>
  18.   <smartcar_body/>
  19.   <smartcar_sim/>
  20. </robot></span>

二、lanuch文件

        在launch文件中要启动节点和模拟器。
  1. <launch>
  2.     <param name=”/use_sim_time” value=”false” />
  3.     <!– Load the URDF/Xacro model of our robot –>
  4.     <arg name=”urdf_file” default=”$(find xacro)/xacro.py ‘$(find smartcar_description)/urdf/smartcar.urdf.xacro'” />
  5.     <arg name=”gui” default=”false” />
  6.     <param name=”robot_description” command=”$(arg urdf_file)” />
  7.     <param name=”use_gui” value=”$(arg gui)”/>
  8.     <node name=”arbotix” pkg=”arbotix_python” type=”driver.py” output=”screen”>
  9.         <rosparam file=”$(find smartcar_description)/config/smartcar_arbotix.yaml” command=”load” />
  10.         <param name=”sim” value=”true”/>
  11.     </node>
  12.     <node name=”joint_state_publisher” pkg=”joint_state_publisher” type=”joint_state_publisher” >
  13.     </node>
  14.     <node name=”robot_state_publisher” pkg=”robot_state_publisher” type=”state_publisher”>
  15.         <param name=”publish_frequency” type=”double” value=”20.0″ />
  16.     </node>
  17.      <!– We need a static transforms for the wheels –>
  18.     <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″ />
  19.     <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″ />
  20.     <node name=”rviz” pkg=”rviz” type=”rviz” args=”-d $(find smartcar_description)/urdf.vcg” />
  21. </launch>

三、仿真测试

        首先运行lanuch,既可以看到rviz中的机器人:roslaunch smartcar_description smartcar_display.rviz.launch
   
         发布一条动作的消息。
 rostopic pub -r 10 /cmd_vel geometry_msgs/Twist ‘{linear: {x: 0.5, y: 0, z: 0}, angular: {x: 0, y: 0, z: 0.5}}’

四、节点关系

转载请注明来源:CV视觉网 » ROS探索总结(六)——使用smartcar进行仿真

分享到:更多 ()
扫描二维码,给作者 打赏
pay_weixinpay_weixin

请选择你看完该文章的感受:

0不错 0超赞 0无聊 0扯淡 0不解 0路过

评论 抢沙发

评论前必须登录!