Skip to main content

Drive Math and Methods

In this module, we will cover the concept of methods in programming and how to implement them in the context of FRC robot development. Methods are reusable blocks of code that perform specific tasks, allowing for modular and organized programming.


Presentation​


Do this lesson in Scriptum

The exercises below are the Drive Math and Methods 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: writing methods (parameters and return values), arrays, for loops, and the % operator.

Exercises​

Methods​

  • Write methods that turn encoder inputs into usable outputs
    • Two of them, linearSpeed and angularSpeed, you write from scratch, signature and all
    • translation position in m: DriveMath.radiansToMeters(wheel_radians, wheel_radius_meters) is wheel radians times wheel radius
    • translation speed in m/s
    • rotation speed in rad/s
  • Write a method that averages an array of numbers using a for loop
    • Use it to smooth the robot's speed over the last 5 readings
  • Write methods to set the speed of the drive motors
    • setting the left side only
    • setting the right side only
    • a method that performs the math of arcade drive and sets the sides (using the methods above)

The IO model​

  • Read how the library calls readInputs, writeOutputs and logData every loop, and find those three steps in the drivetrain

Software​

  • Methods: A detailed explanation of methods in programming, including how to create and use them effectively.
  • Arrays: Storing a numbered list of values.
  • Loops: Repeating code with for loops.

Hardware​

  • IMU: Guide on using Inertial Measurement Units (IMUs) for robot orientation and movement tracking.

Software Tools​

  • VSCode: Our primary Integrated Development Environment (IDE) for programming.
  • Driver Station: Software used to control and monitor the robot during competitions.
  • Elastic: Tool for logging and visualizing robot data.