void loop() { static uint8_t counter; // counter to slow output to the user uint32_t now = hal.scheduler->millis(); // call battery monitor at 10hz if((now - timer) > 100) { // update voltage and current readings battery_mon.read(); // reset timer timer = now; // increment counter counter++; } // display output at 1hz if (counter >= 10) { counter = 0; hal.console->printf("\nVoltage: %.2f \tCurrent: %.2f \tTotCurr:%.2f", battery_mon.voltage(), battery_mon.current_amps(), battery_mon.current_total_mah()); } // delay 1ms hal.scheduler->delay(1); }
void setup() { hal.console->println("Battery monitor library test"); // set battery monitor to smbus battery_mon.set_monitoring(0, AP_BattMonitor::BattMonitor_TYPE_SMBUS); // initialise the battery monitor battery_mon.init(); hal.scheduler->delay(1000); timer = hal.scheduler->millis(); }
void GCS_MAVLINK::send_battery_status(const AP_BattMonitor &battery){ uint16_t voltages[10]; memset(voltages, 0, sizeof(uint16_t)*10); voltages[0] = battery.voltage()/1000; mavlink_msg_battery_status_send(chan, 0, MAV_BATTERY_FUNCTION_ALL, MAV_BATTERY_TYPE_LIPO, INT16_MAX, voltages, battery.current_amps()*100, battery.current_total_mah(), -1, battery.capacity_remaining_pct()); }
// report battery2 state void GCS_MAVLINK::send_battery2(const AP_BattMonitor &battery) { float voltage; if (battery.voltage2(voltage)) { mavlink_msg_battery2_send(chan, voltage*1000, -1); } }
// report battery2 state void GCS_MAVLINK::send_battery2(const AP_BattMonitor &battery) { if (battery.num_instances() > 1) { mavlink_msg_battery2_send(chan, battery.voltage2()*1000, -1); } }