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 each time a new packet is received from the driver station and the robot is in autonomous mode.

Packets are received approximately every 20ms. Fixed loop timing is not guaranteed due to network timing variability and the function may not be called at all if the Driver Station is disconnected. For most use cases the variable timing will not be an issue. If your code does require guaranteed fixed periodic timing, consider using Notifier or PIDController instead.

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 each time a new packet is received from the driver station and the robot is in disabled mode.

Packets are received approximately every 20ms. Fixed loop timing is not guaranteed due to network timing variability and the function may not be called at all if the Driver Station is disconnected. For most use cases the variable timing will not be an issue. If your code does require guaranteed fixed periodic timing, consider using Notifier or PIDController instead.

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.

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

robotPeriodic()[source]

Periodic code for all robot modes should go here.

This function is called each time a new packet is received from the driver station.

Packets are received approximately every 20ms. Fixed loop timing is not guaranteed due to network timing variability and the function may not be called at all if the Driver Station is disconnected. For most use cases the variable timing will not be an issue. If your code does require guaranteed fixed periodic timing, consider using Notifier or PIDController instead.

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 each time a new packet is received from the driver station and the robot is in teleop mode.

Packets are received approximately every 20ms. Fixed loop timing is not guaranteed due to network timing variability and the function may not be called at all if the Driver Station is disconnected. For most use cases the variable timing will not be an issue. If your code does require guaranteed fixed periodic timing, consider using Notifier or PIDController instead.

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 each time a new packet is received from the driver station and the robot is in test mode.

Packets are received approximately every 20ms. Fixed loop timing is not guaranteed due to network timing variability and the function may not be called at all if the Driver Station is disconnected. For most use cases the variable timing will not be an issue. If your code does require guaranteed fixed periodic timing, consider using Notifier or PIDController instead.