VictorSPX Motors (DEPRECATED, THIS IS FOR TANK DRIVE, SEE SWERVE DRIVE INSTEAD) - frc-7603/VespaRobotics2024-25 GitHub Wiki
About
In our robot, we use only the VictorSPX motor controller to control the motors, which is used primarily for the wheels. Knowledge about the hardware itself is not expressly required for programming the motors and controlling them.
This wiki page is a WIP!
Information here may be a bit experimental (except Phoenix 5 speed), so be cautious when using information from this page. I AM NOT RESPONSIBLE FOR THE ROBOT IMPLODING.
Defining a motor (Phoenix 5, may be deprecated)
Import these classes first from the com.ctre.phoenix.motorcontrol package (make sure you have imported both the Phoenix5 and Phoenix6 libraries):
import com.ctre.phoenix.motorcontrol.ControlMode;
import com.ctre.phoenix.motorcontrol.can.VictorSPX;
When defining a motor (in Java), you must instantiate a VictorSPX class, with the device number. The two left motors are 1 and 2, while the two right motors are 3 and 4.
VictorSPX motor = new VictorSPX(int device_number);
You will usually have to instantiate 4 VictorSPX objects, 2 for left and 2 for right motors. Name your variables accordingly, and make them accessible to all methods within the "Robot" class (eg. Use private keyword, and static keyboard so you don't have to instantiate the Robot class as well).
Defining a motor (No Phoenix 5, UNTESTED)
Import the PWMVictorSPX class from the edu.wpi.first.wpilibj.motorcontrol.PWMVictorSPX package:
import edu.wpi.first.wpilibj.motorcontrol.PWMVictorSPX;
The instructions are basically the same as Phoenix 5, except with the PWMVictorSPX class and the channel number instead of the device number.
The channels appear to be 1, 2, 3, and 4 again with the same configurations as the device numbers. A channel number is just the direct connection of the motors to the RoboRIO to specific ports called "channels".
PWMVictorSPX motor = new PWMVictorSPX(int channelnumber);
Speed control
Both classes have a .set() method. The .set() method can set the speed as a percent, from -1 (reverse, 100%) to 1 (forward, 100%). 0 will stop the motor.
Phoenix 5
With Phoenix 5's version, .set() accepts 2 arguments: The control mode and the percent. You usually want to use ControlMode.PercentOutput.
motor.set(ControlMode.PercentOutput, double speed);
You can also get the current speed by using the .getMotorOutputPercent() method, and it is returned as a double.
double currentspeed = motor.getMotorOutputPercent();
PWMVictorSPX
With the PWMVictorSPX class, .set() simply accepts it directly.
motor.set(speed);
You can also get the current speed by using the .get() method, and it is returned as a double.
double currentspeed = motor.get();
IMPORTANT INFORMATION
With both, you must make the left/right speed negative of the other speed. This is because without it, the robot can implode on itself. Usually, you make the right motor speed inverse of the left motor speed.
Other Useful Methods (Phoenix 5, EXPERIMENTAL, UNTESTED)
Inversion
motor.setInverted(boolean invertedornot);
Should invert the direction of the motor (if inverted, a positive value should make it go backwards, and a negative value should make it go forwards).
boolean invertedstate = motor.getInverted();
Gets the state of the inversion.
Have the same output as another motor
motor.follow(othermotor);
Make the motor have the same output (speed) as another motor. Useful for synchronizing left and right motors.
Other Useful Methods (PWMVictorSPX, EXPERIMENTAL, UNTESTED)
Inversion
motor.setInverted(boolean invertedornot);
Should invert the direction of the motor (if inverted, a positive value should make it go backwards, and a negative value should make it go forwards).
boolean invertedstate = motor.getInverted();
Gets the state of the inversion.
Have the same output as another motor
motor.addFollower(othermotor);
Make the motor have the same output (speed) as another motor. Useful for synchronizing left and right motors.
Disable motor (VERY EXPERIMENTAL AND UNTESTED)
motor.disable();
Disables the motor. It is currently unknown how to reenable it, as no method was defined in the official documentation. .set() could potentially reenable it, but testing is required.
Stop motor (VERY EXPERIMENTAL AND UNTESTED)
motor.stop();
Stops the motor. Could potentially be started again by using .set().
For more info
Product Info
https://store.ctr-electronics.com/products/victor-spx