Hi,
I’m working with a wireless charger and I need to reset the battery percentage to 100% whenever the batteries are full again. I asked on Gitter and I think the least intrusive approach would be to send a mavlink command based on some logic on my companion computer. This is what I came out with, I tested with SITL and it seems to work, but I would appreciate some feedback since I don’t usually fly with modified firmware.
Inside libraries/AP_BattMonitor/AP_BattMonitor.h
/// reset_current_total_mah - resets total current drawn since start-up (= resets battery percentage)
void reset_current_total_mah(uint8_t instance);
void reset_current_total_mah() { reset_current_total_mah(AP_BATT_PRIMARY_INSTANCE); }
Inside libraries/AP_BattMonitor/AP_BattMonitor.cpp
/// reset_current_total_mah - resets total current drawn since start-up (= resets battery percentage)
void AP_BattMonitor::reset_current_total_mah(uint8_t instance) {
_BattMonitor_STATE(instance).current_total_mah = 0;
}
Inside ArduCopter/GCS_Mavlink.cpp
case MAV_CMD_RESET_BATTERY_PCT:
copter.battery.reset_current_total_mah();
break;
And of course I added the message to common.xml:
<entry value="301" name="MAV_CMD_RESET_BATTERY_PCT">
<description>resets battery percentage to 100%</description>
<param index="1">first_item: the first mission item to run</param>
<param index="2">last_item: the last mission item to run (after this item is run, the mission ends)</param>
</entry>
Thanks.