其他分享
首页 > 其他分享> > ROS入门笔记

ROS入门笔记

作者:互联网

安装

ROS installation instructions
我安装 版本的是

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

环境变量

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

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.

节点

客户端库:

主题

rosrun [--prefix cmd] [--debug] PACKAGE EXECUTABLE [ARGS]
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key
rosrun rqt_graph rqt_graph
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
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 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 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 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 文件

每行一个类型

  Header header
  string child_frame_id
  geometry_msgs/PoseWithCovariance pose
  geometry_msgs/TwistWithCovariance twist
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

Getting started with roswtf

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