Java教程

ROS入门笔记

本文主要是介绍ROS入门笔记,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

安装

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

这篇关于ROS入门笔记的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!