Voltage compensation is not enabled

I’m trying to set up voltage compensation for our shooter that has two falcons, with the following lines of code:


But when looking at the self test snapshot of the master, the output voltage is above the saturation, and we see this:
Am I doing something wrong?

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

if(flywheelMotor.getLastError() != ErrorCode.OK) System.out.println("[Talon] set enable compensation error " + flywheelMotor.getLastError());

System.out.println("[Talon] compensation set to " + flywheelMotor.isVoltageCompensationEnabled())
if(flywheelMotor.getLastError() != ErrorCode.OK) System.out.println("[Talon] compensation error " + flywheelMotor.getLastError());

Then do you know how it’s possible that it’s not working for me?

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).

To my surprise you were right - below is a screenshot of the RioLog:

What can cause this?

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).

OP can do this:
robust parameters

It has the code in its following post (# 5)

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.


:upside_down_face: :upside_down_face: :upside_down_face: :upside_down_face: Be sure to configure the saturation voltage before enabling this. :upside_down_face: :upside_down_face: :upside_down_face: :upside_down_face:


 * @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.

Thanks for checking - excellent follow through!

1 Like

So what to do now? I’m very confused :thinking:
Getting it to work will affect a lot how the shooting mechanism will change depending on the battery…

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.