Gray Matter
WorkshopMotor Setup & CAN IDs
WPILib 2027 is still in alpha: these pages change as the APIs settle.
LESSON 05

Motor Setup & CAN IDs

Now set up each device. Every device needs its own CAN ID and the correct configuration, so the software matches the hardware. You prove it by applying a volt or two and checking that the mechanism moves the correct direction. Get this wrong and tuning in the next lessons is impossible.

14 minutes
You’ll need
  • The mechanism assembled and powered.
  • Phoenix Tuner X connected to the CANivore over USB, firmware current.
  • No robot program running. Tuner X owns the bus here.

What mechanism are you working on?

The lesson below is written for the one you pick. Switch back any time to read it for the other.

Assign every CAN ID

Factory Default resets inversion and every other setting, but it does not reset the CAN ID. If two devices flash together on a blink, they share an ID. Change one to any unused ID, give the other its number from the table, then come back to the first.

DeviceCAN IDDevice label
Arm TalonFX31Arm motor
Arm CANcoder32Arm encoder
Flywheel TalonFX21Flywheel motor
Screenshot highlighting the Factory Default button in the device configuration screen.
In Tuner X, open the device, then the three dots, then Factory Default.
  1. Open a device, click the three dots, then Factory Default.
  2. Press Clear Faults. This clears whatever the last session left behind.
  3. Click the Blink button on the left panel. The device that flashes is the one you are about to edit.
  4. Give it the ID from the table and a name that says which mechanism it drives.
  5. Repeat until every device has its own ID and Tuner X reports no duplicates.
Screenshot of the Self Test tab with the Clear Faults button circled.
Clear Faults is on the Self Test tab, next to Refresh.

A config change does nothing until you press Apply, the arrow icon above the config list. Its tooltip says "Apply and flash configs". That saves the configs onto the device. It does not touch the firmware.

Screenshot of the config panel with the Apply arrow icon circled and its tooltip showing.
Apply is the arrow icon above the config list.

Arm motor direction

Get the motor right first, by hand, before the encoder or any power. Factory Default reset its inversion, so you set it here.

  1. Select the arm TalonFX on 31 and plot its position.
  2. With the motor facing you, turn the arm counterclockwise by hand.
  3. The motor's position must go up. If it goes down, change Inverted in the Motor Output config, press Apply, and repeat the hand test.

A motor and an encoder linked while they count in opposite directions break every lesson after this one. Do not move on until both go up together.

Arm encoder direction and zero

With the motor right, check the encoder the same way. It is what every downstream lesson uses.

  1. Open the CANcoder device in Tuner X and plot the position.
  2. With the motor facing you, turn the arm counterclockwise by hand.
  3. The CANcoder position must increase. If it decreases, flip the sensor direction, apply, and repeat the hand test.
  4. Put the arm to 0, based on the Unit Circle, then zero the CANcoder position.
  5. Turn it 90 degrees counterclockwise. Expect about 0.25 rotations. A full turn reads 1.0.

Positions are measured in rotations, not degrees. One full turn is 1.0. Counterclockwise with the motor facing you is positive, and every position target from here to Motion Magic is written that way. Every photo on this site is taken from that side, so your directions match ours.

Unit circle showing the same angles written as degrees and as decimal rotations, with counterclockwise as the positive direction
Arrow showing the counterclockwise rotation direction with the motor facing you

Choose the reference with whoever builds the arm, and mark it if you can. If a CANcoder is ever replaced, redo this section on the new one.

Direction under power

This is the first time anything moves under power. Voltage Out sends a fixed voltage and nothing else: no target and no stopping at the end of travel.

You have checked the motor, the encoder and the link by hand. Now prove it under power: positive voltage has to turn the arm counterclockwise.

A flywheel has no sensor to agree with, so nothing on the bench decides which way positive goes. You decide, and then the motor has to match. The rule on this robot is that positive runs a game piece the way it is meant to travel, so on the shooter positive shoots. Seen from the motor side, that is clockwise. The motor is the only thing allowed to change from here.

Watch out

Before you enable anything

Make sure the mechanism is clear of obstacles. Blink the device first: voltage goes to a CAN ID, not to the one you meant. Start at 1 volt and enable for about a second at a time. A Voltage Out request runs until you stop it.

  1. Select the arm TalonFX on 31flywheel TalonFX on 21 and set Control Mode to VoltageOut, the same request your code sends in Mechanisms.
  2. Enter 1 V under Output (Volts), click DISABLED to enable the device, then disable after about a second. Watch the mechanism.
  3. With the motor facing you, the arm should move counterclockwise, and the motor's position should go up.
  4. The wheel should spin the way it shoots, which is clockwise seen from the motor side.
Screenshot of the Control tab with the DISABLED button, the VoltageOut control mode and the Output (Volts) field circled.
Control tab: VoltageOut, the Output (Volts) field, and the DISABLED button that enables the device.

If it turns clockwise, stop. Do not fix it here. One of the hand tests above was skipped or not applied, so go back and redo them.

If positive voltage turns it the other way, the motor is configured wrong. Fix Inverted in the motor's Motor Output config, apply, and test again.

Once 1 V is right, repeat at 3 V. Only the speed should change. An arm that will not budge at 1 V is usually fighting friction or gravity rather than bad wiring. Climb in single volts until it creeps, then stop. A wheel takes a moment to come up and coasts for a while after you disable, so give it time before you call the direction. You are checking which way it goes, not how fast.

The flywheel reads the motor's own sensor, so its positions and speeds are motor rotations. Setting Sensor To Mechanism Ratio in the Feedback configs to the gear reduction would make them, and the gains, read at the wheel. This course leaves it at 1 to keep things simple. If you do set it, set it before you tune, because it changes what every gain means. It is saved on the device, so Generate Code includes it.

Check your work

Power the bench down, bring it back up, and walk these checks in order.

Check

You should see

  • Blinking any ID flashes the device you expected.
  • A volt or two moves the mechanism, and disabling stops it.
  • Tuner X lists all devices on your mechanism, each with its own ID and a name.
  • The arm reference reads about zero, and a quarter turn reads 0.25.
  • Turning the arm counterclockwise by hand raises both the motor and the CANcoder readings, and positive voltage on TalonFX 31 drives it the same way.
  • Positive voltage on TalonFX 21 spins the wheel the way it shoots, clockwise from the motor side, and it spins down on its own once you disable.

PID tuning starts on the next page!

Check yourself

You blink one device from the Tuner X list and two devices on the bench flash together. What have you found?

With the motor facing you, you turn the arm counterclockwise by hand. What should CANcoder do?

What does setting the arm's zero do?

A CANcoder fails and somebody fits a new one. What has to happen?

The motor and encoder are linked, and at 1 volt the arm turns clockwise. What do you do?

At 1 volt the wheel spins counterclockwise, seen from the motor side. What do you change?

You enable at 1 volt for a second, and the wheel is still turning after you disable. What does that tell you?

Why blink the device before sending it any voltage?

Pick an answer for each.