From 98ae6c776a107bad8e01a3c49e89e9aa82698645 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 26 Oct 2016 12:24:41 +1100 Subject: [PATCH] Plane: support for AP_Stats (flight time, bootcount, runtime) --- ArduPlane/ArduPlane.cpp | 10 ++++++++++ ArduPlane/Parameters.cpp | 6 +++++- ArduPlane/Parameters.h | 3 +++ ArduPlane/Plane.h | 2 ++ ArduPlane/is_flying.cpp | 1 + ArduPlane/make.inc | 1 + ArduPlane/system.cpp | 3 +++ ArduPlane/wscript | 3 ++- 8 files changed, 27 insertions(+), 2 deletions(-) diff --git a/ArduPlane/ArduPlane.cpp b/ArduPlane/ArduPlane.cpp index 9c62075893..f5cf39334a 100644 --- a/ArduPlane/ArduPlane.cpp +++ b/ArduPlane/ArduPlane.cpp @@ -82,8 +82,18 @@ const AP_Scheduler::Task Plane::scheduler_tasks[] = { SCHED_TASK(dataflash_periodic, 50, 400), SCHED_TASK(avoidance_adsb_update, 10, 100), SCHED_TASK(button_update, 5, 100), + SCHED_TASK(stats_update, 1, 100), }; +/* + update AP_Stats + */ +void Plane::stats_update(void) +{ + g2.stats.update(); +} + + void Plane::setup() { cliSerial = hal.console; diff --git a/ArduPlane/Parameters.cpp b/ArduPlane/Parameters.cpp index 1be2b723c8..ea0acd8c61 100644 --- a/ArduPlane/Parameters.cpp +++ b/ArduPlane/Parameters.cpp @@ -1386,7 +1386,11 @@ const AP_Param::GroupInfo ParametersG2::var_info[] = { // @Values: 0:NotEnforced,1:Enforced // @User: Advanced AP_GROUPINFO("SYSID_ENFORCE", 4, ParametersG2, sysid_enforce, 0), - + + // @Group: STAT + // @Path: ../libraries/AP_Stats/AP_Stats.cpp + AP_SUBGROUPINFO(stats, "STAT", 5, ParametersG2, AP_Stats), + AP_GROUPEND }; diff --git a/ArduPlane/Parameters.h b/ArduPlane/Parameters.h index 58d8b551ec..0efdcf2a5f 100644 --- a/ArduPlane/Parameters.h +++ b/ArduPlane/Parameters.h @@ -582,6 +582,9 @@ public: // button reporting library AP_Button button; + // vehicle statistics + AP_Stats stats; + // internal combustion engine control AP_ICEngine ice_control; diff --git a/ArduPlane/Plane.h b/ArduPlane/Plane.h index 6a77398d05..160db0a083 100644 --- a/ArduPlane/Plane.h +++ b/ArduPlane/Plane.h @@ -52,6 +52,7 @@ #include #include #include +#include // statistics library #include #include @@ -983,6 +984,7 @@ private: void read_receiver_rssi(void); void rpm_update(void); void button_update(void); + void stats_update(); void ice_update(void); void report_radio(); void report_ins(); diff --git a/ArduPlane/is_flying.cpp b/ArduPlane/is_flying.cpp index 34e7451dbc..847f03e43b 100644 --- a/ArduPlane/is_flying.cpp +++ b/ArduPlane/is_flying.cpp @@ -156,6 +156,7 @@ void Plane::update_is_flying_5Hz(void) #if FRSKY_TELEM_ENABLED == ENABLED frsky_telemetry.set_is_flying(new_is_flying); #endif + g2.stats.set_flying(new_is_flying); crash_detection_update(); diff --git a/ArduPlane/make.inc b/ArduPlane/make.inc index 883edfc478..fc3d34fd19 100644 --- a/ArduPlane/make.inc +++ b/ArduPlane/make.inc @@ -59,3 +59,4 @@ LIBRARIES += AC_Fence LIBRARIES += AC_Avoidance LIBRARIES += AP_Proximity LIBRARIES += AP_Tuning +LIBRARIES += AP_Stats diff --git a/ArduPlane/system.cpp b/ArduPlane/system.cpp index e319ac3db9..ff376b1e48 100644 --- a/ArduPlane/system.cpp +++ b/ArduPlane/system.cpp @@ -88,6 +88,9 @@ void Plane::init_ardupilot() // load_parameters(); + // initialise stats module + g2.stats.init(); + #if HIL_SUPPORT if (g.hil_mode == 1) { // set sensors to HIL mode diff --git a/ArduPlane/wscript b/ArduPlane/wscript index 05b47605fd..d3b8b3bf39 100644 --- a/ArduPlane/wscript +++ b/ArduPlane/wscript @@ -30,7 +30,8 @@ def build(bld): 'AC_PID', 'AC_Fence', 'AC_Avoidance', - 'AP_Proximity' + 'AP_Proximity', + 'AP_Stats', ], )