Skip to content
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

launch: add launch specific idle throttle param #9471

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/modules/fw_pos_control_l1/FixedwingPositionControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ FixedwingPositionControl::control_position(const Vector2f &curr_pos, const Vecto
/* making sure again that the correct thrust is used,
* without depending on library calls for safety reasons.
the pre-takeoff throttle and the idle throttle normally map to the same parameter. */
_att_sp.thrust = _parameters.throttle_idle;
_att_sp.thrust = _launchDetector.getThrottleIdle(_parameters.throttle_idle);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically the pattern here is to pass the value you'd use in the non-launch detection case, and launch detector would return one or the other depending on if it's enabled.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is what is happening. Or do I miss something? (at least this is what I intended)

LaunchDetector.cpp#L128

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake, that looks correct.


} else if (_control_mode_current == FW_POSCTRL_MODE_AUTO &&
pos_sp_curr.type == position_setpoint_s::SETPOINT_TYPE_TAKEOFF &&
Expand All @@ -1078,7 +1078,8 @@ FixedwingPositionControl::control_position(const Vector2f &curr_pos, const Vecto

} else {
/* Copy thrust and pitch values from tecs */
if (_vehicle_land_detected.landed) {
if (_vehicle_land_detected.landed && !(_launch_detection_state == LAUNCHDETECTION_RES_DETECTED_ENABLEMOTORS
&& pos_sp_curr.type == position_setpoint_s::SETPOINT_TYPE_TAKEOFF)) {
// when we are landed state we want the motor to spin at idle speed
_att_sp.thrust = min(_parameters.throttle_idle, throttle_max);

Expand Down Expand Up @@ -1231,7 +1232,7 @@ FixedwingPositionControl::control_takeoff(const Vector2f &curr_pos, const Vector
float takeoff_throttle = _parameters.throttle_max;

if (_launch_detection_state != LAUNCHDETECTION_RES_DETECTED_ENABLEMOTORS) {
takeoff_throttle = _parameters.throttle_idle;
takeoff_throttle = _launchDetector.getThrottleIdle(_parameters.throttle_idle);
}

/* select maximum pitch: the launchdetector may impose another limit for the pitch
Expand Down Expand Up @@ -1820,7 +1821,9 @@ FixedwingPositionControl::tecs_update_pitch_throttle(float alt_sp, float airspee
_last_tecs_update = hrt_absolute_time();

// do not run TECS if we are not in air
bool run_tecs = !_vehicle_land_detected.landed;
bool run_tecs = !_vehicle_land_detected.landed || (_launch_detection_state == LAUNCHDETECTION_RES_DETECTED_ENABLEMOTORS
&& mode == tecs_status_s::TECS_MODE_TAKEOFF);
// handles case of land detected / launch detected interference during take-off

// do not run TECS if vehicle is a VTOL and we are in rotary wing mode or in transition
// (it should also not run during VTOL blending because airspeed is too low still)
Expand Down Expand Up @@ -1896,10 +1899,12 @@ FixedwingPositionControl::tecs_update_pitch_throttle(float alt_sp, float airspee
}

/* tell TECS to update its state, but let it know when it cannot actually control the plane */
bool in_air_alt_control = (!_vehicle_land_detected.landed &&
(_control_mode.flag_control_auto_enabled ||
_control_mode.flag_control_velocity_enabled ||
_control_mode.flag_control_altitude_enabled));
bool in_air_alt_control = ((!_vehicle_land_detected.landed ||
(_launch_detection_state == LAUNCHDETECTION_RES_DETECTED_ENABLEMOTORS
&& mode == tecs_status_s::TECS_MODE_TAKEOFF))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a mouthful, should we have a helper function? Same logic could be used for run_tecs above?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g. just an extra bool calculated directly above?

bool is_launching = _launch_detection_state == LAUNCHDETECTION_RES_DETECTED_ENABLEMOTORS && mode == tecs_status_s::TECS_MODE_TAKEOFF;
bool in_air_alt_control = !_vehicle_land_detected.landed || is_launching;

or do you mean an encapsulated function call?

bool in_air_alt_control = !_vehicle_land_detected.landed || is_launching();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first one is good, I'd say.

&& (_control_mode.flag_control_auto_enabled
|| _control_mode.flag_control_velocity_enabled
|| _control_mode.flag_control_altitude_enabled));

/* update TECS vehicle state estimates */
_tecs.update_vehicle_state_estimates(_airspeed, _R_nb,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,11 @@ float CatapultLaunchMethod::getPitchMax(float pitchMaxDefault)
}
}

float CatapultLaunchMethod::getThrottleIdle(float throttleIdleDefault)
{
// use operator defined launching idle (ignore default idle)
return _throttleIdle.get();
}


} // namespace launchdetection
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class CatapultLaunchMethod : public LaunchMethod, public ModuleParams
LaunchDetectionResult getLaunchDetected() const override;
void reset() override;
float getPitchMax(float pitchMaxDefault) override;
float getThrottleIdle(float throttleIdleDefault) override;

private:
hrt_abstime _last_timestamp{0};
Expand All @@ -71,9 +72,10 @@ class CatapultLaunchMethod : public LaunchMethod, public ModuleParams
(ParamFloat<px4::params::LAUN_CAT_A>) _thresholdAccel,
(ParamFloat<px4::params::LAUN_CAT_T>) _thresholdTime,
(ParamFloat<px4::params::LAUN_CAT_MDEL>) _motorDelay,
(ParamFloat<px4::params::LAUN_CAT_PMAX>) _pitchMaxPreThrottle /**< Upper pitch limit before throttle is turned on.
(ParamFloat<px4::params::LAUN_CAT_PMAX>) _pitchMaxPreThrottle, /**< Upper pitch limit before throttle is turned on.
Can be used to make sure that the AC does not climb
too much while attached to a bungee */
(ParamFloat<px4::params::LAUN_THR_IDLE>) _throttleIdle
)

};
Expand Down
21 changes: 21 additions & 0 deletions src/modules/fw_pos_control_l1/launchdetection/LaunchDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,25 @@ float LaunchDetector::getPitchMax(float pitchMaxDefault)
}
}

float LaunchDetector::getThrottleIdle(float throttleIdleDefault)
{
if (!launchDetectionEnabled()) {
return throttleIdleDefault;
}

/* if a lauchdetectionmethod is active or only one exists return the idle throttle from this method,
* otherwise use the default */
if (_activeLaunchDetectionMethodIndex < 0) {
if (sizeof(_launchMethods) / sizeof(LaunchMethod *) > 1) {
return throttleIdleDefault;

} else {
return _launchMethods[0]->getThrottleIdle(throttleIdleDefault);
}

} else {
return _launchMethods[_activeLaunchDetectionMethodIndex]->getThrottleIdle(throttleIdleDefault);
}
}

} // namespace launchdetection
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class __EXPORT LaunchDetector : public ModuleParams

/* Returns a maximum pitch in deg. Different launch methods may impose upper pitch limits during launch */
float getPitchMax(float pitchMaxDefault);
/* Returns an idle throttle specific to the pre- "motors enabled" launch detection phase */
float getThrottleIdle(float throttleIdleDefault);

private:
/* holds an index to the launchMethod in the array _launchMethods
Expand Down
2 changes: 2 additions & 0 deletions src/modules/fw_pos_control_l1/launchdetection/LaunchMethod.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class LaunchMethod

/* Returns a upper pitch limit if required, otherwise returns pitchMaxDefault */
virtual float getPitchMax(float pitchMaxDefault) = 0;
/* Returns an idle throttle specific to the pre- "motors enabled" launch detection phase */
virtual float getThrottleIdle(float throttleIdleDefault) = 0;

};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,14 @@ PARAM_DEFINE_FLOAT(LAUN_CAT_MDEL, 0.0f);
* @group FW Launch detection
*/
PARAM_DEFINE_FLOAT(LAUN_CAT_PMAX, 30.0f);

/**
* Idle throttle setting during launch detection before motors enabled.
*
* @min 0.0
* @max 1.0
* @decimal 2
* @increment 0.05
* @group FW Launch detection
*/
PARAM_DEFINE_FLOAT(LAUN_THR_IDLE, 0.0f);