Skip to content

Commit 98e7cbd

Browse files
committed
Copter: PosHold brake angle converted to deg
1 parent d6f64da commit 98e7cbd

5 files changed

Lines changed: 81 additions & 21 deletions

File tree

ArduCopter/Parameters.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -275,22 +275,13 @@ const AP_Param::Info Copter::var_info[] = {
275275
GSCALAR(disarm_delay, "DISARM_DELAY", AUTO_DISARMING_DELAY),
276276

277277
#if MODE_POSHOLD_ENABLED
278-
// @Param: PHLD_BRAKE_RATE
278+
// @Param: PHLD_BRK_RATE
279279
// @DisplayName: PosHold braking rate
280280
// @Description: PosHold flight mode's rotation rate during braking in deg/sec
281281
// @Units: deg/s
282282
// @Range: 4 12
283283
// @User: Advanced
284-
GSCALAR(poshold_brake_rate_degs, "PHLD_BRAKE_RATE", POSHOLD_BRAKE_RATE_DEFAULT),
285-
286-
// @Param: PHLD_BRAKE_ANGLE
287-
// @DisplayName: PosHold braking angle max
288-
// @Description: PosHold flight mode's max lean angle during braking in centi-degrees
289-
// @Units: cdeg
290-
// @Increment: 10
291-
// @Range: 2000 4500
292-
// @User: Advanced
293-
GSCALAR(poshold_brake_angle_max, "PHLD_BRAKE_ANGLE", POSHOLD_BRAKE_ANGLE_DEFAULT),
284+
GSCALAR(poshold_brake_rate_degs, "PHLD_BRK_RATE", POSHOLD_BRAKE_RATE_DEFAULT),
294285
#endif
295286

296287
// @Param: LAND_REPOSITION
@@ -1170,6 +1161,12 @@ const AP_Param::GroupInfo ParametersG2::var_info2[] = {
11701161
// @Path: mode_land.cpp
11711162
AP_SUBGROUPPTR(mode_land_ptr, "LAND_", 15, ParametersG2, ModeLand),
11721163

1164+
#if MODE_POSHOLD_ENABLED
1165+
// @Group: PHLD_
1166+
// @Path: mode_poshold.cpp
1167+
AP_SUBGROUPPTR(mode_poshold_ptr, "PHLD_", 16, ParametersG2, ModePosHold),
1168+
#endif
1169+
11731170
// ID 62 is reserved for the AP_SUBGROUPEXTENSION
11741171

11751172
AP_GROUPEND
@@ -1236,6 +1233,9 @@ ParametersG2::ParametersG2(void) :
12361233
,mode_rtl_ptr(&copter.mode_rtl)
12371234
#endif
12381235
,mode_land_ptr(&copter.mode_land)
1236+
#if MODE_POSHOLD_ENABLED
1237+
,mode_poshold_ptr(&copter.mode_poshold)
1238+
#endif
12391239
{
12401240
AP_Param::setup_object_defaults(this, var_info);
12411241
AP_Param::setup_object_defaults(this, var_info2);
@@ -1308,6 +1308,11 @@ void Copter::load_parameters(void)
13081308
// convert LAND parameters
13091309
copter.mode_land.convert_params();
13101310

1311+
#if MODE_POSHOLD_ENABLED
1312+
// convert PosHold parameters
1313+
copter.mode_poshold.convert_params();
1314+
#endif
1315+
13111316
// setup AP_Param frame type flags
13121317
AP_Param::set_frame_type_flags(AP_PARAM_FRAME_COPTER);
13131318
}
@@ -1333,8 +1338,8 @@ void Copter::convert_pid_parameters(void)
13331338
{ "LOIT_BRK_DELAY", 1.0f },
13341339
{ "LOIT_BRK_JRK_M", 2.5f },
13351340
{ "LOIT_SPEED_MS", 30.0f },
1336-
{ "PHLD_BRAKE_ANGLE", 800.0f },
1337-
{ "PHLD_BRAKE_RATE", 4.0f },
1341+
{ "PHLD_BRK_ANGLE", 8.0f },
1342+
{ "PHLD_BRK_RATE", 4.0f },
13381343
{ "PSC_D_ACC_P", 0.028f },
13391344
{ "PSC_NE_VEL_D", 0.0f },
13401345
{ "PSC_NE_VEL_I", 0.5f },

ArduCopter/Parameters.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class Parameters {
123123
k_param_rc_14_old,
124124
k_param_rally,
125125
k_param_poshold_brake_rate_degs,
126-
k_param_poshold_brake_angle_max,
126+
k_param_poshold_brake_angle_max, // deprecated - remove
127127
k_param_pilot_accel_d_cmss,
128128
k_param_serial0_baud, // deprecated - remove
129129
k_param_serial1_baud, // deprecated - remove
@@ -412,7 +412,6 @@ class Parameters {
412412

413413
#if MODE_POSHOLD_ENABLED
414414
AP_Int16 poshold_brake_rate_degs; // PosHold flight mode's rotation rate during braking in deg/sec
415-
AP_Int16 poshold_brake_angle_max; // PosHold flight mode's max lean angle during braking in centi-degrees
416415
#endif
417416

418417
// Waypoints
@@ -702,6 +701,11 @@ class ParametersG2 {
702701
#endif
703702

704703
void *mode_land_ptr;
704+
705+
#if MODE_POSHOLD_ENABLED
706+
void *mode_poshold_ptr;
707+
#endif
708+
705709
};
706710

707711
extern const AP_Param::Info var_info[];

ArduCopter/config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,8 @@
492492
# define POSHOLD_BRAKE_RATE_DEFAULT 8 // default POSHOLD_BRAKE_RATE param value. Rotation rate during braking in deg/sec
493493
# define POSHOLD_BRAKE_RATE_MIN 4 // default POSHOLD_BRAKE_RATE param value. Rotation rate during braking in deg/sec
494494
#endif
495-
#ifndef POSHOLD_BRAKE_ANGLE_DEFAULT
496-
# define POSHOLD_BRAKE_ANGLE_DEFAULT 3000 // default POSHOLD_BRAKE_ANGLE param value. Max lean angle during braking in centi-degrees
495+
#ifdef POSHOLD_BRAKE_ANGLE_DEFAULT
496+
#error "POSHOLD_BRAKE_ANGLE_DEFAULT definition replaced with POSHOLD_BRAKE_ANGLE_DEG_DEFAULT (in degrees)"
497497
#endif
498498

499499
//////////////////////////////////////////////////////////////////////////////

ArduCopter/mode.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,8 +1394,8 @@ class ModeLoiter : public Mode {
13941394
class ModePosHold : public Mode {
13951395

13961396
public:
1397-
// inherit constructor
1398-
using Mode::Mode;
1397+
// need a constructor for parameters
1398+
ModePosHold(void);
13991399
Number mode_number() const override { return Number::POSHOLD; }
14001400

14011401
bool init(bool ignore_checks) override;
@@ -1409,13 +1409,22 @@ class ModePosHold : public Mode {
14091409
bool allows_autotune() const override { return true; }
14101410
bool allows_auto_trim() const override { return true; }
14111411

1412+
// convert parameters
1413+
void convert_params();
1414+
1415+
// mode specific parameter variable table
1416+
static const struct AP_Param::GroupInfo var_info[];
1417+
14121418
protected:
14131419

14141420
const char *name() const override { return "Position Hold"; }
14151421
const char *name4() const override { return "PHLD"; }
14161422

14171423
private:
14181424

1425+
// parameters
1426+
AP_Float brake_angle_max_deg; // max lean angle (in degrees) during braking
1427+
14191428
void update_pilot_lean_angle_rad(float &lean_angle_filtered_rad, float &lean_angle_raw_rad);
14201429
float mix_controls(float mix_ratio, float first_control, float second_control);
14211430
void update_brake_angle_from_velocity(float &brake_angle_rad, float velocity_ms);

ArduCopter/mode_poshold.cpp

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,48 @@
2121
#define POSHOLD_WIND_COMP_ESTIMATE_SPEED_MAX_MS 0.10 // wind compensation estimates will only run when velocity is at or below this speed in cm/s
2222
#define POSHOLD_WIND_COMP_LEAN_PCT_MAX 0.6666f // wind compensation no more than 2/3rds of angle max to ensure pilot can always override
2323

24+
#ifndef POSHOLD_BRAKE_ANGLE_DEG_DEFAULT
25+
# define POSHOLD_BRAKE_ANGLE_DEG_DEFAULT 30 // default PHLD_BRK_ANGLE param value. Max lean angle during braking in degrees
26+
#endif
27+
28+
// table of user settable parameters
29+
const AP_Param::GroupInfo ModePosHold::var_info[] = {
30+
31+
// @Param: BRK_ANGLE
32+
// @DisplayName: PosHold braking angle max
33+
// @Description: PosHold flight mode's max lean angle during braking in degrees
34+
// @Units: deg
35+
// @Increment: 1
36+
// @Range: 20 45
37+
// @User: Advanced
38+
AP_GROUPINFO("BRK_ANGLE", 1, ModePosHold, brake_angle_max_deg, POSHOLD_BRAKE_ANGLE_DEG_DEFAULT),
39+
40+
AP_GROUPEND
41+
};
42+
43+
// constructor
44+
ModePosHold::ModePosHold() : Mode()
45+
{
46+
// load parameter defaults
47+
AP_Param::setup_object_defaults(this, var_info);
48+
}
49+
50+
// convert parameters
51+
void ModePosHold::convert_params()
52+
{
53+
// PARAMETER_CONVERSION - Added: Feb 2026
54+
55+
// return immediately if parameter conversion has already been performed
56+
if (brake_angle_max_deg.configured()) {
57+
return;
58+
}
59+
60+
static const AP_Param::ConversionInfo conversion_info[] = {
61+
{ Parameters::k_param_poshold_brake_angle_max, 0, AP_PARAM_INT16, "PHLD_BRK_ANGLE" }, // PHLD_BRAKE_ANGLE moved to PHLD_BRK_ANGLE
62+
};
63+
AP_Param::convert_old_parameters_scaled(conversion_info, ARRAY_SIZE(conversion_info), 0.01, 0);
64+
}
65+
2466
// poshold_init - initialise PosHold controller
2567
bool ModePosHold::init(bool ignore_checks)
2668
{
@@ -293,7 +335,7 @@ void ModePosHold::run()
293335
// initialise BRAKE mode
294336
pitch_mode = RPMode::BRAKE; // set brake pitch mode
295337
brake.pitch_rad = 0.0f; // initialise braking angle to zero
296-
brake.angle_max_pitch_rad = 0.0f; // reset brake_angle_max so we can detect when vehicle begins to flatten out during braking
338+
brake.angle_max_pitch_rad = 0.0f; // reset brake_angle_max_deg so we can detect when vehicle begins to flatten out during braking
297339
brake.start_time_pitch_ms = now_ms; // timestamp (ms) marking the start of pitch-axis
298340
brake.time_updated_pitch = false; // flag the braking time can be re-estimated
299341
}
@@ -535,7 +577,7 @@ void ModePosHold::update_brake_angle_from_velocity(float &brake_angle_rad, float
535577
brake_angle_rad = constrain_float(lean_angle_rad, brake_angle_rad - brake_delta_rad, brake_angle_rad + brake_delta_rad);
536578

537579
// constrain final brake_angle
538-
const float brake_angle_max_rad = cd_to_rad(g.poshold_brake_angle_max);
580+
const float brake_angle_max_rad = radians(brake_angle_max_deg);
539581
brake_angle_rad = constrain_float(brake_angle_rad, -brake_angle_max_rad, brake_angle_max_rad);
540582
}
541583

0 commit comments

Comments
 (0)