Sparkmax to Falcon 500 powered by Talon FX

Hello, my team recently changed out our swerve motors from Sparkmax (cuz they’re a pain to deal with) to Falcon 500 powered by Talon Fx, but I don’t know how to translate the sparkmax swerve code over to talon fx. I’m not very experienced in programming so help would be very much appreciated.

//Sparkmax based code
CANSparkMax maxFLswerve = new CANSparkMax(Constants.maxFLswerve, MotorType.kBrushless);
CANSparkMax maxFRswerve = new CANSparkMax(Constants.maxFRswerve, MotorType.kBrushless);
CANSparkMax maxBLswerve = new CANSparkMax(Constants.maxBLswerve, MotorType.kBrushless);
CANSparkMax maxBRswerve = new CANSparkMax(Constants.maxBRswerve, MotorType.kBrushless);

public SparkMaxPIDController maxFLswervePID = maxFLswerve.getPIDController();
public RelativeEncoder maxFLswerveEncoder = maxFLswerve.getEncoder();
public SparkMaxPIDController maxFLswervePID = new SparkMaxPIDController(maxFLswerve);
public RelativeEncoder maxFLswerveEncoder = new RelativeEncoder(maxFLswerve);

public SparkMaxPIDController maxFRswervePID = maxFRswerve.getPIDController();
public RelativeEncoder maxFRswerveEncoder = maxFRswerve.getEncoder();
public SparkMaxPIDController maxFRswervePID = new SparkMaxPIDController(maxFRswerve);
public RelativeEncoder maxFRswerveEncoder = new RelativeEncoder(maxFRswerve);

public SparkMaxPIDController maxBLswervePID = maxBLswerve.getPIDController();
public RelativeEncoder maxBLswerveEncoder = maxBLswerve.getEncoder();

public SparkMaxPIDController maxBLswervePID = new SparkMaxPIDController(maxBLswerve);
public RelativeEncoder maxBLswerveEncoder = new RelativeEncoder(maxBLswerve);

public SparkMaxPIDController maxBRswervePID = maxBRswerve.getPIDController();
public RelativeEncoder maxBRswerveEncoder = maxBRswerve.getEncoder();
public SparkMaxPIDController maxBRswervePID = new SparkMaxPIDController(maxBRswerve);
public RelativeEncoder maxBRswerveEncoder = new RelativeEncoder(maxBRswerve);

Ok. What question are you trying to get an answer to?

Edit: ok thanks but I’m afraid I can’t help much with this. Dont know code that well
Good luck!

If you’re looking for code migration help, rev’s guide pretty bidirectional for general function calls.

3 Likes

do you know what the equivalent of the sparkmax getPIDController or getEncoder would be for ctre phoenix?

Ultimately, someone is going to have to become familiar with the code. This is a good time to start – well before build season. In addition to the REV guide linked above, the doc for TalonFX’s Java API is here.

There isn’t a mechanical translation, you will have to go a little deeper. You will also have to retune your PID constants, etc. Much depends on how involved your previous code was, but you should also plan on going through bringup and debug with the new/edited code.

1 Like

You don’t need it you can just use the motor controller object to interface with the encoder

1 Like

Steal from the best? I wish! Here’s my team’s code but you might get frightened and run away. Poke around and it might be helpful to you or not. The rest of the code is nearby.

The basis of the drivetrain is the WPILib SwerveBot example. We tweaked a couple of weaknesses in that. I think we also changed from radians to degrees. We started to change from meters but ran out of time. We also started to change from WPILib PID control to TalonFX PID control but ran out of time. If you stick with the WPILib PID you probably don’t have to change the PID constants to get good control (we did a rough tuning on a 50 pound chassis and ran out of time to tune on the 150 pound robot and it worked fine).

We use CANcoder for the direction of the steering mechanism. We use SDS MK4 modules. Pigeon gyro.

For reading sensors we wrap those gets in a more neutrally named method so it’s a little easier to find and replace them.

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