Any Talon code examples for 2019?

Hello everyone!
I am a new coder for my team, and we are trying to get a TalonSRX to run through the RoboRIO using Java. However, we are having trouble getting it to run with our 2019 code. Can anyone give us a walkthrough of the simplest way to do this? We’d love to get at least one spinning a motor in any form by the end of the night.

1 Like

The first step you need to do is download the Phoenix Installer for Talons:

Next you must download the most recent firmware for the Talons which is also on the link above. (it should be version 4.1.1)

Next you have to import the library into VSCode. I assume you have downloaded VSCode and the WPILib/First Software for the year. I also assume that you have imaged your roborio and have the latest firmware on both the radio and the roborio.

Press “ctrl shift p” to open the command line. Type in WPILib: Manage External Libraries and a window should pop up. Click on Offline installed library and choose the CTRE Library.

Next, you must wire the CAN talons into the roborio. Let me know if you need help with this.

Once the Talons are hooked up to the roborio and to the motor, you can start with the coding.

The first step is to open the Phoenix Tuner which came with the CTRE Phoenix installer you previously downloaded. Once this is open go to the tab that says devices and click on the first talon. click the button that says load firmware, and choose to load firmware for all connected talons. (this may take a while). Next, make sure you take note of the Talon ID of each of the Talons. (I Usually temporarily label the talons with a labeled piece of masking tape that has the ID number on it.) You will need this number later for when you are programming.

Now it is time to import the correct classes into VSCode! The basic Class you need to run a motor with a talon is:

import com.ctre.phoenix.motorcontrol.can.TalonSRX;

then for each talon you must create an object for it. Here is an example:

TalonSRX motor1 = new TalonSRX(8);

The inputted value into the TalonSRX Constructor (8 in my example) is the Talon ID for the specific Talon you are trying to program.

Next, in order to use this Talon to move a motor, you must first program a button or joystick for it.

for this you would have to do:

import edu.wpi.first.wpilibj.Joystick;

Then create a Joystick Object:

Joystick exampleJoystick = new Joystick(0); 

(if it is your only joystick use 0)

then, you must power the motor. To do this you can do something like this (for my example I have the y axis of the joystick control the motor:


if you want to change the range of the speed, just multiply exampleJoystick.getY() by a scalar value such as:

motor1.set(examplejoystick.getY() * .75);

I hope this helps!

Let me know whether it works or if you have any questions!

1 Like

Okay, we’ll work with this for a bit and let you know how it goes. Thanks for the reply!

1 Like

Your welcome!

Start at the top and work your way down…

Driving with robot code…but you should really follow the entire guide, top-to-bottom.