ROS(四):简单的机器人仿真

之前跟着古月居的博客一步一步学ROS,发现可能大神写的博客很早了,然后代码有些版本存在问题.所以LZ要自己在记录下.

环境为Ubuntu14.04+ros indigo.参开书籍:ROS by Example

LZ假设小伙伴已经安装成功ROS indigo的版本.

1.检查环境并安装依赖

cd ~ 
wget https://raw.githubusercontent.com/pirobot/rbx1/indigo-devel/rbx1-prereq.sh
sh rbx1-prereq.sh

2.安装书中例子

cd ~/catkin_ws/src/
git clone https://github.com/pirobot/rbx1.git
cd rbx1
git checkout indigo-devel
cd ~/catkin_ws
catkin_make
source ~/catkin_ws/devel/setup.bash
rospack profile

3.安装机器人模拟器
rviz是一个显示机器人实体的工具,本身不具有模拟的功能,需要安装一个模拟器arbotix。

sudo apt-get install ros-indigo-arbotix-*
rospack profile

4.TurtleBot机器人的模拟
在书中的rbx_vol_1包里已经为我们写好了模拟的代码,我们先进行实验,完成后再仔细研究代码。

机器人模拟运行:

roscore
//如果找不到package,可以source devel/setup.bach
roslaunch rbx1_bringup fake_pi_robot.launch
rosrun rviz rviz -d `rospack find rbx1_nav`/sim.rviz
//发布一个信息
rostopic pub -r 10 /cmd_vel geometry_msgs/Twist '{linear: {x: 0.2, y: 0, z: 0}, angular: {x: 0, y: 0, z: 0.5}}'

最后效果如下图所示:

ROS(四):简单的机器人仿真_第1张图片

如果要让机器人停下来,需要在中端中按下“Ctrl+c”,然后输入:

rostopic pub -1 /cmd_vel geometry_msgs/Twist '{}'

在/home/felaim/catkin_ws/src/rbx1/rbx1_bringup/launch中打开fake_turtlebot.launch

<launch>
  <param name="/use_sim_time" value="false" />
//从制定的包中加载urdf文件
  
  <arg name="urdf_file" default="$(find xacro)/xacro.py '$(find rbx1_description)/urdf/turtlebot.urdf.xacro'" />

  <param name="robot_description" command="$(arg urdf_file)" />
//启动arbotix模拟器    
  <node name="arbotix" pkg="arbotix_python" type="arbotix_driver" output="screen" clear_params="true">
      <rosparam file="$(find rbx1_bringup)/config/fake_turtlebot_arbotix.yaml" command="load" />
      <param name="sim" value="true"/>
  node>
  //启动状态,发布节点
  <node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher">
  //tf坐标系配置
      <param name="publish_frequency" type="double" value="20.0" />
  node>

launch>

在/home/felaim/catkin_ws/src/rbx1/rbx1_nav中打开nav_test.rviz可以看到:很多的参数设置!!!

Panels:
  - Class: rviz/Displays
    Help Height: 78
    Name: Displays
    Property Tree Widget:
      Expanded:
        - /Global Options1
        - /Status1
        - /Odometry1
      Splitter Ratio: 0.652661
    Tree Height: 483
  - Class: rviz/Selection
    Name: Selection
  - Class: rviz/Tool Properties
    Expanded:
      - /2D Pose Estimate1
      - /2D Nav Goal1
    Name: Tool Properties
    Splitter Ratio: 0.588679
  - Class: rviz/Views
    Expanded:
      - /Current View1
    Name: Views
    Splitter Ratio: 0.5
  - Class: rviz/Time
    Experimental: false
    Name: Time
    SyncMode: 0
    SyncSource: ""
Visualization Manager:
  Class: ""
  Displays:
    - Alpha: 0.5
      Cell Size: 0.5
      Class: rviz/Grid
      Color: 160; 160; 164
      Enabled: true
      Line Style:
        Line Width: 0.03
        Value: Lines
      Name: Grid
      Normal Cell Count: 0
      Offset:
        X: 0
        Y: 0
        Z: 0
      Plane: XY
      Plane Cell Count: 20
      Reference Frame: odom
      Value: true
    - Angle Tolerance: 0.05
      Class: rviz/Odometry
      Color: 221; 200; 14
      Enabled: true
      Keep: 100
      Length: 0.6
      Name: Odometry
      Position Tolerance: 0.1
      Topic: /odom
      Value: true
    - Angle Tolerance: 0.1
      Class: rviz/Odometry
      Color: 253; 124; 0
      Enabled: false
      Keep: 100
      Length: 0.6
      Name: Odometry EKF
      Position Tolerance: 0.1
      Topic: /odom
      Value: false
    - Alpha: 1
      Class: rviz/RobotModel
      Collision Enabled: false
      Enabled: true
      Links:
        All Links Enabled: true
        Expand Joint Details: false
        Expand Link Details: false
        Expand Tree: false
        Link Tree Style: Links in Alphabetic Order
        base_footprint:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        base_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        camera_depth_frame:
          Alpha: 1
          Show Axes: false
          Show Trail: false
        camera_depth_optical_frame:
          Alpha: 1
          Show Axes: false
          Show Trail: false
        camera_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        camera_rgb_frame:
          Alpha: 1
          Show Axes: false
          Show Trail: false
        camera_rgb_optical_frame:
          Alpha: 1
          Show Axes: false
          Show Trail: false
        front_wheel_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        gyro_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
        laser:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        left_cliff_sensor_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
        left_wheel_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        leftfront_cliff_sensor_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
        plate_0_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        plate_1_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        plate_2_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        plate_3_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        rear_wheel_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        right_cliff_sensor_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
        right_wheel_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        rightfront_cliff_sensor_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
        spacer_0_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        spacer_1_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        spacer_2_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        spacer_3_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        standoff_2in_0_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        standoff_2in_1_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        standoff_2in_2_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        standoff_2in_3_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        standoff_2in_4_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        standoff_2in_5_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        standoff_2in_6_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        standoff_2in_7_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        standoff_8in_0_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        standoff_8in_1_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        standoff_8in_2_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        standoff_8in_3_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        standoff_kinect_0_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        standoff_kinect_1_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
          Value: true
        wall_sensor_link:
          Alpha: 1
          Show Axes: false
          Show Trail: false
      Name: RobotModel
      Robot Description: robot_description
      TF Prefix: ""
      Update Interval: 0
      Value: true
      Visual Enabled: true
  Enabled: true
  Global Options:
    Background Color: 31; 31; 31
    Fixed Frame: odom
    Frame Rate: 30
  Name: root
  Tools:
    - Class: rviz/MoveCamera
    - Class: rviz/Interact
      Hide Inactive Objects: true
    - Class: rviz/Select
    - Class: rviz/SetInitialPose
      Topic: /initialpose
    - Class: rviz/SetGoal
      Topic: /move_base_simple/goal
  Value: true
  Views:
    Current:
      Angle: -1.57
      Class: rviz/TopDownOrtho
      Enable Stereo Rendering:
        Stereo Eye Separation: 0.06
        Stereo Focal Distance: 1
        Swap Stereo Eyes: false
        Value: false
      Name: Current View
      Near Clip Distance: 0.01
      Scale: 223.579
      Target Frame: 
      Value: TopDownOrtho (rviz)
      X: 0.552935
      Y: 0.0507111
    Saved: ~
Window Geometry:
  Displays:
    collapsed: false
  Height: 696
  Hide Left Dock: false
  Hide Right Dock: false
  QMainWindow State: 000000ff00000000fd00000004000000000000012d00000272fc0200000005fb0000001200530065006c0065006300740069006f006e00000001e10000009b0000006400fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000185000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c006100790073010000002800000272000000dd00ffffff000000010000010f00000270fc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a00560069006500770073000000002800000270000000b000fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b200000000000000000000000200000490000000a9fc0100000001fb0000000a00560069006500770073030000004e00000080000002e10000019700000003000004a00000003efc0100000002fb0000000800540069006d00650000000000000004a0000002f600fffffffb0000000800540069006d00650100000000000004500000000000000000000002990000027200000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000
  Selection:
    collapsed: false
  Time:
    collapsed: false
  Tool Properties:
    collapsed: false
  Views:
    collapsed: false
  Width: 972
  X: 286
  Y: 141

查看了一下msg:

ROS(四):简单的机器人仿真_第2张图片

可以看下Topics graph:

ROS(四):简单的机器人仿真_第3张图片

蜗牛背着重重的壳,一步一步往上爬^_^RVIZ有很多还蛮炫的demo,如果小伙伴感兴趣的话,可以运行看看.

参考博客:https://www.ncnynl.com/archives/201609/841.html

你可能感兴趣的:(ROS)