Skip to content

Commit 0588d5f

Browse files
RomanBapstJaeyoung-Lim
authored andcommitted
TECS: enable direct height-rate control
Signed-off-by: RomanBapst <[email protected]>
1 parent a81515f commit 0588d5f

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

src/lib/tecs/TECS.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,13 @@ void TECS::updateHeightRateSetpoint(float alt_sp_amsl_m, float target_climbrate_
201201
_hgt_rate_setpoint = math::constrain(_hgt_rate_setpoint, -_max_sink_rate, _max_climb_rate);
202202
}
203203

204+
void TECS::_update_height_rate_setpoint(float hgt_rate_sp)
205+
{
206+
// Limit the rate of change of height demand to respect vehicle performance limits
207+
_hgt_rate_setpoint = math::constrain(hgt_rate_sp, -_max_sink_rate, _max_climb_rate);
208+
_hgt_setpoint = _vert_pos_state;
209+
}
210+
204211
void TECS::_detect_underspeed()
205212
{
206213
if (!_detect_underspeed_enabled) {
@@ -510,7 +517,7 @@ void TECS::_update_STE_rate_lim()
510517
void TECS::update_pitch_throttle(float pitch, float baro_altitude, float hgt_setpoint,
511518
float EAS_setpoint, float equivalent_airspeed, float eas_to_tas, bool climb_out_setpoint, float pitch_min_climbout,
512519
float throttle_min, float throttle_max, float throttle_cruise, float pitch_limit_min, float pitch_limit_max,
513-
float target_climbrate, float target_sinkrate)
520+
float target_climbrate, float target_sinkrate, float hgt_rate_sp)
514521
{
515522
// Calculate the time since last update (seconds)
516523
uint64_t now = hrt_absolute_time();
@@ -548,8 +555,14 @@ void TECS::update_pitch_throttle(float pitch, float baro_altitude, float hgt_set
548555
// Calculate the demanded true airspeed
549556
_update_speed_setpoint();
550557

551-
// calculate heigh rate setpoint based on altitude demand
552-
updateHeightRateSetpoint(hgt_setpoint, target_climbrate, target_sinkrate, baro_altitude);
558+
if (PX4_ISFINITE(hgt_rate_sp)) {
559+
// use the provided height rate setpoint instead of the height setpoint
560+
_update_height_rate_setpoint(hgt_rate_sp);
561+
562+
} else {
563+
// calculate heigh rate setpoint based on altitude demand
564+
updateHeightRateSetpoint(hgt_setpoint, target_climbrate, target_sinkrate, baro_altitude);
565+
}
553566

554567
// Calculate the specific energy values required by the control loop
555568
_update_energy_estimates();

src/lib/tecs/TECS.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class TECS
8484
void update_pitch_throttle(float pitch, float baro_altitude, float hgt_setpoint,
8585
float EAS_setpoint, float equivalent_airspeed, float eas_to_tas, bool climb_out_setpoint, float pitch_min_climbout,
8686
float throttle_min, float throttle_setpoint_max, float throttle_cruise,
87-
float pitch_limit_min, float pitch_limit_max, float target_climbrate, float target_sinkrate);
87+
float pitch_limit_min, float pitch_limit_max, float target_climbrate, float target_sinkrate, float hgt_rate_sp = NAN);
8888

8989
float get_throttle_setpoint() { return _last_throttle_setpoint; }
9090
float get_pitch_setpoint() { return _last_pitch_setpoint; }
@@ -311,6 +311,11 @@ class TECS
311311
float alt_amsl);
312312

313313

314+
/**
315+
* Update the desired height rate setpoint
316+
*/
317+
void _update_height_rate_setpoint(float hgt_rate_sp);
318+
314319
/**
315320
* Detect if the system is not capable of maintaining airspeed
316321
*/

src/modules/fw_pos_control_l1/FixedwingPositionControl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,7 +2085,7 @@ FixedwingPositionControl::tecs_update_pitch_throttle(const hrt_abstime &now, flo
20852085
float pitch_min_rad, float pitch_max_rad,
20862086
float throttle_min, float throttle_max, float throttle_cruise,
20872087
bool climbout_mode, float climbout_pitch_min_rad,
2088-
uint8_t mode)
2088+
uint8_t mode, float hgt_rate_sp)
20892089
{
20902090
const float dt = math::constrain((now - _last_tecs_update) * 1e-6f, 0.01f, 0.05f);
20912091
_last_tecs_update = now;
@@ -2186,7 +2186,7 @@ FixedwingPositionControl::tecs_update_pitch_throttle(const hrt_abstime &now, flo
21862186
throttle_min, throttle_max, throttle_cruise,
21872187
pitch_min_rad - radians(_param_fw_psp_off.get()),
21882188
pitch_max_rad - radians(_param_fw_psp_off.get()),
2189-
_param_climbrate_target.get(), _param_sinkrate_target.get());
2189+
_param_climbrate_target.get(), _param_sinkrate_target.get(), hgt_rate_sp);
21902190

21912191
tecs_status_publish();
21922192
}

src/modules/fw_pos_control_l1/FixedwingPositionControl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ class FixedwingPositionControl final : public ModuleBase<FixedwingPositionContro
359359
float pitch_min_rad, float pitch_max_rad,
360360
float throttle_min, float throttle_max, float throttle_cruise,
361361
bool climbout_mode, float climbout_pitch_min_rad,
362-
uint8_t mode = tecs_status_s::TECS_MODE_NORMAL);
362+
uint8_t mode = tecs_status_s::TECS_MODE_NORMAL, float hgt_rate_sp = NAN);
363363

364364
DEFINE_PARAMETERS(
365365

0 commit comments

Comments
 (0)