ROS 小烏龜測試

教程

1.維基 http://wiki.ros.org/cn/ROS/Tutorials
2. 創客智造 http://www.ncnynl.com/category/ros-junior-tutorial/

1安裝環境配置(桌面進入命令行)

echo "source /opt/ros/indigo/setup.bash" >> ~/.bashrc
source ~/.bashrc

2.1創建工作環境並編譯 (生成的在home文件夾下)

mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/
catkin_make

2.2自己創建的包環境 能看到’build’和’devel’這兩個文件夾。
將當前工作環境設置在ROS工作環境

source /home/dongdong/catkin_ws/devel/setup.bash

如果永久性配置

echo "source /home/dongdong/catkin_ws/devel/setup.bash" >> ~/.bashrc
source ~/.bashrc

查看是否配置成功

echo $ROS_PACKAGE_PATH

5 運行小烏龜測試

//打開新窗口
roscore
//另開新窗口
rosrun turtlesim turtlesim_node __name:=my_turtle //改變名字 my_turtle
//發送一條消息給turtlesim,告訴它以2.0大小的線速度和1.8大小的角速度開始移動。
rostopic pub -1 /turtle1/cmd_vel geometry_msgs/Twist -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, 1.8]'
//rostopic pub -r 1命令    一個穩定的頻率爲1Hz的命令
rostopic pub /turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, 1.8]'
//通過鍵盤控制

—————–參數解釋————————————-
-1 發表後就退出
/turtle1/command_velocity 話題名稱
turtlesim/Velocity 話題類型
– (雙破折號)這會告訴命令選項解析器接下來的參數部分都不是命令選項。
2.0 1.8 兩個浮點型元素:linear和angular。
這些參數其實是按照YAML語法格式編寫的,這在YAML文檔中有更多的描述。
——————-參數解釋結束———————————————–


6 roslaunch 同時運行多個小烏龜節點

$ roscd beginner_tutorials
$ mkdir launch
$ cd launch
$ gedit turtlemimic.launch
$ roslaunch beginner_tutorials turtlemimic.launch
$ rostopic pub /turtlesim1/turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, -1.8]'

turtlemimic.launch 文件裏面寫入

<launch>

     <group ns="turtlesim1">
       <node pkg="turtlesim" name="sim" type="turtlesim_node"/>
     </group>

     <group ns="turtlesim2">
        <node pkg="turtlesim" name="sim" type="turtlesim_node"/>
      </group>

     <node pkg="turtlesim" name="mimic" type="mimic">
       <remap from="input" to="turtlesim1/turtle1"/>
       <remap from="output" to="turtlesim2/turtle1"/>
     </node>

   </launch>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章