ROS tutorial

Posted by caraldur on Sat, 18 Dec 2021 14:28:24 +0100

ROS itself provides a point-to-point network to jointly process data. Its basic concepts include node, master node, parameter server, message, service, topic, package and so on.

Use separately
rospack - get package related information: View package dependencies,
roscd - switch to the package directory
rosls - view package files
rosnode - view the related information of the ros node: view the node list and the node message attributes
rosrun - running software package - function of a node: rqt graph
rostopic - get topic related information
rosservice - get service related information
rosparam - get parameter related information
roslaunch - start the launch file
rosmsg - view information about messages

You can use Tab to complete the code

The complete structure of the whole ROS program is

workspace_folder/        -- WORKSPACE
  src/                   -- SOURCE SPACE
    CMakeLists.txt       -- 'Toplevel' CMake file, provided by catkin
    package_1/
      CMakeLists.txt     -- CMakeLists.txt file for package_1
      package.xml        -- Package manifest for package_1
    ...
    package_n/
      CMakeLists.txt     -- CMakeLists.txt file for package_n
      package.xml        -- Package manifest for package_n
  1. Initialize workspace
mkdir -p my_workspace/src
cd my_workspace/src
  1. Create package catkin_ create_ pkg <package_ name> [depend1] [depend2] [depend3]
catkin_create_pkg beginner_tutorials std_msgs rospy roscpp
  1. Create a catkin workspace to validate the configuration file
    Using catkin_make, that is, cmake and make are called successively in the cmake standard workflow.
cd ..
catkin_make
catkin_make install

# Equivalent to executing in CMAKE workspace:
# mkdir build | cd build | cmake .. | make | make install
  1. Run the software package and view the system structure
    Run the example function of the keyboard to control the movement of the little turtle, and run the following commands in multiple terminal windows
roscore
rosrun turtlesim turtlesim_node  __name:=my_turtle
rosrun turtlesim turtle_teleop_key

Check the hierarchical direction of communication

rosrun rqt_graph rqt_graph
  1. rostopic instruction details
    (1) Echo - receive topic message data - rostopic echo < topic_name >
    (2) Pub - publish topic message data - rostopic pub < topic_name > < msgs_type > [args]
# Release a little turtle speed topic message data
rostopic pub -1 /turtle1/cmd_vel geometry_msgs/Twist -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, 1.8]'
# Continuously release the speed data of the little turtle at the frequency of 1Hz
rostopic pub /turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, -1.8]'

(3) hz view data publishing rate-``

  1. rosservice instruction details
(1)rosservice list Get service list
(2)rosservice call 
  1. rosparam instruction details
#(1) Get parameter list from rosparam list
#(2) rosparam get [param_name] get parameter value
#(3) rosparam set [param_name] [args] set parameter value
#(4) rosparam load [yaml_name] ([namespace]) loads parameters from a file (loads a new namespace)
#(5) Rosparam dump [yaml_name] ([namespace]) dumps parameters to a file (loads a new namespace)
#(6) rosparam delete [param_name] delete parameter
  1. rqt instruction details
    (1) View node delivery message hierarchy: rosrun rqt_graph rqt_graph
    (2) View data graph: rosrun rqt_plot rqt_plot
    (3) View log frame: rosrun rqt_console rqt_console
    (4) Level of detail for viewing information: rosrun rqt_logger_level rqt_logger_level
  2. roslaunch
    Create a launch file home in the software package (such as beginer_tutorials) folder to save the launch file.
<launch>
	<!--
	Create two groups with namespaces turtlesim1,turtlesim2
	They all contain sim of turtlesim Node,
	-->
	<group ns="turtlesim1">
		<node pkg="turtlesim" name="sim" type="turtlesim_node"/>
	</group>
	
	<group ns="turtlesim2">
		<node pkg="turtlesim" name="sim" type="turtlesim_node"/>
	</group>
	
	<!--
	Start the imitation node. The input and output of imitation are turtlesim1 and turtlesim2
	-->
	<node pkg="turtlesim" name="mimic" type="mimic">
		<remap from="input" to="turtlesim1/turtle1"/>
		<remap from="output" to="turtlesim2/turtle1"/>
	</node>
	
</launch>

Run the launch file and publish the topic message in the terminal window

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 level of message passing is

13. Rose operation details
Rose is part of the rosbash suite and can be used to edit files in packages
Set default editor
For detailed operation, see: http://wiki.ros.org/cn/ROS/Tutorials/UsingRosEd

10. Create ROS messages and services

(1) Basic introduction

Both message (. msg) and service (. srv) are text files, which are generally placed in the msg and srv folders in the software function package (at the same level as launch) to generate source code for messages written in different languages. msg has only one part, and the service is divided into request and response.

(2) Type format

Available types:

  • int8, int16, int32, int64 (and uint *)
  • float32, float64
  • string
  • time, duration
  • Other msg files
  • Variable length array [] and fixed length array [C]
    . The srv file uses one --- to separate the request and response parts up and down, such as:
int64 A
int64 B
---
int64 Sum

(3) Create a message or service

To ensure that it can be converted into the source code of C + +, python or other languages (that is, if you need to build your own message type), you need to add relevant codes in package.xml and CMakeLists.txt:

For messages

package.xml

  <build_depend>message_generation</build_depend>
  <exec_depend>message_runtime</exec_depend>

CMakeLists.txt

  • find_ Add message to package_ generation
  • catkin_package uncomment and in catkin_ Add message after demands_ runtime
  • add_message_files uncomment and add message_name.msg
  • generate_messages uncomment

For services

package.xml

  <build_depend>message_generation</build_depend>
  <exec_depend>message_runtime</exec_depend>

CMakeLists.txt

  • find_ Add message to package_ generation
  • catkin_package uncomment and in catkin_ Add message after demands_ runtime
  • add_service_files uncomment and add a service_name.srv
  • generate_messages uncomment

After adding, return to the workspace and use catkin_make recompile the ROS package. After the compilation, the self created message types are loaded into the rosmaster. You can use rosmsg show < message_ Name > or rossrv show < service_ Name > View message details.

11. Write simple publishers and subscribers

Topics: Linux ROS