-
Notifications
You must be signed in to change notification settings - Fork 0
TalonFXW
TalonFXW stands for TalonFX Wrapper. It is the BotDog's special talon class, which builds off WPI_TalonFX, the CTRE class to control CAN bus related Falcon 500s. Using this class simplifies some of the harder parts of programming a motor like converting units, applying gearing ratios, and fault analysis.
TalonFXW requires one instance beforehand to be created. That class is the TalonFXWConfiguration class. This class is used to represent two things: the gearing of the motor and the diameter of the object being used in inches. The "object" could refer to a shaft, a wheel, etc. If calculations are needed for both a shaft and a wheel connected, there is a method to just grab the falcon shaft rotations after gearing, which you can then multiply by (pi * the object you need's diameter.) A TalonFXWConfiguration class can be shared across multiple Talon's. For example, if you are using TalonFXW for a drivetrain motor, you can create a TalonFXWConfiguration for drivetrain motors, and then use that for every single one. There are two constructors for TalonFXWConfiguration:
-
TalonFXWConfiguration(double diameter): Which takes in only the diameter of the "object" that you want to measure. It assumes that the gearing is one, which is common place on things like shooters. -
TalonFXWConfiguration(double diameter, double gearing): Takes in both the diameter of the "object," and the gearing.
After you create your TalonFXWConfiguration, you can create a TalonFXW. A TalonFXW has four constructor types:
-
TalonFXW(int can_id, TalonFXWConfiguration configuration): The bare minimum required, only the CAN ID located on Phoenix Tuner and the configuration is required. -
TalonFXW(int can_id, String can_bus, TalonFXWConfiguration configuration): Similar to creating a talon, except on a specific CAN bus. The use case for all CAN bus related constructors have to do with using special CANivore CAN buses. For example, a swerve drive four module setup might all be on the CANivore to lower CAN percentage. The CAN bus on the roboRIO is actually just named "", for future reference. -
TalonFXW(int can_id, TalonFXWConfiguration configuration, SensorUnits sensor_units): Creates a new Talon with specified units that will automatically be converted to by the class itself. No math will have to be done by you with this type. The SensorUnits is an enum, of which the options are both listed in the code itself, with JavaDocs, and down below. -
TalonFXW(int can_id, String can_bus, TalonFXWConfiguration configuration, SensorUnits sensor_units): Creates a new Talon on a specified CAN bus with a specified config and SensorUnits.
There are three types of sensor units:
-
CTRE: Unit output is in CTRE units. There are no processing changes to the outputs of the motor. -
METRIC: Unit output is in Metric units. Units used are: Meters, kilograms, watt, newton-meter, etc... -
IMPERIAL: Unit output is in Imperial units. Units used are: Feet, pounds, horsepower, torque, etc...
Now that you have set up your TalonFXW, you can use a bunch of methods to get information that would take some math to solve. Here are some of the more important ones. There are some private methods, but those are used for BDManager's fault analysis system. It will automatically alert you on Shuffleboard if a Talon has a fault. Here are the accessible methods:
-
getShaftVelocity(): Returns how many rotations per 100ms the falcon shaft makes. -
getObjectRotationsPerSecond(): Returns how many rotations the object, through gearing, makes per second. -
getObjectRotationsPerMinute(): Returns how many rotations the object, through gearing, makes per minute. -
getObjectConvertedVelocity(): Returns the velocity of the object, through gearing, in selected SensorUnits / seconds. If it is CTRE, returns object rotations per second. -
getShaftRotations(): Returns how many rotations the falcon shaft has made. Note: This returns an absolute amount of rotations; you have to use subtraction to use it in a relative sense (beginning rotations vs ending rotations). -
getObjectTotalRotations(): Returns how many rotations the object has made. One again, it is absolute. -
getObjectTotalDistanceTraveled(): Returns how many rotations, through gearing, the object has made in selected SensorUnits. If it is CTRE, it returns the object's total rotations.