When my JD decides that his battery level is low, he lurches forward from a standing position and does a spectacular faceplant on my desk or floor!
To prevent the poor guy cracking his face, I was hoping to script an early warning system that would advise me when he was approaching critical level so I could at least lay him down flat first.
If I recall correctly, the battery warning cuts in at around 6.6 volts so I wrote this small code snippet which runs after connection to alert me when the voltage dipped below 7 volts.
if ($batteryLevel < 7)
ControlCommand("Soundboard v4", Track_12)
sleep( 60000 )
Track 12 is an audio file that advises 'Energy Cell Exhausted' (I know many of you will guess where that came from ).
Whilst the script works, it is not reliably firing off before JD complains his battery level is low and does his faceplant thing.
Can anyone suggest a better method of achieving an early warning alert?
Upgrade to ARC Pro
Get access to the latest features and updates with ARC Early Access edition. You'll have everything that's needed to unleash your robot's potential!
The reason your script is inaccurate is because, based on the situation, the servos moving can drag the battery voltage down fast. Because of this, you need to monitor the voltage more rapidly. I would recommend between 5000 and 10000 milliseconds. This should catch him before the low battery warning.
I would also suggest you experiment with adding a command to stop the currently playing action, and go to a sitting position. This may not always work and will get him off balance, but it is an idea.
The battery monitor uses a custom complimentary filter to remove false positives. You could write that all as en ezscript, but the sample rate would require a great deal of bandwidth to reproduce the functionality. A complimentary filter with a lengthy delay will not be effective. However you could at least check the voltage 3-4 consecutive times before assuming the voltage is low.
The following modified code seems to work relatively well, and I have followed both of your suggestions. Now JD samples the voltage every 10 seconds, and averages the voltage over the last 3 samples. When he detects the average voltage has dropped below 7.05 volts, he announces a warning, stops any action he is doing and sits down (provided he is not already sitting). Whilst the voltage remains below the threshhold he will repeat his warning message every 30 seconds (10 seconds was wayyy too frequent).
This seems to give sufficient time for an early warning before the EZ-B battery saver kicks in at around 6.98 volts. That being said, I am still tinkering with the threshhold to ensure he's not complaining too early, but still prrior to faceplant-time.
I've included the code below in case it is of benefit to anyone else, although it is still a fairly basic script. I have commented the code extensively to help anyone new to scripting to utilise it.