本文主要部分全部来源于ROS官网的Tutorials.

Setup

roscore # making sure that we have roscore running
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key # Now you can use the arrow keys of the keyboard to drive the turtle around.

ROS Topics

sudo apt-get install ros-kinetic-rqt
sudo apt-get install ros-kinetic-rqt-common-plugins
rosrun rqt_graph rqt_graph
rostopic -h
rostopic echo /turtle1/cmd_vel # you will now see topic datas when you press the arrow key in turtle_teleop_key terminal

rostopic list -h # figure out what argument the list sub-command needs
rostopic list -v # displays a verbose list of topics to publish to and subscribe to and their type
rostopic type /turtle1/cmd_vel  # You should get the message type of the topic: geometry_msgs/Twist
rosmsg show geometry_msgs/Twist # look at the details of the message using rosmsg

Using rostopic pub

# publishes data on to a topic, rostopic pub [topic] [msg_type] [args]
rostopic pub -1 /turtle1/cmd_vel geometry_msgs/Twist -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, 1.8]'
# publishes the velocity commands at a rate of 1 Hz on the velocity topic
rostopic pub /turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, -1.8]'
# Now We can also look at what is happening in rqt_graph.
# and see the data published by our turtlesim
rostopic echo /turtle1/pose

# see how fast the turtlesim_node is publishing /turtle1/pose, $ rostopic hz [topic]
rostopic hz /turtle1/pose

# get in depth information about a topic
rostopic type /turtle1/cmd_vel | rosmsg show

Using rqt_plot

rosrun rqt_plot rqt_plot
# a text box in the upper left corner gives you the ability to add any topic to the plot.
# Typing /turtle1/pose/x and add it.
# Typing /turtle1/pose/y and add it.

ROS Services and Parameters

rosservice list # shows us that the turtlesim node provides nine services
rosservice type /clear # find out what type the clear service is
rosservice call /clear # clears the background of the turtlesim_node # look at the case where the service has arguments by looking at the information for the service spawn
rosservice type /spawn | rossrv show
rosservice call /spawn 2 2 0.2 "" # spawn a new turtle at a given location and orientation rosparam list # look at what parameters are currently on the param server
rosparam set /background_r 150 # change the red channel of the background color
rosservice call /clear # call the clear service for the parameter change to take effect
rosparam get /background_g # get the value of the green background channel
rosparam get / # show us the contents of the entire Parameter Serve rosparam dump params.yaml # write all the parameters to the file ./params.yaml (current directory)
rosparam load params.yaml copy # load these yaml files into new namespaces
rosparam get /copy/background_b

Using rqt_console and roslaunch

This tutorial introduces ROS using rqt_console and rqt_logger_level for debugging and roslaunch for starting many nodes at once.

sudo apt-get install ros-kinetic-rqt ros-kinetic-rqt-common-plugins ros-kinetic-turtlesim

# in two new terminals start rqt_console and rqt_logger_level
rosrun rqt_console rqt_console
rosrun rqt_logger_level rqt_logger_level rosrun turtlesim turtlesim_node # Since the default logger level is INFO you will see any info that the turtlesim publishes when it starts up
roscd beginner_tutorials
mkdir launch
cd launch
gedit 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>
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]' # the two turtlesims start moving even though the publish command is only being sent to turtlesim1

Using rosed to edit files in ROS

rosed roscpp Logger.msg #  demonstrates how you would edit the Logger.msg file within the roscpp package

rosed roscpp <tab><tab> # tab auto complete

echo "export EDITOR='gedit -w'" >> ~/.bashrc
source ~/.bashrc
echo $EDITOR
rosed roscpp Logger.msg # This time file will be open by The more beginner-friendly editor

Creating a ROS 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.

Aboat Msg

$ roscd beginner_tutorials
$ mkdir msg
$ echo "int64 num" > msg/Num.msg rosed beginner_tutorials package.xml

Open package.xml, and make sure these two lines are in it.

  <build_depend>message_generation</build_depend>
<exec_depend>message_runtime</exec_depend>
rosed beginner_tutorials CMakeLists.txt

Modify it like this:

find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
message_generation
)
...
catkin_package(
...
CATKIN_DEPENDS message_runtime ...
...)
...
add_message_files(
FILES
Num.msg
)
...
generate_messages(
DEPENDENCIES
std_msgs
)
...

Make sure ROS can see it.

rosmsg show beginner_tutorials/Num # You will see: int64 num
rosmsg show Num # You will see: [beginner_tutorials/Num]: int64 num

Aboat srv

$ roscd beginner_tutorials
$ mkdir srv
$ roscp rospy_tutorials AddTwoInts.srv srv/AddTwoInts.srv
$ rosed beginner_tutorials CMakeLists.txt

Modify it like this:

...
add_service_files(
FILES
AddTwoInts.srv
)
...

make sure that ROS can see it using the rossrv show command

rossrv show beginner_tutorials/AddTwoInts
rossrv show AddTwoInts

Now that we have made some new messages we need to make our package again:

$ roscd beginner_tutorials
$ cd ../..
$ catkin_make install
$ cd -

Any .msg file in the msg directory will generate code for use in all supported languages. The C++ message header file will be generated in ~/catkin_ws/devel/include/beginner_tutorials/.

rosmsg -h

Review

Let's just list some of the commands we've used so far:

  • rospack = ros+pack(age) : provides information related to ROS packages
  • roscd = ros+cd : changes directory to a ROS package or stack

  • rosls = ros+ls : lists files in a ROS package

  • roscp = ros+cp : copies files from/to a ROS package

  • rosmsg = ros+msg : provides information related to ROS message definitions
  • rossrv = ros+srv : provides information related to ROS service definitions
  • catkin_make : makes (compiles) a ROS package
    • rosmake = ros+make : makes (compiles) a ROS package (if you're not using a catkin workspace)

ROS入门学习(基于Ubuntu16.04+kinetic)的更多相关文章

  1. SLAM+语音机器人DIY系列:(二)ROS入门——3.在ubuntu16.04中安装ROS kinetic

    摘要 ROS机器人操作系统在机器人应用领域很流行,依托代码开源和模块间协作等特性,给机器人开发者带来了很大的方便.我们的机器人“miiboo”中的大部分程序也采用ROS进行开发,所以本文就重点对ROS ...

  2. 基于ubuntu16.04部署IBM开源区块链项目-弹珠资产管理(Marbles)

    前言 本教程基本上是对Marbles项目的翻译过程. 如果英文比较好的话,建议根据官方操作说明,一步步进行环境部署.当然你也可以参考本教程在自己的主机上部署该项目. Marbles 介绍 关于 Mar ...

  3. 基于ubuntu16.04快速构建Hyperledger Fabric网络

    前言 最近在参加一个比赛,使用到了区块链的开源软件hyperledger,由于之前从未接触过区块链,以及和区块链开发相关的内容,所有在网上查阅了大量的资料,并且通过学习yeasy(杨宝华)开源的入门书 ...

  4. ROS入门学习

    ROS学习笔记 ROS入门网站; ROS入门书籍 ROS主要包含包括功能包.节点.话题.消息类型和服务; ROS功能包/软件包(Packages) ROS软件包是一组用于实现特定功能的相关文件的集合, ...

  5. C#码农的大数据之路 - 使用Ambari自动化安装HDP2.6(基于Ubuntu16.04)并运行.NET Core编写的MR作业

    准备主机 准备3台主机,名称作用如下: 昵称 Fully Qualified Domain Name IP 作用 Ubuntu-Parrot head1.parrot 192.168.9.126 Am ...

  6. 基于Ubuntu16.04的GeForce GTX 1080驱动安装,遇到的问题及对应的解决方法

    1.在主机上插上GPU之后,查看设备: $ nvidia-smi Tue Dec :: +------------------------------------------------------- ...

  7. Kubernetes入门学习--在Ubuntu16.0.4安装配置Minikube

    目 录 一. 安装minikube环境 1.1. 安装前准备 1.2. 安装Lantern 1.2.1. Lantern下载网站 1.2.2. Lantern下载地址 1.2.3. Lantern安装 ...

  8. 深度学习caffe:Ubuntu16.04安装指南(1)

    caffe [CPU ONLY] 2017-01-15 最简单的安装配置方式: 不用GPU加速,使用OPENCV2.4图像库, 这是根据官方教程(链接如下)简化而得到. Ubuntu 16.04 or ...

  9. Hadoop完全分布式环境搭建(三)——基于Ubuntu16.04安装和配置Java环境

    [系统环境] 1.宿主机OS:Win10 64位 2.虚拟机软件:VMware WorkStation 12 3.虚拟机OS:Ubuntu16.04 4.三台虚拟机 5.JDK文件:jdk-8u201 ...

随机推荐

  1. 基于 apache-arrow 的 duckdb rust 客户端

    背景 duckdb 是一个 C++ 编写的单机版嵌入式分析型数据库.它刚开源的时候是对标 SQLite 的列存数据库,并提供与 SQLite 一样的易用性,编译成一个头文件和一个 cpp 文件就可以在 ...

  2. odoo里面context用法

    原文转自:https://www.cnblogs.com/zhaoweihang/p/9698852.html <field name="partner_id" string ...

  3. phpcms开发使用

    二次开发入口文件: 1.dirname(__FILE___) 函数返回的是脚本所在在的路径 2.__FILE__ 当前运行文件的完整路径和文件名.如果用在被包含文件中,则返回被包含的文件名. 3.DI ...

  4. vsftpd安装配置

    vsftpd安装配置 vsftpd测试服务器: 192.168.1.191 1.安装: yum provides */vsftpd yum install vsftpd -y 2.匿名用户最基本配置( ...

  5. K8S为什么要弃用Docker?Dockershim将移除

    一.背景由于最近知道了 K8s 新版本(v1.20)确定弃用 Docker 的消息,为了明确是否会对现有系统架构产生响,所以对涉及到的相关技术进行了一定的梳理(索性的是对现有的系统架构基本无影响:&g ...

  6. Springboot通过拦截器拦截请求信息收集到日志

    1.需求 最近在工作中遇到的一个需求,将请求中的客户端类型.操作系统类型.ip.port.请求方式.URI以及请求参数值收集到日志中,网上找资料说用拦截器拦截所有请求然后收集信息,于是就开始了操作: ...

  7. 程序员被老板要求两个月做个APP,要不比京东差,网友:做一个快捷方式,直接链到京东

    隔行如隔山,这句话说得一点都没错.做一个程序员,很多人都会羡慕,也有很多人会望而却步. 作为一个外行人,你别看程序员每天坐在电脑前敲敲键盘打打代码,以为很简单,其实啊也只有程序员自己明白,任何一个看似 ...

  8. Jetpack MVVM 实战项目,附带源码+视频,收藏!

    从读者的反馈来看,近期大部分安卓开发已跳出舒适圈,开始尝试认识和应用 Jetpack MVVM 到实际的项目开发中. 只可惜,关于 Jetpack MVVM,网上多是 东拼西凑.人云亦云.通篇贴代码  ...

  9. 代码部署:使用 nginx 代理到云服务器 ( windows 系统)

    在部署之前我们首先要了解什么是nginx,它又可以做什么 Nginx 是高性能的 HTTP 和反向代理的web服务器,处理高并发能力是十分强大的,能经受高负 载的考验,有报告表明能支持高达 50,00 ...

  10. 【剑指offer】65. 不用加减乘除做加法

    剑指 Offer 65. 不用加减乘除做加法 知识点:数学:位运算 题目描述 写一个函数,求两个整数之和,要求在函数体内不得使用 "+"."-"."* ...