Hi, folks in Duckietown!
This figure below actually comes from the Duckietown materials issued by NCTU. I know a little bit about the role of cbSwitch in FSM but if can anyone elaborate it for me?
Plus, what does “cb” stand for (in cbSwitch)? I’ve seen many times the name of a function starting with “cb” but I have no idea what it actually indicates.
Thank you for your interest!
First “cb” stands for “Callback” – it indicates that these are functions that are being used as callback functions, often specified in a topic subscription.
Second the “cbSwitch” exists in many nodes and is used to effectively disable the node. In other words, when the switch is “false” the node stops doing anything. If you look at the config for the FSM under “states” you will see for each state that there is a list of “active nodes”. These are the nodes that should be running during the specified state. Under the hood this is managed through publications to the “switch” topics which are listed just above the “states”.
The purpose of this is so that when we don’t need nodes to be running to achieve a certain objective, they don’t waste computation. The most common case is that of perception nodes which generally require more computation and are not always needed.
Note that in your figure above, the code on the left hand side is for a “Perception” node, the line detector, and is not really related to the picture on the right which is about control.