ROS

ROS机器人仿真(三)- 安装ROS-BY-EXAMPLE源码

2017-03-23  本文已影响185人  Savior2016

1 准备

1.1 下载依赖包

下载一下包以后用,直接在命令窗口粘贴运行就可以了:

sudo apt-get install ros-indigo-turtlebot-bringup \
ros-indigo-turtlebot-create-desktop ros-indigo-openni-* \
ros-indigo-openni2-* ros-indigo-freenect-* ros-indigo-usb-cam \
ros-indigo-laser-* ros-indigo-hokuyo-node \
ros-indigo-audio-common gstreamer0.10-pocketsphinx \
ros-indigo-pocketsphinx ros-indigo-slam-gmapping \
ros-indigo-joystick-drivers python-rosinstall \
ros-indigo-orocos-kdl ros-indigo-python-orocos-kdl \
python-setuptools ros-indigo-dynamixel-motor-* \
libopencv-dev python-opencv ros-indigo-vision-opencv \
ros-indigo-depthimage-to-laserscan ros-indigo-arbotix-* \
ros-indigo-turtlebot-teleop ros-indigo-move-base \
ros-indigo-map-server ros-indigo-fake-localization \
ros-indigo-amcl git subversion mercurial

1.2 下载rbx1

执行以下命令:

$ 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 

如果这个package的代码后来更新了,需要执行以下代码:

$ cd ~/catkin_ws/src/rbx1 
$ git pull 
$ cd ~/catkin_ws 
$ catkin_make 
$ source ~/catkin_ws/devel/setup.bash 

2 安装Arbotix仿真器

2.1 安装仿真器

运行代码:
$ sudo apt-get install ros-indigo-arbotix-*
然后运行:
rospack profile

2.2 测试仿真器

首先启动turtleBot:

roslaunch rbx1_bringup fake_turtlebot.launch

或者也可以启动Pi Robot:

$ roslaunch rbx1_bringup fake_pi_robot.launch 

然后启动rviz:

$ 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}}' 

想要停止运动,可以Ctrl+C,再输入以下指令:

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

2.3 仿真运行自己的机器人

如果我们有一个自己的URDF机器人模型,或者是下载了别的模型,想要仿真运行。
首先复制一份之前的机器人启动的launch文件。

$ roscd rbx1_bringup/launch 
$ cp fake_turtlebot.launch fake_my_robot.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 rbx1_description)/urdf/turtlebot.urdf.xacro'" />
   
  <param name="robot_description" command="$(arg urdf_file)" />
    
  <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">
      <param name="publish_frequency" type="double" value="20.0" />
  </node>
  
</launch>

我们只要简单的替换掉package和指向我们自己的URDF/Xacro 文件的路径就可以了,其他的都可以保持不变。像下面这样:

<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 YOUR_PACKAGE_NAME)/YOUR_URDF_PATH' " />
   
  <param name="robot_description" command="$(arg urdf_file)" />
    
  <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">
      <param name="publish_frequency" type="double" value="20.0" />
  </node>
  
</launch>

如果你的机器人有机械臂或者头,可以使用fake_pi_robot.launch文件作为模板修改。

上一篇 下一篇

猜你喜欢

热点阅读