-
Notifications
You must be signed in to change notification settings - Fork 0
Introduction to FRC Software
There are many different structures when it comes to creating a program for a FRC robot. One of the structures that is supported by WPILib is Command Based. Our team uses Command Based programming for all our robots.
In Command Based programming, there are two main types of classes: subsystems and commands. There are also different types of classes such as Robot class, RobotContainer class, and OI class.
Subsystems are what defines the the capabilities of each mechanism on the robot. Some examples are intakes, ball shooter, and drive train
Commands are the operation of the robot, utilizing the capabilities that are in the subsystems. An example is: If your robot code has a subsystem for a ball shooter, the program would have a command for shooting the balls called Shoot that shoot the game piece.
Subsystems have methods where you can declare the hardware that will be used by the commands i.e Motors, encoders, pneumatic or other sensors. Ultimately, these methods are then used to control various mechanism on the robot. If the robot has a climbing mechanism, you will need to create a method inside the subsystem file. An example method name is climb. This would be recognized in the code as public void(). Inside of public void(), you put the code that makes the robot climb. The subsystems should not include actions that happen over time i.e raising an elevator. Those happen in the command.
Commands use many methods to define a robot's action. When a programmer creates a command or looks at the example command given, they will see that there are about 4 methods. They are:
- initialized(): This is called before the command runs for the first time.
- execute(): This method is the code that has the operations to complete a task. It is basically where the logic goes.
- isFinished(): This tells if the action is done or not. After the code in execute() runs, it goes to the isFinished() method to see if the action is completed. It returns true when finished and false when not. If the action is completed and isFinished() returns true, it moves to end(). If the action is not completed, it continue until it is done.
- end(): This has the code for what the robot should do after isFinished() returns true. This method is also called when the command is interrupted.
In command based under the robot package, you are given 4 files called RobotContainer,Constants,Robot, and Main.
However Main should not be changed and should be left alone.
The OI (Operator Interface) is a class where you declare and get information from other operator interface devices such as joystick, xbox controllers, and wii remotes.
OI was changed in WPILib's 2020 update. However we create a new file for OI instead, which is why the file is still there in our 2020 code.
Constants was called RobotMap in years previous to 2020, which is why in later code there is a file called RobotMap. While the name is different, the purpose is the same. Constants sets up mapping for device ports and is a good place to declare constant variables. The team uses it for physical wiring of the robot. We use the Constants file to set up motor controllers and buttons on the control panel.
This is where a lot of the robot code is declared. The robot's subsystems and commands are defined in RobotContainer, along with OI devices, and commands, and mapping buttons to commands.
Robot runs the control of when commands are run and it will always run first. It also stores the information from Subsystems and in the OI. It also sets up the robot for each part of the game (Autonomous, and Teleop) as well as Enable, Disable, and Test.
- WPILib API: WPILib JavaDocs
- Overview of WPILib (Note this was last updated in 2017 so some information may be out of date): FRC Java Programing.pdf
- Java API: Java SE 8 JavaDocs
- Java Basics: Codecademy
If you have any questions about anything feel free to ask questions in the #software channel on Slack or message Adriana (a programming mentor/alum) on Slack