Skip to content

ezrassor_topic_switch

Tiger Sachse edited this page Jun 26, 2019 · 11 revisions

Summary

The ezrassor_topic_switch routes information from a dominant input topic to an output topic while blocking a recessive input topic. The dominance of these two topics may be "switched" back and forth with an auxiliary "toggle" topic. This is primarily useful during operation of the EZ-RASSOR in "dual mode," when both autonomous control and manual control are enabled. In dual mode, when an autonomous routine is requested manual controls are blocked using topic switches until the autonomous controller relinquishes control back to the user. Topic switches are an optional part of the system and are only employed in dual mode.

Inputs/Outputs

The following is a list of topic inputs and outputs, with each topic's type shown in brackets:

INPUTS
node <- primary topic configured at launch [configured at launch]
node <- secondary topic configured at launch [configured at launch]
node <- /secondary_override_toggle [std_msgs/Bool]

OUTPUTS
node -> output topic configured at launch [configured at launch]

Launch Files

topic_switch.launch

This launch file spins up a single topic switch node. This node is configured via arguments at launch which are passed to the node as namespaced ROS parameters. All possible arguments are listed below:

node_name
The topic switch's name. It must be unique in the switch's namespace.
primary_topic
The primary input topic that the switch listens to. This topic is initially the dominant topic.
secondary_topic
The secondary input topic that the switch listens to. This topic is initially the recessive topic.
output_topic
The topic that the switch outputs all routed information to.
topic_type_module
The name of the Python message module that the primary and secondary topics handle. Examples include std_msgs.msg and geometry_msgs.msg. Custom modules are also supported.
topic_type_class
The name of the message class that the primary and secondary topics handle. Examples include Int8 and Twist. Custom classes are also supported.

Examples

Launch a topic switch that listens to manual and autonomous wheel instructions, and then publishes dominant instructions to /wheel_instructions:

roslaunch ezrassor_topic_switch topic_switch.launch \
    node_name:=wheel_switcher \
    primary_topic:=manual_wheel_instructions \
    secondary_topic:=autonomous_wheel_instructions \
    output_topic:=wheel_instructions \
    topic_type_module:="geometry_msgs.msg" \
    topic_type_class:=Twist

Launch a topic switch that listens for Float32 messages on /primary and /secondary, then echo the /primary, /secondary, and /output topics. Finally, publish a bunch of data points to /primary, /secondary, and /secondary_toggle_switch topics and observe the results (you'll need five terminals for this):

# Launch the topic switch in terminal one.
roslaunch ezrassor_topic_switch topic_switch.launch \
    node_name:=example_switcher \
    primary_topic:=primary \
    secondary_topic:=secondary \
    output_topic:=output \
    topic_type_module:="std_msgs.msg" \
    topic_type_class:=Float32

# Echo the /primary topic in terminal two.
rostopic echo /primary

# Echo the /secondary topic in terminal three.
rostopic echo /secondary

# Echo the /output topic in terminal four.
rostopic echo /output

# Publish several float data points to /primary and /secondary
# in terminal five. Only the the numbers published to /primary
# will show up in /output.
rostopic pub /primary std_msgs/Float32 "data: 13.37" -1 &
rostopic pub /primary std_msgs/Float32 "data: 9001.0" -1 &
rostopic pub /secondary std_msgs/Float32 "data: 40.2" -1 &
rostopic pub /secondary std_msgs/Float32 "data: 100.0" -1 &

# Toggle the topic switch to make /secondary the dominant topic
# in terminal five.
rostopic pub /secondary_override_toggle std_msgs/Bool "data: true" -1 &

# Publish more data to /primary and /secondary in terminal five.
# Only the numbers published to /secondary will show up in /output.
rostopic pub /primary std_msgs/Float32 "data: -10000.00001" -1 &
rostopic pub /primary std_msgs/Float32 "data: 77.77" -1 &
rostopic pub /secondary std_msgs/Float32 "data: 19.69" -1 &
rostopic pub /secondary std_msgs/Float32 "data: 19.63" -1 &