From 6b5afe4654d6a8b42d2fce08a9ac16b82d0bc9d1 Mon Sep 17 00:00:00 2001 From: Yury MonZon Date: Mon, 9 Dec 2024 16:11:39 +0100 Subject: [PATCH 1/4] AP_Tuning: Show current parameter value on OSD and GCS --- libraries/AP_Tuning/AP_Tuning.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libraries/AP_Tuning/AP_Tuning.cpp b/libraries/AP_Tuning/AP_Tuning.cpp index 490416fdab840..8b0c6f7fde922 100644 --- a/libraries/AP_Tuning/AP_Tuning.cpp +++ b/libraries/AP_Tuning/AP_Tuning.cpp @@ -202,10 +202,10 @@ void AP_Tuning::check_input(uint8_t flightmode) //hal.console->printf("chan_value %.2f last_channel_value %.2f\n", chan_value, last_channel_value); + const float dead_zone = 0.02; if (mid_point_wait) { // see if we have crossed the mid-point. We use a small deadzone to make it easier // to move to the "indent" portion of a slider to start tuning - const float dead_zone = 0.02; if ((chan_value > dead_zone && last_channel_value > 0) || (chan_value < -dead_zone && last_channel_value < 0)) { // still waiting @@ -213,7 +213,6 @@ void AP_Tuning::check_input(uint8_t flightmode) } // starting tuning mid_point_wait = false; - GCS_SEND_TEXT(MAV_SEVERITY_INFO, "Tuning: mid-point %s", get_tuning_name(current_parm)); AP_Notify::events.tune_started = 1; } last_channel_value = chan_value; @@ -228,6 +227,12 @@ void AP_Tuning::check_input(uint8_t flightmode) need_revert |= (1U << current_parm_index); set_value(current_parm, new_value); + GCS_SEND_TEXT(MAV_SEVERITY_INFO, + "Tuning %s%s%0.5f", + get_tuning_name(current_parm), + ((chan_value < dead_zone) && (chan_value > -dead_zone)) ? "> " : ": ", + (double)(new_value)); + #if HAL_LOGGING_ENABLED Log_Write_Parameter_Tuning(new_value); #endif From ad3ee178c12c1e8193a46f0c2ccdbbb702a51e4c Mon Sep 17 00:00:00 2001 From: Yury MonZon Date: Mon, 9 Dec 2024 15:02:02 +0100 Subject: [PATCH 2/4] AP_Tuning_Plane: Added PIDFF tuning sets --- ArduPlane/tuning.cpp | 6 ++++++ ArduPlane/tuning.h | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/ArduPlane/tuning.cpp b/ArduPlane/tuning.cpp index be860264fd339..c93c3d862a8ec 100644 --- a/ArduPlane/tuning.cpp +++ b/ArduPlane/tuning.cpp @@ -37,6 +37,9 @@ const uint8_t AP_Tuning_Plane::tuning_set_az[] = { TUNING_AZ_P, TU const uint8_t AP_Tuning_Plane::tuning_set_rate_pitchDP[]= { TUNING_RATE_PITCH_D, TUNING_RATE_PITCH_P }; const uint8_t AP_Tuning_Plane::tuning_set_rate_rollDP[]= { TUNING_RATE_ROLL_D, TUNING_RATE_ROLL_P }; const uint8_t AP_Tuning_Plane::tuning_set_rate_yawDP[]= { TUNING_RATE_YAW_D, TUNING_RATE_YAW_P }; +const uint8_t AP_Tuning_Plane::tuning_set_dp_roll_pitch[] = { TUNING_RLL_D, TUNING_RLL_P, TUNING_PIT_D, TUNING_PIT_P }; +const uint8_t AP_Tuning_Plane::tuning_set_pidff_roll[] = { TUNING_RLL_P, TUNING_RLL_I, TUNING_RLL_D, TUNING_RLL_FF }; +const uint8_t AP_Tuning_Plane::tuning_set_pidff_pitch[] = { TUNING_PIT_P, TUNING_PIT_I, TUNING_PIT_D, TUNING_PIT_FF }; // macro to prevent getting the array length wrong #define TUNING_ARRAY(v) ARRAY_SIZE(v), v @@ -53,6 +56,9 @@ const AP_Tuning_Plane::tuning_set AP_Tuning_Plane::tuning_sets[] = { { TUNING_SET_RATE_PITCHDP, TUNING_ARRAY(tuning_set_rate_pitchDP) }, { TUNING_SET_RATE_ROLLDP, TUNING_ARRAY(tuning_set_rate_rollDP) }, { TUNING_SET_RATE_YAWDP, TUNING_ARRAY(tuning_set_rate_yawDP) }, + { TUNING_SET_DP_ROLL_PITCH, TUNING_ARRAY(tuning_set_dp_roll_pitch) }, + { TUNING_SET_PIDFF_ROLL, TUNING_ARRAY(tuning_set_pidff_roll) }, + { TUNING_SET_PIDFF_PITCH, TUNING_ARRAY(tuning_set_pidff_pitch) }, { 0, 0, nullptr } }; diff --git a/ArduPlane/tuning.h b/ArduPlane/tuning.h index 4334455a09657..9e63bf729d704 100644 --- a/ArduPlane/tuning.h +++ b/ArduPlane/tuning.h @@ -94,6 +94,9 @@ class AP_Tuning_Plane : public AP_Tuning TUNING_SET_RATE_PITCHDP = 8, TUNING_SET_RATE_ROLLDP = 9, TUNING_SET_RATE_YAWDP = 10, + TUNING_SET_DP_ROLL_PITCH = 11, + TUNING_SET_PIDFF_ROLL = 12, + TUNING_SET_PIDFF_PITCH = 13, }; AP_Float *get_param_pointer(uint8_t parm) override; @@ -112,6 +115,9 @@ class AP_Tuning_Plane : public AP_Tuning static const uint8_t tuning_set_rate_pitchDP[]; static const uint8_t tuning_set_rate_rollDP[]; static const uint8_t tuning_set_rate_yawDP[]; + static const uint8_t tuning_set_dp_roll_pitch[]; + static const uint8_t tuning_set_pidff_roll[]; + static const uint8_t tuning_set_pidff_pitch[]; // mask of what params have been set uint64_t have_set; From 9a6f288882e67cb243eb9b4b9d7c488f039f8323 Mon Sep 17 00:00:00 2001 From: Yury MonZon Date: Mon, 9 Dec 2024 21:42:57 +0100 Subject: [PATCH 3/4] AP_Tuning: Update OSD on 5 percent change --- libraries/AP_Tuning/AP_Tuning.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libraries/AP_Tuning/AP_Tuning.cpp b/libraries/AP_Tuning/AP_Tuning.cpp index 8b0c6f7fde922..87bbf15a13e8c 100644 --- a/libraries/AP_Tuning/AP_Tuning.cpp +++ b/libraries/AP_Tuning/AP_Tuning.cpp @@ -218,6 +218,7 @@ void AP_Tuning::check_input(uint8_t flightmode) last_channel_value = chan_value; float new_value; + static float old_value; if (chan_value > 0) { new_value = linear_interpolate(center_value, range*center_value, chan_value, 0, 1); } else { @@ -227,11 +228,14 @@ void AP_Tuning::check_input(uint8_t flightmode) need_revert |= (1U << current_parm_index); set_value(current_parm, new_value); - GCS_SEND_TEXT(MAV_SEVERITY_INFO, - "Tuning %s%s%0.5f", - get_tuning_name(current_parm), - ((chan_value < dead_zone) && (chan_value > -dead_zone)) ? "> " : ": ", - (double)(new_value)); + if ( fabsf(new_value-old_value) > (0.05 * old_value) ) { + old_value = new_value; + GCS_SEND_TEXT(MAV_SEVERITY_INFO, + "Tuning %s%s%0.4f", + get_tuning_name(current_parm), + ((chan_value < dead_zone) && (chan_value > -dead_zone)) ? "> " : ": ", + (double)(new_value)); + } #if HAL_LOGGING_ENABLED Log_Write_Parameter_Tuning(new_value); From 5a9cce5b90b701ba75f37abeb21d4483b35a1754 Mon Sep 17 00:00:00 2001 From: Yury MonZon Date: Tue, 31 Dec 2024 13:08:12 +0100 Subject: [PATCH 4/4] AP_Tuning: Bugfix --- libraries/AP_Tuning/AP_Tuning.cpp | 4 ++-- libraries/AP_Tuning/AP_Tuning.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libraries/AP_Tuning/AP_Tuning.cpp b/libraries/AP_Tuning/AP_Tuning.cpp index 87bbf15a13e8c..c10e5b1253e53 100644 --- a/libraries/AP_Tuning/AP_Tuning.cpp +++ b/libraries/AP_Tuning/AP_Tuning.cpp @@ -123,6 +123,7 @@ void AP_Tuning::re_center(void) AP_Float *f = get_param_pointer(current_parm); if (f != nullptr) { center_value = f->get(); + old_value = 0.0; } mid_point_wait = true; } @@ -218,7 +219,6 @@ void AP_Tuning::check_input(uint8_t flightmode) last_channel_value = chan_value; float new_value; - static float old_value; if (chan_value > 0) { new_value = linear_interpolate(center_value, range*center_value, chan_value, 0, 1); } else { @@ -231,7 +231,7 @@ void AP_Tuning::check_input(uint8_t flightmode) if ( fabsf(new_value-old_value) > (0.05 * old_value) ) { old_value = new_value; GCS_SEND_TEXT(MAV_SEVERITY_INFO, - "Tuning %s%s%0.4f", + "Tuning: %s%s%0.4f", get_tuning_name(current_parm), ((chan_value < dead_zone) && (chan_value > -dead_zone)) ? "> " : ": ", (double)(new_value)); diff --git a/libraries/AP_Tuning/AP_Tuning.h b/libraries/AP_Tuning/AP_Tuning.h index 88ffda0c4b08a..5aad12ea9b019 100644 --- a/libraries/AP_Tuning/AP_Tuning.h +++ b/libraries/AP_Tuning/AP_Tuning.h @@ -64,6 +64,9 @@ class AP_Tuning uint32_t last_check_ms; + // last tuning value scaled + float old_value; + void Log_Write_Parameter_Tuning(float value); // the parameter we are tuning