Control Manager

ControlManager was created to reduce the amount of boiler plate when creating multiple “control modes” for a robot. Essentially, each driver wants their own set of controls. For MagicRobot is is very easy, as each controlmanager mode can be a component that then has variables injected. However, adding all the control modes to the dashboard with a nice chooser, detecting and handling changes can lead to a lot of boilerplate.

ControlManager allows us to reduce boilerplate by subclassing ControlInterface and then initializing ControlManager with the control interfaces, and it creates the chooser.

For even more code reducing magic, see decorator.with_ctrl_manager() which when used with MagicRobot, completely removes all boilerplate by managing the creation of a ControlManager and dispatching event calls.

class marsutils.controlmanager.ControlInterface[source]

Bases: object

ControlInterface is the base class that all interfaces must subclass to be used with ControlManager.

You must define a _DISPLAY_NAME. This value will be displayed in the dashboard chooser. Optionally, you can define a _SORT value. The larger the value, the higher priority it will be given in the chooser.

disabled()[source]
enabled()[source]
teleopPeriodic()[source]
class marsutils.controlmanager.ControlManager(*interfaces, dashboard_key: Optional[str] = 'Control Mode')[source]

This class manages creating a dashboard chooser and the periodic calling of a series of “control interface” components.

Each control interface must subclass ControlInterface and define _DISPLAY_NAME.

Once this has been initalized with the list of interfaces, you must manually call every event function you want your components to recive, like “teleopPeridic” and “teleopInit” and they will be forwarded to the active interface

You can optionally define a _SORT value for your interfaces. The larger the value, the higher priority it will be given in the chooser.

If dashboard_key is None, then the control chooser will not be added automatically, use this if you are using the Shuffleboard API or want a different root path. The control chooser can be accessed from control_chooser

setup_listener(dashboard_key)[source]

If you construct the ControlManager with a None dashboard_key, you must call this function with the full networktables path to connect the callback for the mode to be properly updated