Article Directory
- foreword
- 1. Course Introduction
- 2. Linux system introduction and installation
- 3. Linux basic operations (operation set)
- 4.cpp&python minimalist foundation (operation set)
- 5. Install ROS
- 6. What is ROS?
- 7. The core concept of ROS
- 8. Use of ROS command line tools (operation set)
- 9. Create workspaces and feature packages
- 10. Programming implementation of Publisher
- 11. Subscriber programming implementation
- 12. Definition and use of topic message
- 13. Client programming implementation
- 14. Programming implementation of server
- 15. Definition and use of service data
- 16. Parameter usage and programming method
- 17. Coordinate system management system in ROS
- 18. Programming realization of tf coordinate system broadcasting and monitoring
- 19. How to use the launch file
- 20. Use of common visualization tools
- Organize some trivial information
foreword
"I'm afraid that the truth is endless, and every inch of progress is joyful."
——Gu Yueshi
I am a freshman and a little white, and I have participated in an undergraduate research project, and I am currently learning some pre-basic knowledge related to ROS1.
Here, in the form of a blog, record the learning process, operation details and results, pit climbing methods, and lecture notes.
I hope that I can give some references to problem solving and companionship on the way of learning to friends who are also learning related knowledge.
I basically follow the "ROS Introduction 21 Lectures" (ROS1) recommended by Gu Yueju at Station B.
This blog is also a note in the order of learning
1. Course Introduction
The teacher's course uses Ubuntu 18.04, and
I use Ubuntu 20.04 for ROS melodic.
Since ROS noetic is ROS1, the principle and operation are the same
2. Linux system introduction and installation
Download VMware first
, and then recommend installing the desired ubuntu and ros on a certain treasure
(recommend Big Bear One Plus One).
Here, I tearfully delete thousands of words to engage in machine records.
3. Linux basic operations (operation set)
command structure
Spaces must be added between command
option parameters
Common commands
- pwd View the path where the terminal is located (Print Working Directory)
- cd switch path (note that there is a space before the slash) (change directory)
- cd .. Jump back to the parent directory (there should also be a space between cd and dot)
- mkdir creates a directory in the current path (make directory)
- ls lists all folders under the current path
- touch creates a new file (this file is equivalent to text Notepad)
- mv move a file (move)
(do this under the path of the directory where the file resides)
- cp copy paste a file (copy)
(do this under the path of the directory the file is in)
(cp filename target directory/renamed new name)
- rm delete a file (remove)
- rm -r delete a folder (recursive recursion)
(the effect of adding or not adding a slash after the folder to be deleted seems to be the same, I don’t know the logic of using the slash)
- sudo Elevate user privileges (super user do super user!)
(here to obtain software update privileges as an example)
- "- - help "View help
Shortcuts
- Tab quick completion.
Long file names can be completed with Tab.
If the initial letter of the file name is ambiguous, press twice to display options - Use the up and down arrow keys to recall the previous command,
press Ctrl+C when you don’t want to find it, and enter the command yourself - Adding dot before the file name is a hidden file
4.cpp&python minimalist foundation (operation set)
simple comparison
- cpp is suitable for underlying hardware development and framework development
- Python is suitable for application layer and algorithm development
- Choose different languages for different scenarios
install compiler
- Install the g++ compiler
- Install the python compiler (click the up arrow key to repeat the previous step, just change g++ to python). Something went wrong.
I
found a solution on CSDN. The solution is as follows.
The compiler installation is complete.
The teacher briefly explained the language logic. And some source code will be used for demonstration teaching. I entered the github file address on his WeChat public account and downloaded the source code.
But I couldn't copy and paste it to the virtual machine as easily as the teacher.
Finally, I turned off the virtual machine and changed a virtual machine setting, and changed the use of ISO files in the hardware CD/DCD to use automatic detection of physical drives. (I don’t know if this step works)
I still can’t drag the downloaded folder later. But the linux folder in the large folder can be dragged into the virtual machine. I tried another folder with subdirectories below, and it can also be dragged in. Maybe it's because the big folder is too big? I have no idea. Drag it to the desktop, something strange appears, I don’t understand. (It disappeared after restarting the virtual machine)
Ah, I successfully dragged the teaching folder into the virtual machine. What is the method? . . . Shorten the folder name. . .
I dragged the folder inside to the desktop again, and then deleted the original blank directory. This wave has the same effect as the teacher's direct dragging, which is a way.
compile and run
Let's start compiling and running the cpp for loop file.
- g++ filename -o output executable file name
g++ c++_for.cpp -o c++_for
- ./ run file
./c++_for
Python does not need to be compiled, and
the result is sent directly. SyntaxError: Missing parentheses in call to 'print'
I remember that there was a change when I installed the python compiler before, and the deviation is probably there.
So I went into the python file and modified the grammar (print changed to print()), which was a little different from Mr. Hu's courseware, and it ran successfully.
Run the cpp while program again, and press the up arrow key several times to call out the previous and previous commands.
Did a small thing, installed the IDE on the virtual machine. Regarding the fact that I decided to learn programming on a virtual machine, the first reason is that it is more novel, and the second is that a friend who is a computer tycoon did just that. It is said that there are some instructions that will be handy. When installing the IDE on the virtual machine, I struggled for a while between clion and VScode, and finally chose the latter. On the one hand, I have used clion for a period of time before and the experience is not good. What makes me satisfied is that the charts and pages are better-looking; on the other hand, I heard that the functions of VS are relatively powerful, and it can even communicate with the artificial intelligence ChatGPT. I love it. The installation process and results are also very clean, looking forward to the next study.
5. Install ROS
Provincial flow: on a certain treasure
6. What is ROS?
- Communication Mechanism + Development Tools + Application Functions + Ecosystem
Improve the software reuse rate in robot research and development.
During the learning process, it is recommended to use Google search to find the wiki website
(ROSwiki is the main forum for recording ROS information documents)
7. The core concept of ROS
Nodes and Node Managers
Node — the execution unit
- A node is a specific execution unit, a process that performs specific tasks, and an executable file that runs independently
- Different nodes can use different programming languages, and can be distributed and run on different hosts
- The name of the node in the system must be unique, and the ros system with the same name will not find it
Node Manager (ROS Master) — Control Center
- Node management. Naming, registering, setting up a newsletter
- Provides a parameter server that nodes use to store and retrieve parameters at runtime
Topic communication (asynchronous)
topic topic
- Divided into publishers and subscribers
- One-way data transmission, from the driver to the subscription segment, from the publisher to the subscriber
- A channel is defined as a topic, a bus for data transfer
message message
- Has a certain type and data structure (there are standard types provided by ros and user-defined types
- Define types and data structures using programming language-independent .msg files
Service communication (synchronous)
service service
- Using the client/server (service/client) model, the client sends request data, and the server returns response data after processing
- Use programming language-independent, .srv files to define request and response data structures
- Usually once, a configuration command is issued, the configuration content is completed, and a feedback is returned.
The buffer is to prevent the speed of publishing and subscription from not matching.
The service will be blocked.
parameter parameter
- Suitable for storing static, non-binary configuration parameters, not suitable for dynamic configuration data
File system
- Function package package: the basic unit of ros software, including source code, configuration files, and data definitions
- Function package list package manifest: record the basic information of the function package, including author information, license information, etc.
- Meta packages: organize multiple packages for the same purpose
8. Use of ROS command line tools (operation set)
(Begin practical operation)
The keyboard suddenly became unusable in the virtual machine. effective solution
rosrun
- roscore starts the ROS master (an instruction to be run first)
- rosrun to run a node
- (to call out to a new terminal)
- (Add two parameters, function package name node name)
- (After entering the function package name, press tab to display the nodes under the function package)
The cursor can only be controlled by the window where the keyboard controls the node
rqt_graph
- rqt_graph is a tool used to display system calculation graphs
- (intuitive, visualized, understand the whole picture of the system)
- (displays information about nodes and topics)
rosnode
- rosnode list
- (list the nodes used in the system)
- (rosout is a default topic of ros)
- rosnode info
- (View the information of a node)
- (publish and subscribe information)
rosnode info /turtlesim
rosy
Seeing the cmd_vel below is the topic of communication between the keyboard control node and the turtle emulator node just now.
Learn to use the tab. When entering the message type here, you need to press the tab twice.
- Use pub to publish data to a topic
- followed by topic name
- followed by the message structure (type)
- Then follow the specific data in the message structure
rostopic pub /turtle1/cmd_vel geometry_msgs/Twist "linear:
x: 1.0
y: 0.0
z: 0.0
angular:
x: 0.0
y: 0.0
z: 0.0"
Note that the unit of linear velocity here is meters per second, and the unit of angular velocity is radians per second).
When adjusting the specific data, you can only use the left and right arrow keys to move the cursor (use the up and down to call up the history command)
and see the little turtle moving forward 45 to the left. Moved for a short period of time
, I want the little turtle to move continuously
- -r means rate, 10 means 10Hz
rostopic pub -r 10 /turtle1/cmd_vel geometry_msgs/Twist "linear:
> x: 1.0
> y: 1.0
> z: 0.0
> angular:
> x: 0.0
> y: 0.0
> z: 0.0"
Adjust the z-adjustment rotation of the angular.
You can see that the direction and angular velocity can be adjusted.
The radius of the circle also conforms to the calculation of the velocity and angular velocity.
Adding a negative sign in front also makes sense
rosmsg
- rosmsg show shows the data structure of the message.
Let me make a complaint here. It seems that it is inconvenient to change the name of the device.
After the change, there will be problems in the communication between nodes,
so I have to continue to use ros-virtual-machine. .
rosservice
- rosservice list
- (all services provided)
- (The server is an emulator) (The client is a terminal)
- rosservice call Summons new turtles
rosservice call /spawn "x: 2.0
y: 2.0
theta: 0.0
name: 'turtle2'"
It can be seen that there is a feedback (feedback information name: "turtle2")
- topic record
rosbag record -a -O cmd_record
- (rosbag records all - uppercase O is saved as the name of the compressed package)
I saw the subscribed topic
and let the turtle move a few times.
After the end,
I saved it to the main folder by default in the terminal ctrl+c
. After pressing Enter, I started recording, including the waiting time without operation.
- topic recurrence
rosbag play cmd_record.bag
9. Create workspaces and feature packages
concept
- Workspace (workspace) is a folder that stores files related to project development. All source code, configuration files, and executable files are placed inside. It is mainly divided into four folders:
- 1.src: code space (source space)
to place function packages (codes, configuration files, launch files inside
2.build: Intermediate files in the compilation process of the build space (don't care too much
3.devel: Some executable files, libraries, and scripts compiled and generated by the development space- 4.install: install space (install space)
the result of the install command is placed inside
Put a screenshot of the teacher's courseware:
create workspace
overview:
operation:
catkin_init_workspace //初始化工作空间(属性变化),看到冒出了CMakeLists.txt
- Compile the project below (
catkin_make
- To come to the root directory of the workspace to compile
, see that there are two other spaces:
make the install space appear:
Create feature pack
- A function package is the smallest unit for placing ROS source code
- Function packages with the same name are not allowed to exist in the same workspace
Create a function package:
(to be placed in src):
Command function package name Dependency 1 Dependency 2 Dependency 3:
catkin_create_pkg test_pkg roscpp rospy std_msgs
Open the function package:
include to place the header file
src and put the code.
The latter two files must be included in the function package, which makes them different from the properties of ordinary folders.
Compile the function package
. It is better to return to the catkin_ws
compilation workspace
because there is no code, so there is no Actual effect
If you want to run a certain program in the function package, you must first set the environment variable of the workspace.
After setting, the system can find the workspace
Set environment variables :
ros@ros-virtual-machine:~/catkin_ws$ source devel/setup.bash
Check environment variables
- Use the echo command to open the environment variable
- (ROS_PACKAGE_PATH is an environment variable of ROS itself, through this environment variable to find the path of all function packages)
- It is also only after the setup.bash of the workspace is set in the previous step that the path of the workspace will be included in the path
ros@ros-virtual-machine:~/catkin_ws$ echo $ROS_PACKAGE_PATH
/home/ros/catkin_ws/src:/opt/ros/noetic/share
I don’t understand a bit, post the explanation of chatGPT
Summary:
create workspace
- Create: Create a new workspace folder, and create a new code space under this folder
- cd into the code space
- Initialize the workspace with the command
- cd into the workspace
- Compile the workspace with the command
- source set environment variables
- Check environment variables
Create feature pack
- cd into the code space under the workspace
- Create a feature package and configure dependencies
- cd to workspace
- compile workspace
- source set environment variables
10. Programming implementation of Publisher
- cd into the code space under the workspace, create a function package, and configure dependencies
- Write C++ code files in the code space in the function package
- Configure compilation rules in the cmakelist file
- cd to the workspace, compile the workspace, source set environment variables
- Open roscore, run the turtle simulation node, and run the publisher's node in the function package
11. Subscriber programming implementation
- Write C++ code files and configure compilation rules
- cd to the workspace, compile, set environment variables
- Open roscore, run the turtle node, and run the subscriber's node in the function package
12. Definition and use of topic message
- Define the msg file
- Add function package dependencies in package.xml
- Add compilation options in cmakelist.txt
- Compile and generate language-related files
- write publisher
- write subscriber
- Configure compilation rules in the cmake file:
1. Set up the code to compile and the resulting executable
2. Set up the link library
3. Add dependencies
- cd to the workspace, compile, configure environment variables
- Open roscore, run the publisher node and subscriber node
13. Client programming implementation
-
cd to the code space, create a function package
-
Write C++ code, configure compilation rules
-
cd to the workspace, compile, configure environment variables
-
Open roscore, run the turtle simulation node, run the client node
14. Programming implementation of server
-
Write C++ code, configure compilation rules
-
cd to the workspace, compile, configure environment variables
-
Open roscore, run the turtle simulation node, run the server node
-
$ rosservice call /turtle_command "{}" publish message
15. Definition and use of service data
- Define msg files, add function package dependencies, add compilation options, compile and generate related files
- Write Publisher, Write Subscriber
- Configure compilation rules in the cmake file:
1. Set up the code to compile and the resulting executable 2. Set up the link library 3. Add dependencies
- cd to the workspace, compile, configure environment variables
- Open roscore, run the server, run the client node
16. Parameter usage and programming method
- cd to the code space, create a function package
- Write C++ code, configure compilation rules
- cd to the workspace, compile, configure environment variables
- Open roscore, run the turtle simulation node, run the parameter setting node
17. Coordinate system management system in ROS
- $ sudo apt-getinstall ros-melodic-turtle-tf
- $ roslaunch turtle_tf turtletf demo.launch
- $ rosrun turtlesim turtle_teleop_key
- $ rosrun tf view_frames
18. Programming realization of tf coordinate system broadcasting and monitoring
- cd to the code space, create a function package
- Write the C++ code of the broadcaster and listener, and configure the compilation rules
- cd to the workspace, compile, configure environment variables
- open roscore
- Run the turtle simulation node
- Broadcaster nodes running turtle1 and turtle2
- Run the listener node
- Run the keyboard control node
19. How to use the launch file
- launch file: realize multi-node configuration and startup through xml file (ros master can be started automatically)
- Write the syntax of starting nodes and the syntax of parameter settings in launch
20. Use of common visualization tools
Qt Toolbox
- Provides a range of visualization tools
Rviz
- 3D visualization tools
Gazebo
Organize some trivial information
This week is mainly about the code implementation link in the recurring teacher Gu Yueju's course
Do not ask to memorize every detail and order
The goal to be achieved is to be able to think of where to go when a certain function is needed, and to realize the desired function in front of the teacher's courseware
Notice:
The statements in the command line and cmakelist should not lack spaces
Note that there is an error on page 6 of Section 11, rosrun should be pose_publisher
- 3D physical simulation platform
- To use the python program in the teacher's teaching package, change the first line of the python file to python3
When running python, remember to change it to the syntax of python3.
The command to run the phthon file is in Lecture 11.
What is there to say, just follow the barrage boss to correct the mistakes.
Here you can adjust the text format to achieve the highlight effect.