RobotController Battery Voltage Question

I’m trying to update our team’s programming library with the new version of WPILib. I’m trying to figure out how to make an instance of the RobotController class so I can access the non-static method getBatteryVoltage(). The constructor of that class is marked as private so I’m unable to create an instance in my own code. Here is a link to the source code for the RobotController class. Does anyone know how to use this method?

Thanks in advance!

Just call it as a static method:


double volts = RobotController.getBatteryVoltage();

Edit: Just noticed it’s not a static method - I’ll log an issue on GitHub.

1 Like

Seems like that’s an oversight and should be fixed. In the meanwhile, you can call the same function that it wraps:


double batteryVoltage = PowerJNI.getVinVoltage();

bdaroz, it is not a static method and cannot be called as one.

Thanks for the quick response! I’ll use the JNI as a workaround until it gets fixed.

I noticed that after I scanned the file quick and didn’t see the missing static declaration. Logged issue: (Java) RobotController.getBatteryVoltage() not static · Issue #870 · wpilibsuite/allwpilib · GitHub

You can also use PowerDistributionPanel.getVoltage() to do the same thing.

It still exists in the driverstation class as well.

A fix has been merged in: https://github.com/wpilibsuite/allwpilib/pull/869

It will be available in the next release. Thanks for pointing it out!