Need help Programming Falcon 500 and its integrated encoder

Hi, my team bought some of Vex’s Falcon 500 motors at my bequest and now were having trouble programming them. I’m trying to use one of the motors to make the arm like contraption on our robot that lifts the “power cells” into the goal hole or whatever its called stay up while the robot’s in motion. Our robot is based off of 118’s Everybot and has the same ball grabbing mechanism. The motor I’m talking about is called “217-3351_REV2” on the CAD file for the everybot.

What I’m really looking for is some example code, in Java, of how to use the encoder on the robot with an Xbox Controller and using PWM. I’ve previously only used CIM motors with spark or TalonSRX motor controllers. I have the CTRE library installed on Visual Studio Code and I’ve looked through some of the examples on CTRE’s Github but I can’t any that use the xbox controller or the encoder. The arm on our robot is currently hooked up to a TalonSRX and a mini CIM using a versplanetary gearbox. I can get it to go up and down by pressing whatever button on the xbox controller but I have no idea how to do that on the Falcon.

I should mention that I’m the only person on my team with any programming knowledge, which isn’t much. So the simplest solution is the best one. If anybody has the time or patience I’d be willing to do a Zoom meeting to show you what we’re working with.

Thank you!

You would need to wire the Falcon 500 into the CAN bus instead of PWM to read the encoder value (and to also use its built in PID to hold position).

1 Like

I’ve never used CAN before, is it much different than using PWM? I know how to connect the wires for CAN but not how to program it.

The xbox controller and the falcon are two separate tasks. If you want to use pwm, your code will be identical to your current code. The xBox portion will stay the same.

For xbox, we use the following code…

In your file for using the xbox controller,

import edu.wpi.first.wpilibj.XboxController;
public class Robot extends TimedRobot {
private final XboxController m_controller = new XboxController(0);
public void teleopPeriodic() {
arm.lift(m_controller.getX(Hand.kRight)); //drive the arm with the right stick.
if (m_controller.getAButton()){
      arm.holdForScoring(); //when you press the A button, make the arm run some logic.

You will need to use CAN to use the encoder. The examples in the git show you how to do that. IN addition, if you want to just use the encoder, use the suggestion below that @Kaleb_Dodd posted.

CAN is a bit more involved, but it sounds like you are ready to explore it. I do suggest looking at their examples. You can use an xbox controller for their examples without modifying the code, but you will need to poke around and see which buttons are which (the driverstation and simulator show you though). Once you get their example working, you can implement the xbox logic.

Edit: I may have linked to an external encoder method.

1 Like

You would create the Talon FX object for example " TalonFX driveL1; "

then set it to be in CAN ID 0
this.driveL1 = new TalonFX(0); which CAN ID it is in will be determined by how you configure it using the Phoenix tuner.

To control the percent output of the motor this would work similar to a PWM speed controller driveL1.set(ControlMode.PercentOutput, output);

To read the encoder position

I would recommend reading and following this documentation Primer: CTRE CAN Devices — Phoenix documentation