-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ArduPlane: convert parameter TRIM_PITCH_CD to TRIM_PITCH_DEG #25768
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tend to think were better off adding the new params to the end of the g2 group rather than trying to squeeze them in the base table.
Re TRIM_PITCH vs PITCH_TRIM, I think it depends upon whether you think of the trim as a feature or not. My guess is that it should remain TRIM_PITCH, TRIM_ROLL and TRIM_YAW (or whatever). |
Yes that's very deliberate. I definitely want to have all the PITCH_ stuff show up together rather than grouping by TRIM as it is now, which I find counterintuitive. It also matches the variable name in the code! Very interested in other peoples thoughts. |
There is also an aparam.pitch_trim_cd, but I can't figure out where it gets set. (there is no ASCALAR); It looks like this might be a bug, introduced in this PR #22191 - these changes will fix the bug. |
libraries/AP_TECS/AP_TECS.cpp
Outdated
@@ -849,7 +849,7 @@ void AP_TECS::_update_throttle_without_airspeed(int16_t throttle_nudge) | |||
_pitch_demand_lpf.apply(_pitch_dem, _DT); | |||
const float pitch_demand_hpf = _pitch_dem - _pitch_demand_lpf.get(); | |||
_pitch_measured_lpf.apply(_ahrs.pitch, _DT); | |||
const float pitch_corrected_lpf = _pitch_measured_lpf.get() - radians(0.01f * (float)aparm.pitch_trim_cd); | |||
const float pitch_corrected_lpf = _pitch_measured_lpf.get() - radians(aparm.pitch_trim); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the old method was broken this is a change in behavior that will need testing.
I can't figure out how to make this a g2 parameter now it's in aparm. Is there an equivalent g2 macro to ASCALAR? OTOH- the base table is already > 256 elements, so does it really matter? |
ArduPlane/Parameters.cpp
Outdated
// @Units: deg | ||
// @Range: -45 45 | ||
// @User: Standard | ||
ASCALAR(pitch_trim, "PITCH_TRIM", 0.0f), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would greatly prefer TRIM_PITCH_DEG so users looking for the old parameter can find the new one easily
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought part of the point of getting rid of the "CD" was that the units are already in the metadata, adding _DEG is inconsistent with any other parameter usage and will cost 4 characters without adding any value. Users can easily find the parameter by typing "TRIM" or "PITCH" in the search box.
See also this comment in the related issue: #23580 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh and I just noticed this comment in the related issue - maybe it would be better to use PTCH because it's the most consistently used tag for "pitch" which often needs to be abbreviated. Right now it appears as PITCH, PTCH and PIT
#23580 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with Tim, I don't think we need to add deg for si units. Adding deg also sets up a pattern we may not be able to follow as deg is one character longer than cd.
We could add a magnitude arming check, anything above say 10 we could assume the user copied the cd value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that shouldn't stop us adding _DEG when we can. It will save users a lot of pain and most params can get the _DEG
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are already at least 13 PITCH parameters that are in degrees, but do NOT have "DEG" in the name. Not to mention all the YAW and ROLL parameters that are in degrees with no "DEG" at the end. I can only find one parameter in plane with _DEG at the end (LAND_ABORT_DEG), whereas there are dozens with degrees as their @units
.
IMO it's inconsistency that is most painful to users, and again - it's in the metadata, which is displayed in both Mission Planner and QGroundControl.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed this one: Q_TRIM_PITCH: Quadplane AHRS trim pitch (in degrees, no _DEG) so TRIM_PITCH would be consistent with this. without it we will have
- TRIM_PITCH_DEG (in degrees)
- Q_TRIM_PITCH (in degrees)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok - I get it _DEG is necessary. So I've reworked this now.
ArduPlane/Parameters.cpp
Outdated
// PARAMETER_CONVERSION - Added: Dec 2023 | ||
// Convert _CM (centimeter) parameters to meters and _CD (centidegrees) parameters to meters | ||
{ | ||
const AP_Param::ConversionInfo centimeters_conversion_info[] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to create a special method for this in AP_Param, so we can do:
myparam.convert_centi_parameter();
and it is done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really. That way you have to make multiple calls one for each parameter. This way you can pass in a whole table of parameters using the existing function - which is what I'm expecting next ...
const AP_Param::ConversionInfo centimeters_conversion_info[] {
{ Parameters::k_param_pitch_trim_cd_old, 0, AP_PARAM_INT16, "PITCH_TRIM" },
{ Parameters::k_param_lim_pitch_max_cd_old, 0, AP_PARAM_INT16, "PITCH_LIM_MAX" },
{ Parameters::k_param_lim_pitch_min_cd_old, 0, AP_PARAM_INT16, "PITCH_LIM_MIN" },
{ Parameters::k_param_lim_roll_old, 0, AP_PARAM_INT16, "ROLL_LIM" },
{ Parameters::k_param_airspeed_cruise_old, 0, AP_PARAM_INT16, "AIRSPEED_CRUISE" },
};
AP_Param::convert_old_parameters_scaled(¢imeters_conversion_info[0], ARRAY_SIZE(centimeters_conversion_info), 0.01f, 0);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to create a special method for this in AP_Param, so we can do: myparam.convert_centi_parameter(); and it is done
I took a stab at it by copying the existing convert_parameter_width() method in AP_Param, it seems to work, but it's very low level so I wonder if you could take a look. I had to pass in the old type to get it to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested in SITL
we don't need to move them at all, they can keep the same ID |
I think this is as close to what tridge wanted, based on today's discussion: ( $ means end-of-string) PLANE , RNGFND1_MIN_CM, LEN, 14, newname, RNGFND1_MIN_M, newlen, 13, |
as discussed, the above list also doesn't include params that have centimeters in them, but don't end in _CM ... those are available here: |
b06dd5a
to
cdfd337
Compare
This was force-pushed, so just noting that it still isn't aligned with the renaming that tridge said he prefers in the dev call. TRIM_PITCH_CD => TRIM_PITCH_DEG , so I suspect it won't be mergable. |
I was a bit premature with my push, I need to do more testing. |
0333e42
to
947d90c
Compare
@timtuxworth I've rebased and cleaned this up for TRIM_PITCH_DEG |
Thanks @tridge this looks much cleaner. I think the only thing left are a few .param files so the CI will pass. |
947d90c
to
5f308bb
Compare
5f308bb
to
1760e51
Compare
replaced by #26025 |
There is a target to do some refactoring of parameters in the 4.5 release. This is mostly about targeting removing the use of centi-degrees and centimeters in favour of degrees and meters as well as some other parameter cleanups. There is a list documented in this issue: #23580 (comment)
The parameter TRIM_PITCH_CD uses centi degrees. This PR is would replace that with TRIM_PITCH_DEG in degrees.
I understand now why _DEG is important. Not so much for this parameter, but for other parameters (e.g. Q_ANGLE_MAX) which are in "centi" units but don't have a suffix now, so if we just changed them in situ it would be very dangerously easy to set a new Q_ANGLE_MAX in centi-degrees without realizing it was now degrees. So the only safe way to do this is:
This PR refactors all the uses of pitch_trim_cd to use pitch_trim scaled down by 100, which almost always simplifies the code and removes floating point operations, since the code needed degrees anyway.
I've added the suggestion from Tridge to create a generic convert_centi_parameter() method on parameters which I copied from some previous code. It does work, but I don't totally understand what it's doing, so please check my work on this.