Object Oriented Programming and WPILib
In this module we will cover the basics of Object Oriented Programming. This will include creating classes, methods, and using objects. We will then cover some of the WPILib classes used for controlling a differential drive robot, including kinematics and odometry. Finally, we will cover how to simulate a differential drive robot using WPILib's simulation tools.
Presentationβ
Exercisesβ
Classesβ
- Create an abstract OI class
- Add a getter for a joystick Y axis
- Add a getter for a joystick X axis
- Update your code to use the OI class methods and remove the XboxController from Robot.java
Objectsβ
- Create a Drivetrain Class
- Create the class in a new folder called βsubsystemsβ
- Move all content related to your drivetrain and its methods to the new class
- Your readInputs and writeOutputs should now be your primary methods
- Add a new method to reset wheel encoders
- Add a new helper method to convert from ticks to meters
- Create a Drivetrain Object in Robot
- Use it to call readInputs and writeOutputs in robotPeriodic
- Use it to call arcadeDrive in teleopPeriodic and autonomousPeriodic
- Use it to call getDistance in autonomous
WPILibβ
- Create a DifferentialDrive Object
- Use the arcadeDrive method to drive the robot in auto/tele
- Create a DifferentKinematics Object
- Write a getChassisSpeeds methods
- Use this object to get the ChassisSpeeds of the robot
- Create a DifferentialDrivePoseEstimator Object
- Publish the estimated pose to NetworkTables
- Use the x segment from the estimated pose for auto drive distance
Simulationβ
- Setup a DifferentialDrivetrainSim Object
- Add a Rotation2d based calculation for yaw in simulation
- Drive the robot in simulation using AdvantageScope!
Related Documentationβ
Softwareβ
- Classes and Objects: Overview of classes and objects in Java.
- WPILib: The main library used for programming FRC robots.
- Kinematics and the ChassisSpeeds Class: Overview of kinematics and how to use the ChassisSpeeds class in WPILib.
Software Toolsβ
-
VSCode: Our primary Integrated Development Environment (IDE) for programming.
-
Driver Station: Software used to control and monitor the robot during competitions.
-
Advantage Scope: Tool for analyzing robot performance data.
-
Elastic: Tool for logging and visualizing robot data.