mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-13 19:40:31 +03:00
Added throttle flight statistics (#12978)
* Added throttle flight statistics * Changed rc_stats.c/h license header to a modern one * rc_stats.c Style fix
This commit is contained in:
parent
fb9587b2ec
commit
dfef3bfb0e
11 changed files with 191 additions and 1 deletions
|
@ -105,6 +105,7 @@ COMMON_SRC = \
|
||||||
rx/msp.c \
|
rx/msp.c \
|
||||||
rx/pwm.c \
|
rx/pwm.c \
|
||||||
rx/frsky_crc.c \
|
rx/frsky_crc.c \
|
||||||
|
rx/rc_stats.c \
|
||||||
rx/rx.c \
|
rx/rx.c \
|
||||||
rx/rx_bind.c \
|
rx/rx_bind.c \
|
||||||
rx/rx_spi.c \
|
rx/rx_spi.c \
|
||||||
|
@ -326,6 +327,7 @@ SPEED_OPTIMISED_SRC := $(SPEED_OPTIMISED_SRC) \
|
||||||
flight/pid.c \
|
flight/pid.c \
|
||||||
flight/rpm_filter.c \
|
flight/rpm_filter.c \
|
||||||
rx/ibus.c \
|
rx/ibus.c \
|
||||||
|
rx/rc_stats.c \
|
||||||
rx/rx.c \
|
rx/rx.c \
|
||||||
rx/rx_spi.c \
|
rx/rx_spi.c \
|
||||||
rx/crsf.c \
|
rx/crsf.c \
|
||||||
|
|
|
@ -114,4 +114,5 @@ const char * const debugModeNames[DEBUG_COUNT] = {
|
||||||
"CURRENT_ANGLE",
|
"CURRENT_ANGLE",
|
||||||
"DSHOT_TELEMETRY_COUNTS",
|
"DSHOT_TELEMETRY_COUNTS",
|
||||||
"RPM_LIMIT",
|
"RPM_LIMIT",
|
||||||
|
"RC_STATS",
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#define DEBUG16_VALUE_COUNT 8
|
#define DEBUG16_VALUE_COUNT 8
|
||||||
extern int16_t debug[DEBUG16_VALUE_COUNT];
|
extern int16_t debug[DEBUG16_VALUE_COUNT];
|
||||||
extern uint8_t debugMode;
|
extern uint8_t debugMode;
|
||||||
|
@ -112,6 +114,7 @@ typedef enum {
|
||||||
DEBUG_CURRENT_ANGLE,
|
DEBUG_CURRENT_ANGLE,
|
||||||
DEBUG_DSHOT_TELEMETRY_COUNTS,
|
DEBUG_DSHOT_TELEMETRY_COUNTS,
|
||||||
DEBUG_RPM_LIMIT,
|
DEBUG_RPM_LIMIT,
|
||||||
|
DEBUG_RC_STATS,
|
||||||
DEBUG_COUNT
|
DEBUG_COUNT
|
||||||
} debugType_e;
|
} debugType_e;
|
||||||
|
|
||||||
|
|
|
@ -1736,7 +1736,9 @@ const clivalue_t valueTable[] = {
|
||||||
#ifdef USE_BATTERY_CONTINUE
|
#ifdef USE_BATTERY_CONTINUE
|
||||||
{ "stats_mah_used", VAR_UINT32 | MASTER_VALUE, .config.u32Max = UINT32_MAX, PG_STATS_CONFIG, offsetof(statsConfig_t, stats_mah_used) },
|
{ "stats_mah_used", VAR_UINT32 | MASTER_VALUE, .config.u32Max = UINT32_MAX, PG_STATS_CONFIG, offsetof(statsConfig_t, stats_mah_used) },
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
#endif // USE_PERSISTENT_STATS
|
||||||
|
|
||||||
{ "craft_name", VAR_UINT8 | MASTER_VALUE | MODE_STRING, .config.string = { 1, MAX_NAME_LENGTH, STRING_FLAGS_NONE }, PG_PILOT_CONFIG, offsetof(pilotConfig_t, craftName) },
|
{ "craft_name", VAR_UINT8 | MASTER_VALUE | MODE_STRING, .config.string = { 1, MAX_NAME_LENGTH, STRING_FLAGS_NONE }, PG_PILOT_CONFIG, offsetof(pilotConfig_t, craftName) },
|
||||||
#ifdef USE_OSD
|
#ifdef USE_OSD
|
||||||
{ "pilot_name", VAR_UINT8 | MASTER_VALUE | MODE_STRING, .config.string = { 1, MAX_NAME_LENGTH, STRING_FLAGS_NONE }, PG_PILOT_CONFIG, offsetof(pilotConfig_t, pilotName) },
|
{ "pilot_name", VAR_UINT8 | MASTER_VALUE | MODE_STRING, .config.string = { 1, MAX_NAME_LENGTH, STRING_FLAGS_NONE }, PG_PILOT_CONFIG, offsetof(pilotConfig_t, pilotName) },
|
||||||
|
|
|
@ -92,6 +92,7 @@
|
||||||
#include "pg/pg_ids.h"
|
#include "pg/pg_ids.h"
|
||||||
#include "pg/rx.h"
|
#include "pg/rx.h"
|
||||||
|
|
||||||
|
#include "rx/rc_stats.h"
|
||||||
#include "rx/rx.h"
|
#include "rx/rx.h"
|
||||||
|
|
||||||
#include "scheduler/scheduler.h"
|
#include "scheduler/scheduler.h"
|
||||||
|
@ -554,6 +555,10 @@ void tryArm(void)
|
||||||
#endif
|
#endif
|
||||||
ENABLE_ARMING_FLAG(ARMED);
|
ENABLE_ARMING_FLAG(ARMED);
|
||||||
|
|
||||||
|
#ifdef USE_RC_STATS
|
||||||
|
NotifyRcStatsArming();
|
||||||
|
#endif
|
||||||
|
|
||||||
resetTryingToArm();
|
resetTryingToArm();
|
||||||
|
|
||||||
#ifdef USE_ACRO_TRAINER
|
#ifdef USE_ACRO_TRAINER
|
||||||
|
|
|
@ -82,6 +82,7 @@
|
||||||
#include "pg/motor.h"
|
#include "pg/motor.h"
|
||||||
|
|
||||||
#include "rx/rx.h"
|
#include "rx/rx.h"
|
||||||
|
#include "rx/rc_stats.h"
|
||||||
|
|
||||||
#include "scheduler/scheduler.h"
|
#include "scheduler/scheduler.h"
|
||||||
|
|
||||||
|
@ -450,6 +451,11 @@ task_attribute_t task_attributes[TASK_COUNT] = {
|
||||||
#ifdef USE_CRSF_V3
|
#ifdef USE_CRSF_V3
|
||||||
[TASK_SPEED_NEGOTIATION] = DEFINE_TASK("SPEED_NEGOTIATION", NULL, NULL, speedNegotiationProcess, TASK_PERIOD_HZ(100), TASK_PRIORITY_LOW),
|
[TASK_SPEED_NEGOTIATION] = DEFINE_TASK("SPEED_NEGOTIATION", NULL, NULL, speedNegotiationProcess, TASK_PERIOD_HZ(100), TASK_PRIORITY_LOW),
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_RC_STATS
|
||||||
|
[TASK_RC_STATS] = DEFINE_TASK("RC_STATS", NULL, NULL, rcStatsUpdate, TASK_PERIOD_HZ(100), TASK_PRIORITY_LOW),
|
||||||
|
#endif
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
task_t *getTask(unsigned taskId)
|
task_t *getTask(unsigned taskId)
|
||||||
|
@ -621,4 +627,8 @@ void tasksInit(void)
|
||||||
#ifdef SIMULATOR_MULTITHREAD
|
#ifdef SIMULATOR_MULTITHREAD
|
||||||
rescheduleTask(TASK_RX, 1);
|
rescheduleTask(TASK_RX, 1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_RC_STATS
|
||||||
|
setTaskEnabled(TASK_RC_STATS, true);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,6 +89,7 @@
|
||||||
#include "pg/stats.h"
|
#include "pg/stats.h"
|
||||||
|
|
||||||
#include "rx/crsf.h"
|
#include "rx/crsf.h"
|
||||||
|
#include "rx/rc_stats.h"
|
||||||
#include "rx/rx.h"
|
#include "rx/rx.h"
|
||||||
|
|
||||||
#include "scheduler/scheduler.h"
|
#include "scheduler/scheduler.h"
|
||||||
|
@ -196,6 +197,9 @@ const osd_stats_e osdStatsDisplayOrder[OSD_STAT_COUNT] = {
|
||||||
OSD_STAT_WATT_HOURS_DRAWN,
|
OSD_STAT_WATT_HOURS_DRAWN,
|
||||||
OSD_STAT_BEST_3_CONSEC_LAPS,
|
OSD_STAT_BEST_3_CONSEC_LAPS,
|
||||||
OSD_STAT_BEST_LAP,
|
OSD_STAT_BEST_LAP,
|
||||||
|
OSD_STAT_FULL_THROTTLE_TIME,
|
||||||
|
OSD_STAT_FULL_THROTTLE_COUNTER,
|
||||||
|
OSD_STAT_AVG_THROTTLE,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Group elements in a number of groups to reduce task scheduling overhead
|
// Group elements in a number of groups to reduce task scheduling overhead
|
||||||
|
@ -355,6 +359,12 @@ void pgResetFn_osdConfig(osdConfig_t *osdConfig)
|
||||||
// turn off the over mah capacity warning
|
// turn off the over mah capacity warning
|
||||||
osdWarnSetState(OSD_WARNING_OVER_CAP, false);
|
osdWarnSetState(OSD_WARNING_OVER_CAP, false);
|
||||||
|
|
||||||
|
#ifdef USE_RC_STATS
|
||||||
|
osdStatSetState(OSD_STAT_FULL_THROTTLE_TIME, true);
|
||||||
|
osdStatSetState(OSD_STAT_FULL_THROTTLE_COUNTER, true);
|
||||||
|
osdStatSetState(OSD_STAT_AVG_THROTTLE, true);
|
||||||
|
#endif
|
||||||
|
|
||||||
osdConfig->timers[OSD_TIMER_1] = osdTimerDefault[OSD_TIMER_1];
|
osdConfig->timers[OSD_TIMER_1] = osdTimerDefault[OSD_TIMER_1];
|
||||||
osdConfig->timers[OSD_TIMER_2] = osdTimerDefault[OSD_TIMER_2];
|
osdConfig->timers[OSD_TIMER_2] = osdTimerDefault[OSD_TIMER_2];
|
||||||
|
|
||||||
|
@ -1009,6 +1019,28 @@ static bool osdDisplayStat(int statistic, uint8_t displayRow)
|
||||||
osdDisplayStatisticLabel(midCol, displayRow, "TOTAL DISTANCE", buff);
|
osdDisplayStatisticLabel(midCol, displayRow, "TOTAL DISTANCE", buff);
|
||||||
return true;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_RC_STATS
|
||||||
|
case OSD_STAT_FULL_THROTTLE_TIME: {
|
||||||
|
int seconds = RcStatsGetFullThrottleTimeUs() / 1000000;
|
||||||
|
const int minutes = seconds / 60;
|
||||||
|
seconds = seconds % 60;
|
||||||
|
tfp_sprintf(buff, "%02d:%02d", minutes, seconds);
|
||||||
|
osdDisplayStatisticLabel(midCol, displayRow, "100% THRT TIME", buff);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case OSD_STAT_FULL_THROTTLE_COUNTER: {
|
||||||
|
itoa(RcStatsGetFullThrottleCounter(), buff, 10);
|
||||||
|
osdDisplayStatisticLabel(midCol, displayRow, "100% THRT COUNT", buff);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case OSD_STAT_AVG_THROTTLE: {
|
||||||
|
itoa(RcStatsGetAverageThrottle(), buff, 10);
|
||||||
|
osdDisplayStatisticLabel(midCol, displayRow, "AVG THROTTLE", buff);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif // USE_RC_STATS
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -232,6 +232,9 @@ typedef enum {
|
||||||
OSD_STAT_MIN_RSNR,
|
OSD_STAT_MIN_RSNR,
|
||||||
OSD_STAT_BEST_3_CONSEC_LAPS,
|
OSD_STAT_BEST_3_CONSEC_LAPS,
|
||||||
OSD_STAT_BEST_LAP,
|
OSD_STAT_BEST_LAP,
|
||||||
|
OSD_STAT_FULL_THROTTLE_TIME,
|
||||||
|
OSD_STAT_FULL_THROTTLE_COUNTER,
|
||||||
|
OSD_STAT_AVG_THROTTLE,
|
||||||
OSD_STAT_COUNT // MUST BE LAST
|
OSD_STAT_COUNT // MUST BE LAST
|
||||||
} osd_stats_e;
|
} osd_stats_e;
|
||||||
|
|
||||||
|
|
95
src/main/rx/rc_stats.c
Normal file
95
src/main/rx/rc_stats.c
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Betaflight.
|
||||||
|
*
|
||||||
|
* Betaflight is free software. You can redistribute this software
|
||||||
|
* and/or modify this software under the terms of the GNU General
|
||||||
|
* Public License as published by the Free Software Foundation,
|
||||||
|
* either version 3 of the License, or (at your option) any later
|
||||||
|
* version.
|
||||||
|
*
|
||||||
|
* Betaflight is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public
|
||||||
|
* License along with this software.
|
||||||
|
*
|
||||||
|
* If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "platform.h"
|
||||||
|
|
||||||
|
#ifdef USE_RC_STATS
|
||||||
|
|
||||||
|
#include "build/debug.h"
|
||||||
|
#include "fc/core.h"
|
||||||
|
#include "fc/rc_modes.h"
|
||||||
|
#include "fc/runtime_config.h"
|
||||||
|
|
||||||
|
#include "rx/rc_stats.h"
|
||||||
|
|
||||||
|
timeUs_t previousTimeUs = 0;
|
||||||
|
bool throttleEverRaisedAfterArming = false;
|
||||||
|
uint32_t counter = 0;
|
||||||
|
uint32_t totalTrottleNumber = 0;
|
||||||
|
timeUs_t fullThrottleTimeUs = 0;
|
||||||
|
uint32_t fullThrottleCounter = 0;
|
||||||
|
int8_t previousThrottlePercent = 0;
|
||||||
|
|
||||||
|
|
||||||
|
void rcStatsUpdate(timeUs_t currentTimeUs)
|
||||||
|
{
|
||||||
|
uint32_t deltaT = currentTimeUs - previousTimeUs;
|
||||||
|
previousTimeUs = currentTimeUs;
|
||||||
|
const int8_t throttlePercent = calculateThrottlePercent();
|
||||||
|
|
||||||
|
if (ARMING_FLAG(ARMED) && !IS_RC_MODE_ACTIVE(BOXFLIPOVERAFTERCRASH) && !throttleEverRaisedAfterArming) {
|
||||||
|
if (abs(throttlePercent) >= 15) { // start counting stats if throttle was raised >= 15% after arming
|
||||||
|
throttleEverRaisedAfterArming = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ARMING_FLAG(ARMED) && !IS_RC_MODE_ACTIVE(BOXFLIPOVERAFTERCRASH) && throttleEverRaisedAfterArming) {
|
||||||
|
counter++;
|
||||||
|
totalTrottleNumber += throttlePercent;
|
||||||
|
|
||||||
|
if (abs(throttlePercent) == 100) {
|
||||||
|
fullThrottleTimeUs += deltaT;
|
||||||
|
if (abs(previousThrottlePercent) != 100) {
|
||||||
|
fullThrottleCounter ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG_SET(DEBUG_RC_STATS, 0, lrintf(RcStatsGetAverageThrottle()));
|
||||||
|
|
||||||
|
previousThrottlePercent = throttlePercent;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t RcStatsGetFullThrottleCounter(void)
|
||||||
|
{
|
||||||
|
return fullThrottleCounter;
|
||||||
|
}
|
||||||
|
|
||||||
|
timeUs_t RcStatsGetFullThrottleTimeUs(void)
|
||||||
|
{
|
||||||
|
return fullThrottleTimeUs;
|
||||||
|
}
|
||||||
|
|
||||||
|
int8_t RcStatsGetAverageThrottle(void)
|
||||||
|
{
|
||||||
|
return (float)totalTrottleNumber/(float)counter + 0.5; // rounding
|
||||||
|
}
|
||||||
|
|
||||||
|
void NotifyRcStatsArming(void)
|
||||||
|
{
|
||||||
|
throttleEverRaisedAfterArming = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // USE_RC_STATS
|
34
src/main/rx/rc_stats.h
Normal file
34
src/main/rx/rc_stats.h
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Betaflight.
|
||||||
|
*
|
||||||
|
* Betaflight is free software. You can redistribute this software
|
||||||
|
* and/or modify this software under the terms of the GNU General
|
||||||
|
* Public License as published by the Free Software Foundation,
|
||||||
|
* either version 3 of the License, or (at your option) any later
|
||||||
|
* version.
|
||||||
|
*
|
||||||
|
* Betaflight is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public
|
||||||
|
* License along with this software.
|
||||||
|
*
|
||||||
|
* If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef USE_RC_STATS
|
||||||
|
|
||||||
|
#include "common/time.h"
|
||||||
|
|
||||||
|
void rcStatsUpdate(timeUs_t currentTimeUs);
|
||||||
|
void NotifyRcStatsArming(void);
|
||||||
|
int8_t RcStatsGetAverageThrottle(void);
|
||||||
|
uint32_t RcStatsGetFullThrottleCounter(void);
|
||||||
|
timeUs_t RcStatsGetFullThrottleTimeUs(void);
|
||||||
|
|
||||||
|
#endif // USE_RC_STATS
|
|
@ -176,6 +176,9 @@ typedef enum {
|
||||||
#ifdef USE_CRSF_V3
|
#ifdef USE_CRSF_V3
|
||||||
TASK_SPEED_NEGOTIATION,
|
TASK_SPEED_NEGOTIATION,
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_RC_STATS
|
||||||
|
TASK_RC_STATS,
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Count of real tasks */
|
/* Count of real tasks */
|
||||||
TASK_COUNT,
|
TASK_COUNT,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue