------------恢复内容开始------------

通过自己不断地摸索,对ros系统有了一定的了解,首先装系统,这一过程中也遇到了很多问题,但通过不断地尝试,经过一天一夜的倒腾,总算是把系统给安装好了,接下来配置环境,虽然这个过程比较艰辛,总是出现编译出错或者没有功能包依赖等各种问题。但是通过我们的努力,都一点一点的解决了,我会再接再厉,

1.首先运行个小乌龟例程:

  打开一个终端:roscore                              #运行ros环境

  打开一个终端:rosrun turtlesim turtlesim_node        #运行小乌龟仿真器节点,打开小乌龟运行场景

  打开一个终端:rosrun turtlesim turtle_teleop_key             #运行键盘控制节点,通过方向键控制小乌龟的运动

ros机器人之小乌龟仿真-路径记录-LMLPHP

2.通过话题给小乌龟发送消息让小乌龟定向运动

命令如下

 qqtsj  ~  rostopic pub /turtle1/cmd_vel geometry_msgs/Twist "linear:
x: 3.0
y: 0.0
z: 2.0
angular:
x: 0.0
y: 0.0
z: 0.0"
publishing and latching message. Press ctrl-C to terminate

可以定向的改变小乌龟的角速度和线速度以及小乌龟的转动角度,但是这样只能发送一次消息。

若需以一定的频率不断地发送消息数据,则为如下命令

 qqtsj  ~  rostopic pub -r 10 /turtle1/cmd_vel geometry_msgs/Twist "linear:
x: 2.0
y: 0.0
z: 2.0
angular:
x: 0.0
y: 0.0
z: 3.0"

其中-r为循环,10为发送给消息的频率(单位为hz),然后小乌龟就会根据规定的速度和角度定向的运动,这就用到了ROS系统中的话题通信,以便后面研究机器人打下基础。

查看消息的结构:rosmsg show geometry/Twlist

服务:service

查看服务的列表(服务的内容):rosservice list

 qqtsj  ~  rosservice list
/clear
/kill
/reset
/rosout/get_loggers
/rosout/set_logger_level
/rostopic_26871_1579011097016/get_loggers
/rostopic_26871_1579011097016/set_logger_level
/spawn
/teleop_turtle/get_loggers
/teleop_turtle/set_logger_level
/turtle1/set_pen
/turtle1/teleport_absolute
/turtle1/teleport_relative
/turtlesim/get_loggers
/turtlesim/set_logger_level

建立一个新的海龟:rosservice call /spawn  (Tab键两下)

 qqtsj  ~  rosservice call /spawn "x: 0.0
y: 0.0
theta: 0.0
name: 'turtle2'"
name: "turtle2"

路径记录

首先创建一个bag包,存放小乌龟运行的路径,记录下小乌龟的行进路线。命令为

 qqtsj  ~  rosbag record -a -O cmd_record
[ INFO] [1579021261.961366553]: Recording to cmd_record.bag.
[ INFO] [1579021261.962496904]: Subscribing to /turtle1/color_sensor
[ INFO] [1579021261.964809471]: Subscribing to /turtle2/color_sensor
[ INFO] [1579021261.966782329]: Subscribing to /rosout
[ INFO] [1579021261.968599482]: Subscribing to /turtle2/pose
[ INFO] [1579021261.970367259]: Subscribing to /rosout_agg
[ INFO] [1579021261.972389384]: Subscribing to /turtle1/cmd_vel
[ INFO] [1579021261.975169187]: Subscribing to /turtle1/pose

路径重现

在bag包中已经记录了小乌龟的路径,然后通过调用bag包去实现小乌龟路径的重现,小乌龟会按照记录的路径重新运动,如下

 qqtsj  ~  rosbag play cmd_record.bag
[ INFO] [1579021485.400287473]: Opening cmd_record.bag Waiting 0.2 seconds after advertising topics... done. Hit space to toggle paused, or 's' to step.
[RUNNING] Bag Time: 1579021261.977381 Duration: 0.000000 / [RUNNING] Bag Time: 1579021261.978402 Duration: 0.001021 / [RUNNING] Bag Time: 1579021262.078691 Duration: 0.101311 / [RUNNING] Bag Time: 1579021262.177369 Duration: 0.199988 / [RUNNING] Bag Time: 1579021262.185319 Duration: 0.207938 / [RUNNING] Bag Time: 1579021262.201285 Duration: 0.223904 / [RUNNING] Bag Time: 1579021262.217652 Duration: 0.240271 / [RUNNING] Bag Time: 1579021262.233162 Duration: 0.255782 / [RUNNING] Bag Time: 1579021262.249374 Duration: 0.271993 / [RUNNING] Bag Time: 1579021262.266055 Duration: 0.288674 / [RUNNING] Bag Time: 1579021262.281470 Duration: 0.304090 /

通过对小乌龟的控制,定向移动,路径记录,路径重现。对接下来ros机器人的研究有一定的帮助,会加深我们对机器人的理解。

05-04 01:14