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

转自:https://www.ncnynl.com/archives/201609/843.html

总结:

一、机器人描述文件三个:

  机器人主体body文件:

  gazebo属性文件:

  主文件 smartcar.urdf:

二、启动文件smartcar_display.rviz.launch:启动节点和模拟器。

三、新增smartcar_description/config/smartcar_arbotix.yaml文件:

四、urdf.rviz文件:

cp /opt/ros/indigo/share/urdf_tutorial/rviz/urdf.rviz

 

 

 

1.indigo版本机器人主体文件:smartcar_description/urdf/smartcar_body.urdf.xacro

  • 修改property,为xacro:property
  • 修改include, 为xacro:include
"1.0"?>  
"smartcar" xmlns:xacro="http://ros.org/wiki/xacro">  
  "M_PI" value="3.14159"/>    
    
  "$(find smartcar_description)/urdf/gazebo.urdf.xacro"/>  
  "base_x" value="0.33" />  
  "base_y" value="0.33" />  
  "smartcar_body">  
    "base_link">  
      
      "0 0 0.055"/>  
      "1.0" />  
      "1.0" ixy="0.0" ixz="0.0" iyy="1.0" iyz="0.0" izz="1.0"/>  
      
      
        
        "0.25 .16 .05"/>  
        
      "0 0 0" xyz="0 0 0.055"/> 
      "blue">  
      "0 0 .8 1"/>  
        
     
     
      "0 0 0" xyz="0 0 0.055"/>  
        
        "0.25 .16 .05" />  
        
      
    

 "left_front_wheel">  
      
      "0.08 0.08 0.025"/>  
      "0.1" />  
       "1.0" ixy="0.0" ixz="0.0" iyy="1.0" iyz="0.0" izz="1.0"/>  
      

      
        
        ".02" radius="0.025"/>  
        
      "black">  
        "0 0 0 1"/>  
        
      
      
      "0 1.57075 1.57075" xyz="0.08 0.08 0.025"/>  
        
         ".02" radius="0.025"/>  
        
      
    

  "left_front_wheel_joint" type="continuous">  
    "0 0 1"/>  
    "base_link"/>  
    "left_front_wheel"/>  
    "0 1.57075 1.57075" xyz="0.08 0.08 0.025"/>  
    "100" velocity="100"/>  
    "0.0" friction="0.0"/>  
    

  "right_front_wheel">  

      

      "0.08 -0.08 0.025"/>  

      "0.1" />  

       "1.0" ixy="0.0" ixz="0.0" iyy="1.0" iyz="0.0" izz="1.0"/>  

      

      

        

        ".02" radius="0.025"/>  

        

      "black">  

        "0 0 0 1"/>  

        

      

      

      "0 1.57075 1.57075" xyz="0.08 -0.08 0.025"/>  

        

         ".02" radius="0.025"/>  

        

      

    

 

  "right_front_wheel_joint" type="continuous">  

    "0 0 1"/>  

    "base_link"/>  

    "right_front_wheel"/>  

    "0 1.57075 1.57075" xyz="0.08 -0.08 0.025"/>  

    "100" velocity="100"/>  

    "0.0" friction="0.0"/>  

   

 

 "left_back_wheel">  

      

      "-0.08 0.08 0.025"/>  

      "0.1" />  

       "1.0" ixy="0.0" ixz="0.0" iyy="1.0" iyz="0.0" izz="1.0"/>  

      

      

        

        ".02" radius="0.025"/>  

        

      "black">  

        "0 0 0 1"/>  

        

     

     

       "0 1.57075 1.57075" xyz="-0.08 0.08 0.025"/>  

        

         ".02" radius="0.025"/>  

        

      

    

 

  "left_back_wheel_joint" type="continuous">  

    "0 0 1"/>  

    "base_link"/>  

    "left_back_wheel"/>  

    "0 1.57075 1.57075" xyz="-0.08 0.08 0.025"/>  

    "100" velocity="100"/>  

    "0.0" friction="0.0"/>  

    

 

  "right_back_wheel">  

      

       "-0.08 -0.08 0.025"/>  

       "0.1" />  

       "1.0" ixy="0.0" ixz="0.0" iyy="1.0" iyz="0.0" izz="1.0"/>  

      

      

        

        ".02" radius="0.025"/>  

        

      "black">  

        "0 0 0 1"/>  

        

     

     

      "0 1.57075 1.57075" xyz="-0.08 -0.08 0.025"/>  

        

         ".02" radius="0.025"/>  

        

      

    

 

 

  "right_back_wheel_joint" type="continuous">  

    "0 0 1"/>  

    "base_link"/>  

    "right_back_wheel"/>  

    "0 1.57075 1.57075" xyz="-0.08 -0.08 0.025"/>  

    "100" velocity="100"/>  

    "0.0" friction="0.0"/>  

    

 

  "head">  

      

      "0.08 0 0.08"/>  

      "0.1" />  

      "1.0" ixy="0.0" ixz="0.0" iyy="1.0" iyz="0.0" izz="1.0"/>  

      

      

        

        ".02 .03 .03"/>  

        

      "white">  

        "1 1 1 1"/>  

        

       

       

      "0.08 0 0.08"/>  

        

         ".02" radius="0.025"/>  

        

      

    

 

  "tobox" type="fixed">  

    "base_link"/>  

    "head"/>  

    "0.08 0 0.08"/>  

    

    

 

2.gazebo属性部分 smartcar_description/urdf/gazebo.urdf.xacro

"1.0"?>  
"http://playerstage.sourceforge.net/gazebo/xmlschema/#controller"   

    xmlns:interface="http://playerstage.sourceforge.net/gazebo/xmlschema/#interface"   

    xmlns:sensor="http://playerstage.sourceforge.net/gazebo/xmlschema/#sensor"   

    xmlns:xacro="http://ros.org/wiki/xacro"   

    name="smartcar_gazebo">  

 

  

  

"smartcar_sim">  

    "base_link">  

        Gazebo/Blue  

      

 

    "right_front_wheel">  

        Gazebo/FlatBlack  

      

 

    "right_back_wheel">  

        Gazebo/FlatBlack  

      

 

    "left_front_wheel">  

        Gazebo/FlatBlack  

      

 

    "left_back_wheel">  

        Gazebo/FlatBlack  

      

 

    "head">  

        Gazebo/White  

      

 

  

 

3.主文件:smartcar_description/urdf/smartcar.urdf.xacro

"1.0"?>  
"smartcar"    

    xmlns:xi="http://www.w3.org/2001/XInclude"  

    xmlns:gazebo="http://playerstage.sourceforge.net/gazebo/xmlschema/#gz"  

    xmlns:model="http://playerstage.sourceforge.net/gazebo/xmlschema/#model"  

    xmlns:sensor="http://playerstage.sourceforge.net/gazebo/xmlschema/#sensor"  

    xmlns:body="http://playerstage.sourceforge.net/gazebo/xmlschema/#body"  

    xmlns:geom="http://playerstage.sourceforge.net/gazebo/xmlschema/#geom"  

    xmlns:joint="http://playerstage.sourceforge.net/gazebo/xmlschema/#joint"  

    xmlns:controller="http://playerstage.sourceforge.net/gazebo/xmlschema/#controller"  

    xmlns:interface="http://playerstage.sourceforge.net/gazebo/xmlschema/#interface"  

    xmlns:rendering="http://playerstage.sourceforge.net/gazebo/xmlschema/#rendering"  

    xmlns:renderable="http://playerstage.sourceforge.net/gazebo/xmlschema/#renderable"  

    xmlns:physics="http://playerstage.sourceforge.net/gazebo/xmlschema/#physics"  

    xmlns:xacro="http://ros.org/wiki/xacro">  

 

  "$(find smartcar_description)/urdf/smartcar_body.urdf.xacro" />  

 

    

    

 

    

 

二、lanuch文件,smartcar_description/launch/smartcar_display.rviz.launch

 

  

    "/use_sim_time" value="false" />  

 

      

    "urdf_file" default="$(find xacro)/xacro.py '$(find smartcar_description)/urdf/smartcar.urdf.xacro'" />  

    "gui" default="false" />  
    "robot_description" command="$(arg urdf_file)" />  
    "use_gui" value="$(arg gui)"/>  
    "arbotix" pkg="arbotix_python" type="arbotix_driver" output="screen">  
        "$(find smartcar_description)/config/smartcar_arbotix.yaml" command="load" /> 
        "sim" value="true"/>  
      

    "joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" >  

      

    "robot_state_publisher" pkg="robot_state_publisher" type="state_publisher">  

        "publish_frequency" type="double" value="20.0" />  

      

 

       

    "tf" type="static_transform_publisher" name="odom_left_wheel_broadcaster" args="0 0 0 0 0 0 /base_link /left_front_link 100" />  

    "tf" type="static_transform_publisher" name="odom_right_wheel_broadcaster" args="0 0 0 0 0 0 /base_link /right_front_link 100" />  

 

    "rviz" pkg="rviz" type="rviz" args="-d $(find smartcar_description)/urdf.rviz" />  

 

4.在indigo版本里,新增smartcar_description/config/smartcar_arbotix.yaml文件,内容为:

port: /dev/ttyUSB0
baud: 115200
rate: 20
sync_write: True
sync_read: True
read_rate: 20
write_rate: 20

controllers: {
   #  Pololu motors: 1856 cpr = 0.3888105m travel = 4773 ticks per meter (empirical: 4100)
   base_controller: {type: diff_controller, base_frame_id: base_link, base_width: 0.26, ticks_meter: 4100, Kp: 12, Kd: 12, Ki: 0, Ko: 50, accel_limit: 1.0 }
}

 

5.urdf.rviz文件:(或者自己按照目录找到了copy过来,如果没有就先安装这个包:urdf_tutorial

$ cp /opt/ros/indigo/share/urdf_tutorial/rviz/urdf.rviz

 

三、仿真测试

首先运行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}}'

 

 运行结果:

ROS探索总结(六)——使用smartcar进行仿真_第1张图片

 

 如果小车跑不起来,把Global中的fixed frame改成odom,就好了

转载于:https://www.cnblogs.com/yrm1160029237/p/10027615.html

你可能感兴趣的:(javascript,python)