OpModeRobotBase
- class wpilib.OpModeRobotBase(*args, **kwargs)
Bases:
RobotBaseOpModeRobotBase is the non-templated base class for OpModeRobot. Users should generally prefer using OpModeRobot instead of this class.
Opmodes are constructed when selected on the driver station, and destroyed when the robot is disabled after being enabled or a different opmode is selected. When no opmode is selected, NonePeriodic() is called. The DriverStationConnected() function is called the first time the driver station connects to the robot.
Overloaded function.
__init__(self: wpilib._wpilib.OpModeRobotBase, period: wpimath.units.seconds) -> None
Constructor.
- Parameters:
period – The period of the robot loop function.
__init__(self: wpilib._wpilib.OpModeRobotBase) -> None
Constructor for an OpModeRobot with a default loop time of 0.02 seconds.
- DEFAULT_PERIOD = 20.0
- addOpModeFactory(*args, **kwargs)
Overloaded function.
addOpModeFactory(self: wpilib._wpilib.OpModeRobotBase, factory: collections.abc.Callable[[], wpilib._wpilib.OpMode], mode: hal._wpiHal.RobotMode, name: str, group: str, description: str, textColor: wpiutil._wpiutil.Color, backgroundColor: wpiutil._wpiutil.Color) -> None
Adds an operating mode option using a factory function that creates the opmode. It’s necessary to call PublishOpModes() to make the added modes visible to the driver station.
- Parameters:
factory – factory function
mode – robot mode
name – name of the operating mode
group – group of the operating mode
description – description of the operating mode
textColor – text color
backgroundColor – background color
addOpModeFactory(self: wpilib._wpilib.OpModeRobotBase, factory: collections.abc.Callable[[], wpilib._wpilib.OpMode], mode: hal._wpiHal.RobotMode, name: str, group: str = ‘’, description: str = ‘’) -> None
Adds an operating mode option using a factory function that creates the opmode. It’s necessary to call PublishOpModes() to make the added modes visible to the driver station.
- Parameters:
factory – factory function
mode – robot mode
name – name of the operating mode
group – group of the operating mode
description – description of the operating mode
- addPeriodic(callback: collections.abc.Callable[[], None], period: wpimath.units.seconds) None
Add a callback to run at a specific period.
- Parameters:
callback – The callback to run.
period – The period at which to run the callback.
- clearOpModes() None
Clears all operating mode options and publishes an empty list to the driver station.
- disabledExit() None
Function called once when the robot exits disabled state.
- disabledInit() None
Function called once when the robot becomes disabled.
- disabledPeriodic() None
Function called periodically while the robot is disabled.
- driverStationConnected() None
Code that needs to know the DS state should go here.
Users should override this method for initialization that needs to occur after the DS is connected, such as needing the alliance information.
- endCompetition() None
Ends the main loop in StartCompetition().
- getLoopStartTime() wpimath.units.microseconds
Return the system clock time in microseconds for the start of the current periodic loop. This is in the same time base as Timer.getMonotonicTimeStamp(), but is stable through a loop. It is updated at the beginning of every periodic callback (including the normal periodic loop).
- Returns:
Robot running time in microseconds, as of the start of the current periodic function.
- nonePeriodic() None
Function called periodically anytime when no opmode is selected, including when the Driver Station is disconnected.
- publishOpModes() None
Publishes the operating mode options to the driver station.
- removeOpMode(mode: hal._wpiHal.RobotMode, name: str) None
Removes an operating mode option. It’s necessary to call PublishOpModes() to make the removed mode no longer visible to the driver station.
- Parameters:
mode – robot mode
name – name of the operating mode
- robotPeriodic() None
Function called periodically every loop, regardless of enabled state or OpMode selection.
- simulationInit() None
Function called once during robot initialization in simulation.
- simulationPeriodic() None
Function called periodically in simulation.
- startCompetition() None
Provide an alternate “main loop” via StartCompetition().