mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-03 06:28:27 -04:00
AP_RCTelemetry: add and use AP_BATTERY_ENABLED
This commit is contained in:
parent
c7678042da
commit
b48b26ddb8
@ -296,12 +296,16 @@ void AP_Spektrum_Telem::calc_qos()
|
|||||||
// prepare rpm data - B/E mandatory frame that must be sent periodically
|
// prepare rpm data - B/E mandatory frame that must be sent periodically
|
||||||
void AP_Spektrum_Telem::calc_rpm()
|
void AP_Spektrum_Telem::calc_rpm()
|
||||||
{
|
{
|
||||||
|
#if AP_BATTERY_ENABLED
|
||||||
const AP_BattMonitor &_battery = AP::battery();
|
const AP_BattMonitor &_battery = AP::battery();
|
||||||
|
#endif
|
||||||
|
|
||||||
_telem.rpm.identifier = TELE_DEVICE_RPM;
|
_telem.rpm.identifier = TELE_DEVICE_RPM;
|
||||||
_telem.rpm.sID = 0;
|
_telem.rpm.sID = 0;
|
||||||
// battery voltage in centivolts, can have up to a 12S battery (4.25Vx12S = 51.0V)
|
// battery voltage in centivolts, can have up to a 12S battery (4.25Vx12S = 51.0V)
|
||||||
|
#if AP_BATTERY_ENABLED
|
||||||
_telem.rpm.volts = htobe16(((uint16_t)roundf(_battery.voltage(0) * 100.0f)));
|
_telem.rpm.volts = htobe16(((uint16_t)roundf(_battery.voltage(0) * 100.0f)));
|
||||||
|
#endif
|
||||||
_telem.rpm.temperature = htobe16(int16_t(roundf(32.0f + AP::baro().get_temperature(0) * 9.0f / 5.0f)));
|
_telem.rpm.temperature = htobe16(int16_t(roundf(32.0f + AP::baro().get_temperature(0) * 9.0f / 5.0f)));
|
||||||
#if AP_RPM_ENABLED
|
#if AP_RPM_ENABLED
|
||||||
const AP_RPM *rpm = AP::rpm();
|
const AP_RPM *rpm = AP::rpm();
|
||||||
@ -328,10 +332,12 @@ void AP_Spektrum_Telem::send_msg_chunk(const MessageChunk& chunk)
|
|||||||
// prepare battery data - B/E but not supported by Spektrum
|
// prepare battery data - B/E but not supported by Spektrum
|
||||||
void AP_Spektrum_Telem::calc_batt_volts(uint8_t instance)
|
void AP_Spektrum_Telem::calc_batt_volts(uint8_t instance)
|
||||||
{
|
{
|
||||||
|
#if AP_BATTERY_ENABLED
|
||||||
const AP_BattMonitor &_battery = AP::battery();
|
const AP_BattMonitor &_battery = AP::battery();
|
||||||
|
|
||||||
// battery voltage in centivolts, can have up to a 12S battery (4.25Vx12S = 51.0V)
|
// battery voltage in centivolts, can have up to a 12S battery (4.25Vx12S = 51.0V)
|
||||||
_telem.hv.volts = htobe16(uint16_t(roundf(_battery.voltage(instance) * 100.0f)));
|
_telem.hv.volts = htobe16(uint16_t(roundf(_battery.voltage(instance) * 100.0f)));
|
||||||
|
#endif
|
||||||
_telem.hv.identifier = TELE_DEVICE_VOLTAGE;
|
_telem.hv.identifier = TELE_DEVICE_VOLTAGE;
|
||||||
_telem.hv.sID = 0;
|
_telem.hv.sID = 0;
|
||||||
_telem_pending = true;
|
_telem_pending = true;
|
||||||
@ -340,6 +346,7 @@ void AP_Spektrum_Telem::calc_batt_volts(uint8_t instance)
|
|||||||
// prepare battery data - B/E but not supported by Spektrum
|
// prepare battery data - B/E but not supported by Spektrum
|
||||||
void AP_Spektrum_Telem::calc_batt_amps(uint8_t instance)
|
void AP_Spektrum_Telem::calc_batt_amps(uint8_t instance)
|
||||||
{
|
{
|
||||||
|
#if AP_BATTERY_ENABLED
|
||||||
const AP_BattMonitor &_battery = AP::battery();
|
const AP_BattMonitor &_battery = AP::battery();
|
||||||
|
|
||||||
float current;
|
float current;
|
||||||
@ -349,6 +356,7 @@ void AP_Spektrum_Telem::calc_batt_amps(uint8_t instance)
|
|||||||
|
|
||||||
// Range: +/- 150A Resolution: 300A / 2048 = 0.196791 A/count
|
// Range: +/- 150A Resolution: 300A / 2048 = 0.196791 A/count
|
||||||
_telem.amps.current = htobe16(int16_t(roundf(current * 2048.0f / 300.0f)));
|
_telem.amps.current = htobe16(int16_t(roundf(current * 2048.0f / 300.0f)));
|
||||||
|
#endif
|
||||||
_telem.amps.identifier = TELE_DEVICE_AMPS;
|
_telem.amps.identifier = TELE_DEVICE_AMPS;
|
||||||
_telem.amps.sID = 0;
|
_telem.amps.sID = 0;
|
||||||
_telem_pending = true;
|
_telem_pending = true;
|
||||||
@ -357,11 +365,14 @@ void AP_Spektrum_Telem::calc_batt_amps(uint8_t instance)
|
|||||||
// prepare battery data - L/E
|
// prepare battery data - L/E
|
||||||
void AP_Spektrum_Telem::calc_batt_mah()
|
void AP_Spektrum_Telem::calc_batt_mah()
|
||||||
{
|
{
|
||||||
|
#if AP_BATTERY_ENABLED
|
||||||
const AP_BattMonitor &_battery = AP::battery();
|
const AP_BattMonitor &_battery = AP::battery();
|
||||||
|
#endif
|
||||||
|
|
||||||
_telem.fpMAH.identifier = TELE_DEVICE_FP_MAH;
|
_telem.fpMAH.identifier = TELE_DEVICE_FP_MAH;
|
||||||
_telem.fpMAH.sID = 0;
|
_telem.fpMAH.sID = 0;
|
||||||
|
|
||||||
|
#if AP_BATTERY_ENABLED
|
||||||
float current;
|
float current;
|
||||||
if (!_battery.current_amps(current, 0)) {
|
if (!_battery.current_amps(current, 0)) {
|
||||||
current = 0;
|
current = 0;
|
||||||
@ -396,6 +407,10 @@ void AP_Spektrum_Telem::calc_batt_mah()
|
|||||||
} else {
|
} else {
|
||||||
_telem.fpMAH.temp_B = 0x7FFF;
|
_telem.fpMAH.temp_B = 0x7FFF;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
_telem.fpMAH.temp_A = 0x7FFF;
|
||||||
|
_telem.fpMAH.temp_B = 0x7FFF;
|
||||||
|
#endif
|
||||||
|
|
||||||
_telem_pending = true;
|
_telem_pending = true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user