I don’t see anything wrong. We do it this way (below) which should be equivalent and we check for errors.
// get the factory defaults for some setting as defined by this Java API
TalonFXConfiguration configs = new TalonFXConfiguration();
var voltageCompensation = 11.;
configs.voltageCompSaturation = voltageCompensation;
…
//send the new config back to Talon
System.out.println("[Talon] set configs " + flywheelMotor.configAllSettings(configs));
// read them back from Talon
System.out.println("[Talon] get configs " + flywheelMotor.getAllConfigs(configs, TIMEOUT_MS));
// print them
System.out.println("[Talon] configuration:\n" + configs);
// turn on compensation
flywheelMotor.enableVoltageCompensation(true);
Sorry, I meant that maybe there is an error message that you aren’t seeing.
A code snippet loses all context and so much can go wrong it’s hard for commenters to describe them all or any of them. For example, there could be a set factory default command after the enable compensation command. Or another example, duplicate CAN ids. Enabling compensation is one of the rare methods with no timeout. Maybe it should have - I don’t know the design rationale. Sometimes good, valid statements are not executed (logic errors).
What is your can utilization at this time? You can receive this message if your bus is saturated. Maybe consider setting these levels after everything is initialized?
Or consider setting the value, until it actually persists (when you can read the value back).
I tried setting it 5 seconds after everything, and it didn’t help.
The saturation is configured properly.
Checking if it’s set is impossible because it’s a flag in the code, it doesn’t actually ask the motor if compensation is enabled.
Good catch! I need to read that baseMotorController class carefully as it appears things don’t work exactly as I assumed.
But regarding your error I suggest hovering over the enable method and you’ll see instructions that you didn’t follow and that might help you. I highlighted the good part
/**
* Enables voltage compensation. If enabled, voltage compensation works in
* all control modes.
*
Be sure to configure the saturation voltage before enabling this.
*
* @param handle
* handle of device.
* @param enable
* Enable state of voltage compensation.
**/
public static native void EnableVoltageCompensation(long handle, boolean enable);
Not impossible but ridiculously hard so I’ll say you are right. The Phoenix Tuner self-test snapshot reports the compensation status enabled T/F. We found a weakness in CTRE design of the Java API in that it assumes a value instead of checking it.
Seems like if the Driver Station PC Phoenix Tuner can get the value from the roboRIO, the roboRIO robot Java program certainly should be able to.
What has been done so far? Here are the simple but maybe tedious experiments:
make sure there aren’t two TalonFX with the same CAN id.
Check the CAN bus utilization and if high reduce it by changing all motor controller frame status rates to as slow as possible and still work for you. Certainly the follower doesn’t need much status information. TalonFX doc here
follow the instruction to set the saturation voltage first then enable its use.
change the order of configurations and find one that works.
try the way I said my team does with the configAllSettings
A complete example that I have used to help tune the PIDF controller for the flywheel is here
It has some PIDF stuff for my single bare Falcon 500 TalonFX that I was testing with. Copy whatever you want from the configFlywheel method. Add your Leader/Follower. The follower doesn’t use much configuration since it gets its voltage from the leader.
Maybe there is a wiring problem. You can reduce CAN load and check for wiring problems at the same time by disconnecting some of the CAN devices and see what happens.