Subsystem Toggling
Last updated
Last updated
This work is licensed under a Attribution-ShareAlike 2.0 Generic License
A subsystem toggle is an operator control feature that allows the user to turn a specific subsystem on the robot on or off. This can be useful for a variety of reasons, such as conserving energy, testing individual components, or disabling a subsystem that is not currently in use.
This is widely used on subsystems that may need to run for prolonged periods of time but may need to stop for various reasons such as a flywheel, lift position hold, or an intake.
Conceptually, we want to visualize our "toggle" feature as a state machine with 2 states. We start in state 1 where the subsystem is off by default, and turn on the subsystem by pressing the toggle button. In order to keep track of this state, we can use a Boolean variable to do so. If more states are needed, we simply expand the diagram above to have more states where the subsystem has different actions than off and on, and use an integer value or an enumeration to keep track of current state.
In the example code below, we will use the button "b" on the VEX V5 controller to toggle a VEX V5 motor on and off.
While simple in concept, the execution of such code might be challenging to grasp for beginners. Do note that if multiple threads are both writing and reading to the state variable, it is best practice to use some form of thread protection such as a mutex.
BLRS (Purdue SIGBots)