Finding battery voltage?

hi all. last year team 3044 made a robot that used an arm attached to a window motor. i assisted with the autonomus code, and the issue we had was that when the battery voltage went down, the arm moved less. (and of course we had not other feedback control sensor) so we attemped to use the voltage to change the power outputed to the arm durring autonomus. we failed. we had the code, exept we could not get a voltage value as an int or any other value. we were using labview last year, but now we have switched to java. we have the voltage outputed to the driver station as it is. i think it may be of use this year.

can anyone help? thank you all in advance :slight_smile:

What you are attempting is called an open-loop compensation: Measure everything that affects the result, and find a function that (hopefully) compensates for them. This is inherently difficult and prone to error - what if there is something else that also affects your result that you aren’t measuring?

Put a sensor on what you are trying to control and close the loop. A potentiometer will likely serve your purpose well.

we attempted this with the gyro, but we found our algorithum to work better when the gyro received static… (it was unplugged) but is there a way for the voltage to be a value that java can interperate?

Although I think you would be far better off with a closed loop control as Eric said, I took a quick peak in the driverstation code (I would like to read it so I can give myself a more obvious warning when the battery is dying and I can’t think of why things stop working), and found something that would most likely work:


import edu.wpi.first.wpilibj.DriverStation;

...

DrivetStation DS = DriverStation.getInstance();

...

double voltage = DS.getBatteryVoltage();

It is important that the CRIO has the proper jumper to read the voltage; if you see voltage on your dashboard, this should work. I have not tested it, and I don’t know what sort of value it returns, but I will most likely look into it tomorrow.

I question why the battery was low enough to make the arm much slower; how long do you run the robot before putting a charged battery in? We swap after the voltage drops below 12v (if we remember :P).

thank you so much. i am going to check it right now. the arm is slowed just enough to make a difference. we had to get the arm completely vertical, and a slight difference in battery changes that slightly… unfortunatly it was unrepeatable due to minute changes.

thanks again! :slight_smile: