IterativeRobot

class wpilib.IterativeRobot[source]

Bases: wpilib.RobotBase

IterativeRobot implements a specific type of Robot Program framework, extending the RobotBase class.

The IterativeRobot class is intended to be subclassed by a user creating a robot program.

This class is intended to implement the “old style” default code, by providing the following functions which are called by the main loop, startCompetition(), at the appropriate times:

  • robotInit() – provide for initialization at robot power-on

init() functions – each of the following functions is called once when the appropriate mode is entered:

  • disabledInit() – called only when first disabled
  • autonomousInit() – called each and every time autonomous is entered from another mode
  • teleopInit() – called each and every time teleop is entered from another mode
  • testInit() – called each and every time test mode is entered from another mode

Periodic() functions – each of these functions is called iteratively at the appropriate periodic rate (aka the “slow loop”). The period of the iterative robot is synced to the driver station control packets, giving a periodic frequency of about 50Hz (50 times per second).

Constructor for RobotIterativeBase.

The constructor initializes the instance variables for the robot to indicate the status of initialization for disabled, autonomous, and teleop code.

Warning

If you override __init__ in your robot class, you must call the base class constructor. This must be used to ensure that the communications code starts.

autonomousInit()[source]

Initialization code for autonomous mode should go here.

Users should override this method for initialization code which will be called each time the robot enters autonomous mode.

autonomousPeriodic()[source]

Periodic code for autonomous mode should go here.

Users should override this method for code which will be called periodically at a regular rate while the robot is in autonomous mode.

disabledInit()[source]

Initialization code for disabled mode should go here.

Users should override this method for initialization code which will be called each time the robot enters disabled mode.

disabledPeriodic()[source]

Periodic code for disabled mode should go here.

Users should override this method for code which will be called periodically at a regular rate while the robot is in disabled mode.

logger = <logging.Logger object>

A python logging object that you can use to send messages to the log. It is recommended to use this instead of print statements.

nextPeriodReady()[source]

Determine if the appropriate next periodic function should be called. Call the periodic functions whenever a packet is received from the Driver Station, or about every 20ms.

Return type:bool
robotInit()[source]

Robot-wide initialization code should go here.

Users should override this method for default Robot-wide initialization which will be called when the robot is first powered on. It will be called exactly 1 time.

Note

It is simpler to override this function instead of defining a constructor for your robot class

startCompetition()[source]

Provide an alternate “main loop” via startCompetition().

teleopInit()[source]

Initialization code for teleop mode should go here.

Users should override this method for initialization code which will be called each time the robot enters teleop mode.

teleopPeriodic()[source]

Periodic code for teleop mode should go here.

Users should override this method for code which will be called periodically at a regular rate while the robot is in teleop mode.

testInit()[source]

Initialization code for test mode should go here.

Users should override this method for initialization code which will be called each time the robot enters test mode.

testPeriodic()[source]

Periodic code for test mode should go here.

Users should override this method for code which will be called periodically at a regular rate while the robot is in test mode.