Robot Class

Purpose

The Robot class is a required class by FRC. It contains the methods robotInit() and a init and periodic method for the disabled, autonomous, teleop, and test states of the robot. All periodic methods must have the code Scheduler.getInstance().run(); as the first line, in order to run subsystems and commands. This class should have public static references to each subsystem of the robot and sensor classes you have made, so that they can be used in commands (Ex. Robot.driveTrain.move(0.5, 0.5)). The following descriptions for the class will be to instruct my teammates on our style of programming, other teams may vary in their usage of the class.

robotInit()

This method is what first runs when the robot starts up. The first line in this method should be RobotMap.init() so that all the sensors and motors to be used in subsystems can be instantiated. Following this line, sensors and subsystems should be instantiated and OI should be instantiated LAST. This is because OI makes references to commands which make references to subsystems and sensors that get instantiated in robotInit(), so OI must get instantiated after all those subsystems and sensors.

Autonomous

To run auto routines, you will need a command as a reference variable and to instantiate it, along with calling .start() on it, in autonomousInit(). My team generally places a potentiometer to use as a dial with option 0-10 to allow us to have multiple routines and to be able to pick them by the use of a physical dial. I will go over the code for this dial system in a seperate post. In autonomousInit() you can also set any subsystems or sensors to a desired starting states.

Teleop

Like autonomousInit(), teleopInit() can be used to set starting states of parts of the robot. The method should also be used to call .cancel() on the auto command if it is not null. We use teleopPeriodic() to print info to the smart dashboard via the SmartDashboard class. Subsystem movement methods and motors can be used here, but we do not call any of those methods here. Movement of the robot should be handled by joystick control and can be programmed through subsystem methods and commands.

Disabled

The only purpose we have had for the disabled state of the robot is to use the disabledPeriodic() method to put SmartDashboard values for sensors so that we can test them without enabling the robot.


© All Rights Reserved.