ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

ROS入门笔记

2022-03-21 00:03:01  阅读:228  来源: 互联网

标签:src ROS catkin 入门 笔记 rostopic ros type


安装

ROS installation instructions
我安装 版本的是

ROS Melodic Morenia
Released May, 2018
LTS, supported until May, 2023
Recommended for Ubuntu 18.04

环境变量

  • source “some setup.*sh” files

source /opt/ros//setup.bash
source /opt/ros/melodic/setup.bash

设置每次打开终端,自动source设置文件

echo “source /opt/ros/melodic/setup.bash” >> ~/.bashrc
source ~/.bashrc

  • 查看环境变量

printenv | grep ROS

ROS_ETC_DIR=/opt/ros/melodic/etc/ros
ROS_ROOT=/opt/ros/melodic/share/ros
ROS_MASTER_URI=http://localhost:11311
ROS_VERSION=1
ROS_PYTHON_VERSION=2
ROS_PACKAGE_PATH=/opt/ros/melodic/share
ROSLISP_PACKAGE_DIRECTORIES=
ROS_DISTRO=melodic

Create a ROS Workspace

mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/
catkin_make
  • 工作空间的目录

build
devel. Inside the ‘devel’ folder you can see that there are now several setup.*sh files. Sourcing any of these files will overlay this workspace on top of your environment.
src : 里面有CmakeLists.txt

source devel/setup.bash

echo $ROS_PACKAGE_PATH
/home/lsy/catkin_ws/src:/opt/ros/melodic/share

Navigating the ROS Filesystem

  • Packages: Packages are the software organization unit of ROS code. Each package can contain libraries, executables, scripts, or other artifacts.

  • Manifests (package.xml): A manifest is a description of a package. It serves to define dependencies between packages and to capture meta information about the package like version, maintainer, license, etc…

rospack

rospack find [package_name]

roscd

roscd <package-or-stack>[/subdir]

rosls

rosls <package-or-stack>[/subdir]

Creating a ROS Package

cd ~/catkin_ws/src

catkin_create_pkg <package_name> [depend1] [depend2] [depend3]
catkin_create_pkg beginner_tutorials std_msgs rospy roscpp

cd ~/catkin_ws
catkin_make

package dependencies

rospack depends1 beginner_tutorials 
rospack depends beginner_tutorials

包的目录结构

在这里插入图片描述

编译包

$ catkin_make
$ catkin_make install  # (optionally)

$ catkin_make --source my_src
$ catkin_make install --source my_src  # (optionally)

The above commands will build any catkin projects found in the src folder.

节点

  • 节点: A node is an executable that uses ROS to communicate with other nodes.ROS nodes use a ROS client library to communicate with other nodes.
  • 消息:ROS data type used when subscribing or publishing to a topic.
  • 主题:odes 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 (parameter server will be introduced later)

客户端库:

  • rospy = python client library

  • roscpp = c++ client library

  • roscore = ros+core : master (provides name service for ROS) + rosout (stdout/stderr) + parameter server (parameter server will be introduced later)

  • rosnode = ros+node : ROS tool to get information about a node.

  • rosrun = ros+run : runs a node from a given package.

主题

  • 先执行两个节点
rosrun [--prefix cmd] [--debug] PACKAGE EXECUTABLE [ARGS]
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key
  • rqt_graph
rosrun rqt_graph rqt_graph
  • rostopic
lsy@lsy-GS65-Stealth-9SD:~/catkin_ws/src$ rostopic
rostopic is a command-line tool for printing information about ROS Topics.

Commands:
	rostopic bw	display bandwidth used by topic
	rostopic delay	display delay of topic from timestamp in header
	rostopic echo	print messages to screen
	rostopic find	find topics by type
	rostopic hz	display publishing rate of topic    
	rostopic info	print information about active topic
	rostopic list	list active topics
	rostopic pub	publish data to topic
	rostopic type	print topic or field type
  • rosmsg
lsy@lsy-GS65-Stealth-9SD:~/catkin_ws/src$ rostopic type /turtle1/cmd_vel
geometry_msgs/Twist
lsy@lsy-GS65-Stealth-9SD:~/catkin_ws/src$ rosmsg show geometry_msgs/Twist
geometry_msgs/Vector3 linear
  float64 x
  float64 y
  float64 z
geometry_msgs/Vector3 angular
  float64 x
  float64 y
  float64 z

主动发布主题

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]'
rostopic pub /turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, -1.8]'

Services and Parameters

节点可以通过服务来通信。Services allow nodes to send a request and receive a response.

  • rosservice
rosservice list         print information about active services
rosservice call         call the service with the provided args
rosservice type         print service type
rosservice find         find services by service type
rosservice uri          print service ROSRPC uri

rosservice type [service]

rosservice call [service] [args]
  • rosparam
    rosparam allows you to store and manipulate data on the ROS Parameter Server.
rosparam set            set parameter
rosparam get            get parameter
rosparam load           load parameters from file
rosparam dump           dump parameters to file
rosparam delete         delete parameter
rosparam list           list parameter names

rqt_console and roslaunch

using rqt_console and rqt_logger_level for debugging and roslaunch for starting many nodes at once.

  • roslaunch
    自动在包的目录下寻找对应的launch文件。oslaunch command automatically looks into the passed package and detects available launch files.
roslaunch beginner_tutorials turtlemimic.launch

lsy@lsy-GS65-Stealth-9SD:~/catkin_ws/src/beginner_tutorials$ rosrun turtlesim 
draw_square        mimic              turtlesim_node     turtle_teleop_key

一次性启动多个节点

<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>

rosed

不用输入完整目录

rosed [package_name] [filename]

msg 和 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.

每行一个类型

  Header header
  string child_frame_id
  geometry_msgs/PoseWithCovariance pose
  geometry_msgs/TwistWithCovariance twist
  • srv: an srv file describes a service. It is composed of two parts: a request and a response.
    分请求、响应2部分
int64 A
int64 B
---
int64 Sum

既使简单的功能,生成的文件页特别复杂

Publisher and Subscriber

固定流程。
CmakLists.txt

Writing a Simple Service and Client (C++)

还行吧。约束很多

Recording and playing back data

rosbag record -a
rosbag info 2022-03-20-19-10-22.bag 
rosbag play 2022-03-20-19-10-22.bag 
rosbag play -r 2  2022-03-20-19-10-22.bag 

Reading messages from a bag file

  • rostopic
  • ros_readbagfile:更快

Getting started with roswtf

标签:src,ROS,catkin,入门,笔记,rostopic,ros,type
来源: https://blog.csdn.net/qq_28038207/article/details/123468813

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有