Tutorial: Your First Canandgyro
This tutorial covers the complete setup of a Redux Canandgyro. By the end of this lesson, you will have a wired, configured, and programmed sensor reading robot heading.
Prerequisites
Section titled “Prerequisites”- A Redux Canandgyro
- A RoboRIO with a configured CAN bus
- A laptop with WPILib VSCode installed
- A basic FRC robot project
-
Basic Wiring
Connect the Canandgyro to your robot’s CAN bus.- CAN High: Yellow wire to the yellow terminal/pad.
- CAN Low: Green wire to the green terminal/pad.
- Power (12V): Red wire to a 12V source.
- Ground: Black wire to the corresponding ground port.
-
Install ReduxLib
Open your FRC project in VSCode.- Press
Ctrl+Shift+P. - Select WPILib: Manage Vendor Libraries.
- Choose Install new libraries (online).
- Paste the ReduxLib URL:
https://frcsdk.reduxrobotics.com/ReduxLib_2026.json
- Press
-
Configure the CAN ID
All Redux devices ship with CAN ID 0. We can give it a unique ID using the Alchemist or the web dashboard.- Deploy a basic robot project that includes
CanandEventLoop.getInstance();inrobotInit. - Open a web browser and navigate to
http://roborio-XXXX-frc.local:7244(replacing XXXX with your team number). - Find the device with ID 0, type
1into the CAN device ID box, and click Change ID.
- Deploy a basic robot project that includes
-
Write your first code
In yourRobot.javafile, let’s read the heading (yaw) of the gyro.import com.reduxrobotics.sensors.canandgyro.Canandgyro;public class Robot extends TimedRobot {// Create the sensor object with ID 1private final Canandgyro m_gyro = new Canandgyro(1);@Overridepublic void teleopPeriodic() {// Read the heading in rotations [-0.5, 0.5)double heading = m_gyro.getYaw();// Convert to degrees for easier readingdouble degrees = heading * 360.0;System.out.println("Robot Heading: " + degrees);}} -
Verify on the Dashboard
Deploy your code and open the RIOlog. You should see the heading value changing as you rotate the gyro. If you rotate it 360 degrees, it should return to near its starting value.
Next Steps
Section titled “Next Steps”Now that you have the basics working, explore the Programming Guide to learn about 3D rotations, acceleration data, and manual calibration.