I’ve loaned out the bench supplies I had at home, and I haven’t been back to the lab, so we haven’t yet run a test identical to your simple monitoring code above. But we have some interesting results from experimenting further with the sample I provided.
First, the confirmation:
Using RobotC v4.5 and Master CPU firmware v4.25.
Now, the observation:
Running the debugger affects the “stability” of nImmediateBatteryLevel. The variable does not change (for us; clearly it does for you) while a debug session is active.
Detail:
We ran the code containing the “monitorPower” task shown above, this time leaving it running for about 8 minutes. We used debugger to stop the code and restart it, running it for several more minutes. These run times were much longer than any runs we’ve done in the past. We did this to have high confidence that we had drained the battery enough to indicate a change even given the 59 mv per bit “chunkiness”. During the entire time, the voltage written to the debugStream window never changed for the first battery. The second battery voltage jumped around considerably, but with an overall downward trend, as expected. (Since the motors were being switched on and off asynchronously to the power monitoring task, we fully expected to see a lot of volatility in the reported voltage.) The numbers shown in the debugStream output matched what was shown on the LCD screen as well. The first battery voltage never changed from 7.092000.
After those two long sessions, we used the debugger to stop the robot and power-cycled both the robot and the joystick. After the robot and joystick established communications, the robot resumed its cyclic dance.
Turn Left. Turn Right. Raise arm. Lower Arm. repeat.
And the values displayed on the LCD for the first battery actually changed.
Then, I plugged the “program” cable back in the joystick. The robot stopped for a second or so, then resumed the cyclic exercise. When it started moving again, the debugStream window refreshed and a number of updated lines flooded into the window. It looked like this:
>-- first battery is: 7.092000 Volts
>-- second battery is: 7.907407 Volts
>-- first battery is: 7.092000 Volts
>-- second battery is: 7.566667 Volts
>-- first battery is: 7.092000 Volts
>-- second battery is: 7.548148 Volts
>-- first battery is: 6.619000 Volts
>-- second battery is: 7.888889 Volts
>-- first battery is: 5.259000 Volts
>-- second battery is: 7.888889 Volts
>-- first battery is: 7.032000 Volts
>-- second battery is: 7.529630 Volts
>-- first battery is: 7.032000 Volts
>-- second battery is: 7.533333 Volts
>-- first battery is: 6.619000 Volts
>-- second battery is: 7.877778 Volts
>-- first battery is: 5.259000 Volts
>-- second battery is: 7.866667 Volts
>-- first battery is: 7.032000 Volts
>-- second battery is: 7.544445 Volts
>-- first battery is: 7.032000 Volts
>-- second battery is: 7.544445 Volts
>-- first battery is: 7.032000 Volts
>-- second battery is: 7.874074 Volts
The lines where the first battery voltage moved around were the ones that all loaded quickly, in under a second or so. Following that refresh of the buffered debugStream, the window would update every second, but the first battery voltage never changed from 7.032000. The first battery voltage reported on the LCD stayed stable as well.
We were able to replicate this every time we tried. Active debugging means the first battery voltage doesn’t change either in the debugStream window or on the LCD. Restart without running the debugger, and the output of the LCD changes as expected.
So, there are a couple of conclusions we have:
1.) Indications are we can trust the nImmediateBatteryLevel to reflect the recent reading of the battery voltage, subject to the 59mv per bit limitation. (It was clear you could. Now it’s clear we can.)
2.) Instantaneous voltage readings during motor loads vary greatly, as expected. So, either take a reading during a quiescent period, use the RobotC provided average variable, nAvgBatteryLevel, or perform your own filtering.
3.) The debugStream is buffered, and the buffer is updated even if a debug session is not running.
Further, there is an interesting implication:
Rather than living in the generated code, the programmatic scaffolding for debugger support is built in to the RobotC VM. Some parts of debugging (real or virtual interrupts to run the check for breakpoints, for instance) are only activated when debugging is active. This could lead to different behaviors and timings between debug vs non-debug runs. While the concept of having a debugger change timing is hardly novel, it often (even usually) is due to running code that was compiled for debug versus code that was not.
I’ll try to run the system with a bench supply if we have time to do so tomorrow.
Thanks,
KYPyro