Battery Status unofficial answer

https://vexforum.com/t/battery-status/30180/1

I am responding here because normal forum members do not have the ability to post in the official ROBOTC forum.



int batteryVoltage = nImmediateBatteryLevel;

task main()
{
while (true)
{
motor[motorOne] = batteryVoltage/100;
}
}

This is the original code. Current the value of the battery at the very beginning is saved to the variable batteryVoltage and then used throughout the while loop. I would suggest updating the variable in the while loop so that you can see the voltage update. Or you could just use the nImmediate variable in the while loop rather than using your own variable.



task main()
{
while (true)
{
motor[motorOne] = nImmediateBatteryLevel/100;
}
}

Lastly the battery level changes rather slowly so you might not see a change in motor speed for several minutes.

I’ve tried this code but my flywheel keeps on jerking. (I would assume it’s because the battery voltage updates constantly so the speed of the flywheel changes.)

Any idea on how to fix the jerking? (May not be caused by the battery voltage – it’s just my speculation)

If the battery voltage is in fact the issue, you should be able to fix it by using “nAvgBatteryLevel” which gives the average of the last 20 samples, instead of “nImmediateBatteryLevel” which gives only the last sample and may jump around. Hopefully that will fix it.

I’ve looked at this code for awhile. (ie, read it, and Tabor’s post, walked away, surfed the interwebs, came back and read it, surfed the interwebs).

I’m back and I guess the question I want to as is what do you WANT to do? I’m a little lost on what giving a motor a value related to battery voltage would do for you.

If you are looking for a way to monitor battery voltage on the robot, invest in three LEDs (green, yellow, red) from the VEX store.

Stuff them at the ends of extensions and mount them at high points of the robot. Then turn them on / off depending on the battery voltage.

OR – mount a servo with an indicator arm and send it the value of the battery. That way you can watch the “hand” move from “Full O’Clock” to “Empty O’Clock”

I’m happy to spew amazing RobotC code at you, but only if it’s going to do something useful.

[Mentors!! == Today, get your roboteers to move their hands/body/arms “clockwise” and / or “counterclockwise”. Report back on the “blank looks” you get back. Then try “swipe right” or “swipe left”. Welcome to the digital age]]

I don’t know about the original person who posted this, but I see some use for this.

I mainly want to implement this in my flywheel system. I am seeking to make motor power inversely proportional to battery voltage. This way the power levels for the shooter can be automatically configured without the need of an actual human programmer. The team can then practice without worrying that battery voltage will affect the power of the flywheel. This can also help in match situations if the battery voltage drops significantly

Proportional or PID control would be better to keep the flywheel at a certain speed, I’m not sure how well it would work with using the battery voltage as it is not directly linear to the motor speed, and doesn’t factor in load or friction of the flywheel.

Exactly! PID is the right tool and the right input is the wheel speed, not the battery voltage.