This case uses the example provided by ROS1 to demonstrate the program.
This series takes 7 days. Bloggers also try their best to write it from scratch. If you find an error, you must tell me in a private letter. Bloggers who work so hard, pay attention.
Author: Yang Sier Motto: from interest, from love, into investment. Introduction: artificial intelligence major, University of Edinburgh. Technical interests focus on robots, artificial intelligence, interpretability, mathematics, physics and so on. Personal blog: discover304.top Personal station B account: Yang Si'er is also practicing immortality in science today
⭐ ⅸ operation method
- Execute $roscore to start roscore
- Execute and run under package: $rosrun < package name > < executable program in package / python script > [< other parameters >]
I thought renaming was such a difficult task. After practice, I found that it was a super simple trick.
A robot always has many repeated components, such as two arms or two pairs of wheels, or four cameras in front, back, left and right. We can arrange the programs running on each component by renaming, which is convenient for software development and management.
There are three kinds of renaming in ROS: modifying namespace, modifying node name and modifying subject / message name.
✨ Naming concept
First, understand the naming in ROS. The planning of messages or node names in ROS is similar to the path of computer system, separated by backslash "/".
The folder in the computer corresponds to the namespace in the ROS naming, and the file in the computer corresponds to the node name in the ROS naming.
✨ Naming effect
# Terminal 1 rosmaster # Terminal 2 rosrun rospy_tutorials talker # Terminal 3 rosrun rospy_tutorials listener # Terminal 4 rosrun rospy_tutorials talker # Terminal 5 rosrun rospy_tutorials listener # Terminal 6 rqt_graph
Operation after naming
# Terminal 1 rosmaster # Terminal 2 rosrun rospy_tutorials talker __ns:=first __name:=talker # Terminal 3 rosrun rospy_tutorials listener __ns:=first __name:=listener chatter:=/second/chatter # Terminal 4 rosrun rospy_tutorials talker __ns:=second __name:=talker # Terminal 5 rosrun rospy_tutorials listener __ns:=second __name:=listener chatter:=/first/chatter # Terminal 6 rqt_graph
The structure is clear, and the communication between the two namespaces is realized at the same time.
✨ rename method
After the program runs the instruction, add the rename rule according to the following format.
- Namespace remapping: $rosrun < package name > < program name >__ NS: = < new namespace name >
- Node rename: $rosrun < package name > < program name >__ Name: = < new node name >
- Message rename: $rosrun < package name > < program name > < message name >: = < new message name >
Key: the above three grammars can be used at the same time.
If there are python code programs in the current path, you can also directly use $/< The program name > [< ditto >] replaces the above instruction.
⭐ ROS Launch launch
Every time you start a system of ROS, you need to take so many steps above, which is too cumbersome.
Of course, you can also write one of these bash script, one click start. However, ROS provides us with an automatic startup method called roslaunch.
Different from the start instruction rosrun above, we use the roslaunch instruction to start here. The syntax is: $roslaunch < package name > < Launch filename >
✨ file structure
The. launch file is essentially an xml file. Its basic structure is as follows
- launch - node - name="<Node name>" - ns="<Namespace>" - pkg="<Package name>" - type="<Software name>" - output="screen"，This is a debugging method, output to the terminal. It can be removed after debugging to ensure the cleanliness of the terminal. - Other naming - node - ···
✨ File example
The use code of this case comes from: [robot] ROS engineering case: basic part
<launch> <node name="publisher" ns="first" pkg="communicate_bot" type="topic_publisher.py" output="screen"/> <node name="subscriber" ns="first" pkg="communicate_bot" type="topic_subscriber.py" output="screen"/> <node name="publisher" ns="second" pkg="communicate_bot" type="topic_publisher.py" output="screen"/> <node name="subscriber" ns="second" pkg="communicate_bot" type="topic_subscriber.py" output="screen"/> </launch>
✨ Operation effect
source devel/setup.bash roslaunch communicate_bot communicate.launch
It should be noted that roslaunch will automatically start one when there is no rosmaster. However, because there is a risk of losing the master node, it is recommended to start another terminal when deploying.