Skip to main content

Objects and Odometry

In this module we will cover the basics of Object Oriented Programming: classes, objects and static methods. We will then use WPILib classes for controlling a differential drive robot, including kinematics and a pose estimator that tracks where the robot is. Finally, we will compare that estimate with the simulator's true position.


Presentation​


Do this lesson in Scriptum

The exercises below are the Objects and Odometry lesson in Scriptum. Open the lesson, start the simulated robot and follow its README. Each step is checked with the Verify button.

New Java in this lesson: classes and objects, new, import, static and abstract.

Exercises​

Classes​

  • Finish an abstract OI class
    • Add a static getter for forward (the left stick Y axis) with a deadband
    • Add a static getter for turn (the left stick X axis) with a deadband
  • Update your code to use the OI class methods and remove the XboxController from Robot.java

WPILib​

  • Use a DifferentialDriveKinematics object in the drive mechanism
    • Write a getChassisSpeeds method
    • Use it to get the ChassisSpeeds of the robot and compare it with your hand-written speeds
  • Write a getYaw method that works out the robot's heading from how far each side has driven
    • The heading in radians is (right meters - left meters) / track width (0.61 m)
    • Return it as a Rotation2d
  • Use a DifferentialDrivePoseEstimator object
    • Update it every loop and log the estimated pose
    • Use the x value from the estimated pose to drive 3 meters in autonomous

Simulation​

  • Drive the robot in simulation and watch the pose on the AdvantageScope 2D field
  • Compare your estimated pose with the simulator's true pose
    • Why do they drift apart? What would a real robot add to fix it?
  • Optional: try WPILib's DifferentialDrive arcadeDriveIK method and compare it with your own arcade math

Software​

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.