-
Notifications
You must be signed in to change notification settings - Fork 2
RLD 3: REV
REV is a popular vendor that makes lots of parts for FRC. In addition to mechanical parts, they manufacture electronics, including motors and motor controllers. The REV library allows us to communicate with, configure, and control these motor controllers (called SparkMaxs) through robot code.
To include REVLib in a file, use #include <rev/
, followed by the header file that contains the part of the library that you wish to use.
REV's SparkMax is a motor controller, which basically means it controls how much power to provide to the motor. In addition, it takes encoder (sensor) values from the motor and sends them to the RoboRio. This allows us to see the speed, position, temperature, etc. of the motor.
To use SparkMaxs in your code, make sure to use #include <rev/CANSparkMax.h>
Everything to do with REV is in the "rev::" namespace.
To make a SparkMax variable (instance of the rev::CANSparkMax class), use the constructor.
The constructor takes in an int
for the CAN ID of the SparkMax (this is the "address" of the motor controller on the robot's network), and then a MotorType
to know if the motor is brushed or brushless (two different motor technology; most motors are brushless nowadays).
The easiest way to figure out something like this by yourself is to simply hover over things in VSCode (or press "ctrl" + "t") because it will give suggestions from the REVLib documentation.
rev::CANSparkMaxLowLevel::MotorType
may look scary, but it is actually very easy to figure out. You can simply paste that from the constructors function definition (this appears when you start typing rev::CANSparkMax spark_max = rev::CANSparkMax()
and hover your cursor inside the parentheses), and after that you can press "ctrl" + "t" to see what options are given (in this case, kBrushed and kBrushless). This happens a lot when using vendor libraries like REV and CTRE.
Here's a GIF for demonstration
This kind of information can also be found on the REVLib API docs
rev::CANSparkMax upper = rev::CANSparkMax(6, rev::CANSparkMaxLowLevel::MotorType::kBrushed);
rev::CANSparkMax upper{8, rev::CANSparkMaxLowLevel::MotorType::kBrushless};
WIP
The simplest way to actually run a motor hooked up to a SparkMax is using the .Set() function. This is a WPILib function that is implemented across all motor controllers.
The idea is very simple: the function takes in an int
value between -1
and 1
, with -1
being -100% speed and 1
being 100% speed.
WIP
Just like WPILib, REV has 2 libraries.
-
The main documentation is a very detailed resource explaining SparkMaxs and utilizing them with REV Client (a GUI app for tuning/testing REV stuff), but doesn't really go into using SparkMaxs in code.
-
REV also has API documentation that you can access in WPILib by hovering over things from REV's library, such as function arguments. This is great to see what each function does, how to use the constructors, etc.