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
AP_Motors: Add multicopter thrust slew limit #9929
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
#define AP_MOTORS_BAT_CURR_MAX_DEFAULT 0.0f // current limiting max default | ||
#define AP_MOTORS_BAT_CURR_TC_DEFAULT 5.0f // Time constant used to limit the maximum current | ||
#define AP_MOTORS_BATT_VOLT_FILT_HZ 0.5f // battery voltage filtered at 0.5hz | ||
#define AP_MOTORS_SLEW_TIME_DEFAULT 0.0f // slew rate limit for thrust output | ||
|
||
// spool definition | ||
#define AP_MOTORS_SPOOL_UP_TIME_DEFAULT 0.5f // time (in seconds) for throttle to increase from zero to min throttle, and min throttle to full throttle. | ||
|
@@ -90,7 +91,7 @@ class AP_MotorsMulticopter : public AP_Motors { | |
|
||
// var_info for holding Parameter information | ||
static const struct AP_Param::GroupInfo var_info[]; | ||
|
||
protected: | ||
|
||
// run spool logic | ||
|
@@ -114,11 +115,17 @@ class AP_MotorsMulticopter : public AP_Motors { | |
// return gain scheduling gain based on voltage and air density | ||
float get_compensation_gain() const; | ||
|
||
// convert thrust (0~1) range back to pwm range | ||
int16_t calc_thrust_to_pwm(float thrust_in) const; | ||
// convert actuator output (0~1) range to pwm range | ||
int16_t output_to_pwm(float _actuator_output); | ||
|
||
// converts desired thrust to linearized actuator output in a range of 0~1 | ||
float thrust_to_actuator(float thrust_in); | ||
|
||
// adds slew rate limiting to actuator output if MOT_SLEW_TIME > 0 and not shutdown | ||
void set_actuator_with_slew(float& actuator_output, float input); | ||
|
||
// calculate spin up to pwm range | ||
int16_t calc_spin_up_to_pwm() const; | ||
// gradually increase actuator output maximum limit | ||
float actuator_spin_up() const; | ||
|
||
// apply any thrust compensation for the frame | ||
virtual void thrust_compensation(void) {} | ||
|
@@ -127,7 +134,7 @@ class AP_MotorsMulticopter : public AP_Motors { | |
virtual void output_boost_throttle(void); | ||
|
||
// save parameters as part of disarming | ||
void save_params_on_disarm() override; | ||
void save_params_on_disarm() override; | ||
|
||
// enum values for HOVER_LEARN parameter | ||
enum HoverLearn { | ||
|
@@ -139,9 +146,11 @@ class AP_MotorsMulticopter : public AP_Motors { | |
// parameters | ||
AP_Int16 _yaw_headroom; // yaw control is given at least this pwm range | ||
AP_Float _thrust_curve_expo; // curve used to linearize pwm to thrust conversion. set to 0 for linear and 1 for second order approximation | ||
AP_Float _spin_min; // throttle out ratio which produces the minimum thrust. (i.e. 0 ~ 1 ) of the full throttle range | ||
AP_Float _spin_max; // throttle out ratio which produces the maximum thrust. (i.e. 0 ~ 1 ) of the full throttle range | ||
AP_Float _spin_arm; // throttle out ratio which produces the armed spin rate. (i.e. 0 ~ 1 ) of the full throttle range | ||
AP_Float _slew_up_time; // throttle increase slew limitting | ||
AP_Float _slew_dn_time; // throttle decrease slew limitting | ||
AP_Float _spin_min; // throttle out ratio which produces the minimum thrust. (i.e. 0 ~ 1 ) of the full throttle range | ||
AP_Float _spin_max; // throttle out ratio which produces the maximum thrust. (i.e. 0 ~ 1 ) of the full throttle range | ||
AP_Float _spin_arm; // throttle out ratio which produces the armed spin rate. (i.e. 0 ~ 1 ) of the full throttle range | ||
AP_Float _batt_voltage_max; // maximum voltage used to scale lift | ||
AP_Float _batt_voltage_min; // minimum voltage used to scale lift | ||
AP_Float _batt_current_max; // current over which maximum throttle is limited | ||
|
@@ -166,6 +175,7 @@ class AP_MotorsMulticopter : public AP_Motors { | |
bool motor_enabled[AP_MOTORS_MAX_NUM_MOTORS]; // true if motor is enabled | ||
int16_t _throttle_radio_min; // minimum PWM from RC input's throttle channel (i.e. minimum PWM input from receiver, RC3_MIN) | ||
int16_t _throttle_radio_max; // maximum PWM from RC input's throttle channel (i.e. maximum PWM input from receiver, RC3_MAX) | ||
// spool variables | ||
|
||
// spool variables | ||
float _spin_up_ratio; // throttle percentage (0 ~ 1) between zero and throttle_min | ||
|
@@ -179,4 +189,7 @@ class AP_MotorsMulticopter : public AP_Motors { | |
|
||
// vehicle supplied callback for thrust compensation. Used for tiltrotors and tiltwings | ||
thrust_compensation_fn_t _thrust_compensation_callback; | ||
|
||
// array of motor output values | ||
float _actuator[AP_MOTORS_MAX_NUM_MOTORS]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it would be good to add a comment re what's held in this array |
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 wonder if we could come up with a more easily understood name and/or comment for the "actuator_spin_up()" function. maybe it's "actuator_spin_up_to_ground_idle()". That's a bit long but "spin_up" alone doesn't really clarify that it's only spinning up to ground-idle. the comment as it is might make future developers think it spins up to throttle-unlimited.