博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[未修订]ROS学习笔记
阅读量:2134 次
发布时间:2019-04-30

本文共 6606 字,大约阅读时间需要 22 分钟。

本文章内容是我在阅读ROS初级教程(beginner level)时的随笔,内容不是连续的,用于给我自己学习进行提示之用。主要内容来源于ROS的Wiki。

Creating a ROS Package

3. Creating a catkin Package

cd ~/catkin_ws/src

catkin_create_pkg beginner_tutorials std_msgs rospy roscpp

4. Building a catkin workspace and sourcing the setup file

cd ~/catkin_ws

catkin_make

 . ~/catkin_ws/devel/setup.bash

5. package dependencies

rospack depends1 beginner_tutorials

dependencies也列在package.xml文件中。

rospack depends beginner_tutorials 将列出所有依赖,将递归的寻找间接依赖。

Building a ROS Package

2. Building Packages

确保source 相应的setup.bash。

catkin_make

build目录即为build space

devel目录即为devel space

Understanding ROS Nodes

2. Quick Overview of Graph Concepts

Nodes: A node is an executable that uses ROS to communicate with other nodes.

Messages: ROS data type used when subscribing or publishing to a topic.
Topics: Nodes can publish messages to a topic as well as subscribe to a topic to receive messages.
Master:
Name service for ROS (i.e. helps nodes find each other)
rosout: ROS equivalent of stdout/stderr
roscore: Master + rosout + parameter server

3. Nodes

 Nodes can publish or subscribe to a Topic. Nodes can also provide or use a Service.

4. Client Libraries

ROS client libraries allow nodes written in different programming languages to communicate:

rospy = python client library
roscpp = c++ client library

5. roscore

执行

roscore

6. Using rosnode

rosnode list列出正在运行的node。

rosnode infor node_name列出node_name所代表的node的信息。

7. Using rosrun

运行rosnode时可带有Remapping Argument。

rosrun turtlesim turtlesim_node __name:=my_turtle

可能有用的命令,rosnode cleanup。

rosnode ping 正在运行的node的name(remap后的名称)

Understanding ROS Topics

2. Ros topics

Using rqt_graph

rosnode rqt_graph rqt_graph

运行rostopic -h以查看所支持的命令。

rostopic echo 显示某一个topic(正在传输)的数据。

rostopic list 显示topics。对于像list一类的命令,还有自命令可使用,利用rostopic list -h来查看。

3. ROS Messages

每个topic都有一个type,type由topic的publisher发送来的message决定。

查看一个topic的type用

rostopic type topic_name

所得结果为这个topic的message

利用

rosmsg show msg_name

来查看该message的具体定义。(都可以用tab补全)

术语: advertised topic

利用rostopic pub 命令来像一个topic 以某种特定的message type发送数据,例如

$ rostopic pub -1 /turtle1/cmd_vel geometry_msgs/Twist -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, 1.8]'

其中 -1 表示只发送一次,--表示其后方为message的参数。参数使用了YAML command line的形式。

重复发送使用-r参数。

利用rostopic hz 命令来显示某个topic的publish的频率。

有用的node: rqt_plot

Understanding ROS Services and Parameters

1. ROS Services

Services are another way that nodes can communicate with each other. Services allow nodes to send a request and receive a response.

2. Using rosservice

rosservice list  列出所有service

rosservice type 列出service的type

rosservice call 对一个service提出request

有用的命令 rossrv show,可用管道接在rosservice type后面

3. Using rosparam

parameter使用YAML格式。

rosparam list 列出目前有的parameter

rosparam set 设定某个parameter的值(可能需要call某些service使parameter的设定生效)

rosparam get 查看某个parameter的值,rosparam get / 查看所有parameter的值

rosparam dump 将parameter输出到文件上。

rosparam load 从文件张读回parameters。可以读回并存放在其他“名称空间”中。

Using rqt_console and roslaunch

2. Using rqt_console and rqt_logger_level

Using roslaunch

写一个xml文件作为launch的输入。内有<group><node>和<launch>等xml element。

Using rosed to edit files in ROS

1. Using rosed

rosed [pkg name] [file name] 来修改一个pkg内的文件。

设定~/.bashrc内export EDITOR的值,以确定默认使用的编辑器。

Creating a ROS msg and srv

1. Introduction to msg and srv

    msg: msg files are simple text files that describe the fields of a ROS message. They are used to generate source code for messages in different languages.

    srv: an srv file describes a service. It is composed of two parts: a request and a response.
msg files are stored in the msg directory of a package, and srv files are stored in the srv directory.
msgs are just simple text files with a field type and field name per line. The field types you can use are:
    int8, int16, int32, int64 (plus uint*)
    float32, float64
    string
    time, duration
    other msg files
    variable-length array[] and fixed-length array[C]
There is also a special type in ROS: Header, the header contains a timestamp and coordinate frame information that are commonly used in ROS. You will frequently see the first line in a msg file have Header header.

srv files are just like msg files, except they contain two parts: a request and a response. The two parts are separated by a '---' line.

2. Using msg

在pkg的文件夹下创建msg文件夹,在其中创建msg的描述文件。创建后即可用rosmsg show来显示这个新的msg的定义。

在pkg的package.xml文件中增加对message_generation的编译依赖,和对message_runtime的运行依赖。

修改pkg的CMakeLists.txt,调整find_package,catkin_package,add_message_files和generate_message的配置。

3. Using srv

在pkg的文件夹下创建srv文件夹,在其中创建srv的描述文件。创建后即可用rossrv show来显示这个新的srv的定义。

在pkg的package.xml文件中增加对message_generation的编译依赖,和对message_runtime的运行依赖。

修改pkg的CMakeLists.txt,调整find_package,catkin_package,add_message_files和generate_message的配置。

有用的网址:

Writing a Simple Publisher and Subscriber (C++)

#include "ros/ros.h"#include "std_msgs/String.h"ros::init(argc, argv, name_of_node);ros::NodeHandle n;ros::Publisher chatter_pub = n.advertise
("chatter", 1000);ros::Rate loop_rate(10);while (ros::ok())chatter_pub.publish(msg);ros::spinOnce();loop_rate.sleep();ros::Subscriber sub = n.subscribe("chatter", 1000, chatterCallback);

修改CMakeLists.txt文件。

有用的网址:

Writing a Simple Publisher and Subscriber (Python)

The python version of the above code is more simpler.

The difference is that there is no "handler" but a rospy object that is imported throuh

import rospy

And in the talker code, there is no direct invocation of spin() function.

Remember to chmod the python scripts.

Examining the Simple Publisher and Subscriber

启动新的terminal时记得source相应的setup.bash。

Writing a Simple Service and Client (C++)

首先必须已经根据srv和msg的描述,生成了相应的C++头文件。在源文件中include这些生成的头文件。

service启动后一直处于运行状态。client启动后请求server进行服务,一旦server响应了请求,client既退出。

Writing a Simple Service and Client (Python)

Python形式的server和client也使用ros自动生的python代码,这些自动生成的python代码位于workspace的devel/lib/python2.7/dist-packages内。自动生成的代码主要用于定义service的“类型”。

对于client的代码,并不再要求进行init_node(),而是使用rospy.wait_for_service()。通过rospy.ServiceProxy()获得service的一个句柄(也就是一个函数接口)来向server进行请求。在client的代码中应该是用try,except进行异常的捕捉。

注意修改python脚本的可执行权限。

Recording and playing back data

rosbag record -a 记录所有topic的信息。记录将持续进行,直到退出。记录将保存在一个bagfile中。 -O 指定输出文件,并以topic名称作为后续参数,来记录部分topic的信息。

rosbag info [record_file_name] 显示一个bagfile的基本信息。

rosbag play [record_file_name] 回放一个bagfile,此时可以代替原来用于输入的node,向指定的topic输入信息。回放时可以选择启示的等待时间(-d),可以指定开始回放的起始时间(-s),可以选择回放的速度(-r)。

Getting started with roswtf

其实我很好奇,roswtf中的wtf是不是What the f*ck 的意思。。。

使用roswtf以查看系统的运行状况,用于调试系统是否有问题或者故障。

Where next?

初级教程在最后给出了几个比较重要的内容

(1)机器人simulator。可以在使用真实硬件之前在simulator上进行测试。

(2)仿真环境,例如RViz。

(3)TF。是用于对坐标变换进行建模的工具。

(4)actionlib,用于对可抢占任务设计的库。

(5)navigation,一个2D的建地图,路径规划的库。

(6)MoveIt,一个对机械臂进行建模的库。

转载地址:http://ssugf.baihongyu.com/

你可能感兴趣的文章
TP 分页后,调用指定页。
查看>>
Oracle数据库中的(+)连接
查看>>
java-oracle中几十个实用的PL/SQL
查看>>
PLSQL常用方法汇总
查看>>
几个基本的 Sql Plus 命令 和 例子
查看>>
PLSQL单行函数和组函数详解
查看>>
Oracle PL/SQL语言初级教程之异常处理
查看>>
Oracle PL/SQL语言初级教程之游标
查看>>
Oracle PL/SQL语言初级教程之操作和控制语言
查看>>
Oracle PL/SQL语言初级教程之过程和函数
查看>>
Oracle PL/SQL语言初级教程之表和视图
查看>>
Oracle PL/SQL语言初级教程之完整性约束
查看>>
PL/SQL学习笔记
查看>>
如何分析SQL语句
查看>>
结构化查询语言(SQL)原理
查看>>
SQL教程之嵌套SELECT语句
查看>>
几个简单的SQL例子
查看>>
日本語の記号の読み方
查看>>
计算机英语编程中一些单词
查看>>
JavaScript 经典例子
查看>>