Skip to content
UAS.cc 103 KiB
Newer Older
        return QString("%1V,%2V,%3V").arg(emptyVoltage).arg(warnVoltage).arg(fullVoltage);
        return QString("%1%").arg(warnLevelPercent);
    }
/**
* @return the time remaining.
pixhawk's avatar
pixhawk committed
int UAS::calculateTimeRemaining()
{
LM's avatar
LM committed
    quint64 dt = QGC::groundTimeMilliseconds() - startTime;
pixhawk's avatar
pixhawk committed
    double seconds = dt / 1000.0f;
    double voltDifference = startVoltage - currentVoltage;
    if (voltDifference <= 0) voltDifference = 0.00000000001f;
    double dischargePerSecond = voltDifference / seconds;
    int remaining = static_cast<int>((currentVoltage - emptyVoltage) / dischargePerSecond);
    // Can never be below 0
    if (remaining < 0) remaining = 0;
    return remaining;
}

lm's avatar
lm committed
/**
 * @return charge level in percent - 0 - 100
 */
float UAS::getChargeLevel()
pixhawk's avatar
pixhawk committed
{
    if (batteryRemainingEstimateEnabled)
    {
        if (lpVoltage < emptyVoltage)
        {
            chargeLevel = 0.0f;
            chargeLevel = 100.0f;
            chargeLevel = 100.0f * ((lpVoltage - emptyVoltage)/(fullVoltage - emptyVoltage));
        }
pixhawk's avatar
pixhawk committed
}

lm's avatar
lm committed
void UAS::startLowBattAlarm()
{
        GAudioOutput::instance()->alert(tr("system %1 has low battery").arg(getUASName()));
        QTimer::singleShot(3000, GAudioOutput::instance(), SLOT(startEmergency()));
lm's avatar
lm committed
        lowBattAlarm = true;
    }
}

void UAS::stopLowBattAlarm()
{
lm's avatar
lm committed
        GAudioOutput::instance()->stopEmergency();
        lowBattAlarm = false;
    }
}