How to program CAN motors

I successfully programmed my team’s robot last year, but this year we need more motors, and I have come to a road block: I’m not sure how to program a motor connected to CAN. I believe I have imported the correct libraries for it and all, but I am not sure how to define the controller within the code, as I can’t simply define the port on the Roborio like with a PWM connection. We program the robot in Java, and are trying to use VictorSPX. If anyone could give some suggestions on how to accomplish this, that would be greatly appreciated, we leave for competition tomorrow.

*For clarification, I know how to assign controls to the joystick/xbox controller, but I am not sure how to simply define the motor controller within the code.

well what are ya wanting to do with the motors are you using encoders and pids or are ya just settings a percent?

also for the most part you would cust import the victor " import com.ctre.phoenix.motorcontrol.can.VictorSPX; "

public VictorSpx “name of motor” = new Victorspx(“can id”);

Just setting a percent, nothing fancy

" import com.ctre.phoenix.motorcontrol.can.VictorSPX; "

public VictorSpx “name of motor” = new Victorspx(“can id”);

“name of motor”.set(Victorspxcontrolmode.percentoutput, "percent value);

1 Like

Adding to this, the “can id” needs to be set in the VictorSPX using the Phoenix Tuner application. This is the definitive getting started guide for CTRE devices: Bring Up: Talon FX/SRX and Victor SPX — Phoenix documentation

1 Like

You probably want to use WPI_VictorSPX.

2 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.