The principle of twist_mux is similar to the task scheduling in RTOS. The priority needs to be set for each input topic. Different topics can also be set to the same priority, but this is not recommended. In addition to the priority mechanism, twist_mux can limit the choice of input topics based on timeout constraints and external lock topics.
When we are doing robot ROS development, we often encounter the same speed control message selection problem. For example, the geometry_msgs::Twist message that controls the movement of the robot can be published using a keyboard node, can be published using a handle node, or can be published by movebase during navigation. When these nodes are running simultaneously, multiple nodes publish the same speed control topic. At this time, the robot is confused. Who should listen to it? Who can hear only what data it receives?
To solve this problem, ROS provides a mux multi-switcher, twist_mux, which helps us switch to the data source we wish to receive.
— Principle —
As we described in the opening scene, when the robot receives speed control messages issued by different nodes, how to choose?
Recall the principle of task scheduling in the RTOS. Each task has its own priority. When multiple tasks enter the waiting state, the system will select the task with the highest priority. Many systems also support tasks of the same priority. The system will perform tasks in a time-slot polling manner, that is, impartial and equal to the same priority task.
The principle of twist_mux is similar to the task scheduling in RTOS. The priority needs to be set for each input topic. Different topics can also be set to the same priority, but this is not recommended.
In addition to the priority mechanism, twist_mux can limit the choice of input topics based on timeout constraints and external lock topics.
The core node in the twist_mux function package is twist_mux. Its input and output are as follows:
On the left is a number of topics of type geometry_msgs::Twist. After the selection of twist_mux, a unique geometry_msgs::Twist topic is output. The topic entered below is the lock topic of the user's dynamic configuration selection mechanism. The topic's message type is Bool. Just like a lock, only two states can be opened and closed.
Here the concept of lock can be understood as: by limiting the input sources of different priorities, to achieve the effect of control output.
— Configuration —
The twist_mux package can be installed in one sentence:
Sudo apt-get install ros-indigo-twist-mux
Then you can run the multiplexer:
Roslaunch twist_mux twist_mux.launch
Print the current list of topics to see:
Let's take a look at the twist_mux.launch file in the end:
As you can see, some of the topic name parameters are configured in the launch file. Two configuration files are loaded during the startup of the twist_mux node. The corresponding configuration of the input topic is twist_mux_topics.yaml, and the lock_mux_locks.yaml corresponds to the lock topic. Configuration.
1. twist_mux_topics.yaml
# Input topics handled/muxed.# For each topic:# - name : name identifier to select the topic# - topic : input topic of geometry_msgs::Twist type# - timeout : timeout in seconds to start discarding old messages, and use 0.0 Speed ​​instead# - priority: priority in the range [0, 255]; the higher the more priority over other topicstopics:- name : navigation topic : nav_vel timeout : 0.5 priority: 10- name : joystick topic : joy_vel timeout : 0.5 priority: 100- name : keyboard topic : key_vel timeout : 0.5 priority: 90- name : tablet topic : tab_vel timeout : 0.5 priority: 100
The configuration file contains a configuration list of input topics. The configuration items for each input topic include the following:
Name: a user-readable name, not a topic name, only for debugging display;
Topic: topic name, topic must be geometry_msgs::Twist type;
Timeout: the timeout allowed by the message. If there is no data after this time, it will switch to other input topics. If it is set to 0, it is equivalent to no limit and will wait indefinitely.
Priority: Enter the priority of the topic, 0~255, the higher the value, the higher the priority
2. twist_mux_locks.yaml
# Locks to stop the twist inputs.# For each lock:# - topic : input topic that provides the lock; it must be of type std_msgs::Bool?!!!# - timeout : == 0.0 -> not used# > 0.0 -> the lock is told to published at a certain frequency in order# to detect that the publisher is alive; the timeout in seconds allows# to detect that, and if the publisher dies we will enable the lock# - priority: priority in The range [0, 255], so all the topics with priority lower than it# will be stopped/disabledlocks:- name : pause topic : pause_navigation timeout : 0.0 # Same priority as joystick control, so it'll not block it. : 100- name : loop_closure topic : stop_closing_loop timeout : 0.0 priority: 200- name : joystick topic : joy_priority timeout : 0.0 priority: 100
The configuration of the lock topic is also a list. Each sub-item is a configuration of a lock topic. Configuration items include the following:
Name: a user-readable name, not a topic name, only for debugging display;
Topic: lock topic name, message type must be std_msgs::Bool type;
Timeout: The lock topic needs to be issued periodically. Therefore, after the time limit is exceeded, the node that issued the lock is considered to be offline, and the lock is invalid, similar to the function of the watchdog. If it is set to 0, there is no timeout limit and it remains effective.
Priority: Limits the priority of the input topic, between 0 and 255, the priority below this value, will be locked, can not be output before unlocking, in order to achieve the effect of dynamic control output.
- Practice -
Now let's verify the effect of twist_mux through practice.
Start the twist_mux node first:
Roslaunch twist_mux twist_mux.launch
Then listen to the final output speed control message:
Rostopic echo /twist_mux/cmd_vel
1. Selection of multiple input sources
There is currently no input, so there will be no output.
Then we can publish several input messages, first publish a navigation output speed message:
Rostopic pub -r 10 /nav_vel geometry_msgs/Twist "linear: x: 1.0 y: 0.0 z: 0.0angular: x: 0.0 y: 0.0 z: 0.0"
After the successful release, the output listener does not have any output, because in the lock message, we set the minimum priority is 100, and the nav_vel priority is set in the configuration file is 10, naturally blocked out the door, no Method output.
Let's post the joy_vel message again:
Rostopic pub -r 10 /joy_vel geometry_msgs/Twist "linear: x: 2.0 y: 0.0 z: 0.0angular: x: 0.0 y: 0.0 z: 0.0"
Soon you can see the joy_vel message in the output monitor as shown below:
There are two input messages, nav_vel and joy_vel. After the selection of twist_mux, only the joy_vel message is output.
So what if we want to output nav_vel?
With the nav_vel and joy_vel messages still released, reopen a window and close the priority threshold:
Rostopic pub /joy_priority std_msgs/Bool "data: false"
At this point if the joy_vel message is stopped or timed out, the twist_mux will automatically switch to the nav_vel output, we can directly kiil off the topic of joy_vel, and the output listening terminal will display the data of the nav_vel message:
2. Stop the input source below a certain priority
What if we want to pause the output? The topic of pausing nav_vel is also set in the lock message:
Rostopic pub /pause_navigation std_msgs/Bool "data: true"
Now the nav_vel topic is suspended. If you want to resume, you only need to publish the pause_navigation message again:
Rostopic pub /pause_navigation std_msgs/Bool "data: false"
It should be noted that the priority set by the /pause_navigation topic is the same as joy_priority, so the pause here cannot suspend the topic of priority 100 and above, so it does not affect the forwarding of the joy_vel message.
We also set a control lock with a priority of 200 in the lock configuration. Once we activate the lock, the following priority 200 topics will stop forwarding:
Rostopic pub /stop_closing_loop std_msgs/Bool "data: true"
Now all topics cannot be output through twist_mux.
OK, now we should have understood the principle and usage of the twist_mux function package, flexible use of lock configuration, allows us to easily control the switching of multiple input sources.
SC/PC Fiber Optic Fast Connector
Sc/Pc Fiber Optic Fast Connector,Fast Fiber Connector Kit,Quick Connect Fiber Connectors,Sc Quick Connector
Ningbo Fengwei Communication Technology Co., Ltd , https://www.fengweicommunication.com