Skip to main content

Motors and Drivetrains

This is where the training meets the robot hardware. We start with how a command reaches a motor: the Driver Station, the radio, the roboRIO, the CAN bus and the motor controllers, and the tools that set CAN IDs. We look at the difference between a motor and its motor controller, and at motors like the Kraken and Falcon 500 that have the controller built in. Then we explore the various motors and drivetrains commonly used in FRC robots. We will also write our first Java: reading a controller and driving a simulated differential drive robot through MWLib, the team's robot library, so we never program a motor directly.

Try it in the Swerve Kinematics Lab

Drive a simulated swerve robot with two joysticks and watch each module's angle and speed. Open the Swerve Kinematics Lab in a new tab ↗


Presentation​


Do this lesson in Scriptum

The exercises below are the Motors and Drivetrains 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: planning in pseudocode (plain-English steps) before writing code, calling methods, variables and the data types int, double, boolean and String, giving every variable a value on the line where you declare it, case sensitivity, the team's naming style (snake_case variables, trailing_underscore_ fields, SCREAMING_SNAKE_CASE constants) and operators: + - * / and the order they run in, whole-number division (7 / 2 is 3), the remainder %, and shortcuts like += and ++.

Building, deploying, and where main() went

Building checks your Java and turns it into a program the robot can run. A mistake, like a missing semicolon, stops the build, and the console names the file and line to fix. Deploying copies that built program onto the robot's roboRIO. In Scriptum, Start builds your code and runs it on the simulated robot, so there is nothing to deploy. On a real robot, Deploy Robot Code in WPILib VS Code (Shift+F5) builds and then deploys. See Build Tools.

The Java Basics lessons put your code inside main() in Main.java. A robot project still has a Main.java, but it has one line, RobotBase.startRobot(Robot::new), which hands your Robot to WPILib. A robot program never ends, so WPILib keeps calling your methods, like teleopPeriodic() every 20 ms. Scriptum hides Main.java because you never change it. Your code goes in Robot.java.

Exercises​

Plan it first

Before you type any Java, write the steps in plain English (pseudocode). For driving straight: read how far the left stick is pushed, flip it so up means forward, send that speed to both sides. Then turn each step into a line of code.

Motors​

  • Read the controller sticks from your own code
    • Declare double variables and store the stick values in them on the same line
    • Remember that pushing a stick forward gives a negative number

Drivetrains​

  • Tank drive: the left stick drives the left side and the right stick drives the right side
    • Drive forward, backward, and spin in place
  • Arcade drive: the left stick drives forward and backward (up/down) and turns (left/right)
    • Use arithmetic: left = forward + turn and right = forward - turn
  • Bonus: add a speed limit, and try squaring the stick values for finer control

Hardware​

  • RoboRio: Information about the roboRIO, the main control system for FRC robots.
  • Robot Radio: Details about the radio used for communication between the robot and driver station.
  • Motor Controllers: Overview of the motor controllers we use on our robots.

Hardware Interfacing​

  • CAN: Overview of the CAN communication protocol used for motor controllers and sensors.
  • Hardware Configurators: Guide on how to configure hardware components in the FRC ecosystem.

Software​

Software Tools​

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