コード例 #1
0
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);
}
コード例 #2
0
ファイル: GCS_Common.cpp プロジェクト: walmis/APMLib
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());
}