Skip to content

Commit 4c9dba8

Browse files
sfuhrerbkueng
authored andcommitted
VTOL type and tiltrotor: use math::constrain() for constraining
Signed-off-by: Silvan Fuhrer <[email protected]>
1 parent e331079 commit 4c9dba8

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

src/modules/vtol_att_control/tiltrotor.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,7 @@ float Tiltrotor::thrust_compensation_for_tilt()
397397
{
398398

399399
// only compensate for tilt angle up to 0.5 * max tilt
400-
float compensated_tilt = _tilt_control;
401-
compensated_tilt = compensated_tilt < 0.0f ? 0.0f : compensated_tilt;
402-
compensated_tilt = compensated_tilt > 0.5f ? 0.5f : compensated_tilt;
400+
float compensated_tilt = math::constrain(_tilt_control, 0.0f, 0.5f);
403401

404402
// increase vertical thrust by 1/cos(tilt), limmit to [0,1]
405403
return math::constrain(_v_att_sp->thrust_body[2] / cosf(compensated_tilt * M_PI_2_F), 0.0f, 1.0f);

src/modules/vtol_att_control/vtol_type.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,7 @@ float VtolType::pusher_assist()
434434

435435
forward_thrust = (sinf(-pitch_down) - sinf(_params->down_pitch_max)) * _params->forward_thrust_scale;
436436
// limit forward actuation to [0, 0.9]
437-
forward_thrust = forward_thrust < 0.0f ? 0.0f : forward_thrust;
438-
forward_thrust = forward_thrust > 0.9f ? 0.9f : forward_thrust;
437+
forward_thrust = math::constrain(forward_thrust, 0.0f, 0.9f);
439438

440439
// return the vehicle to level position
441440
float pitch_new = 0.0f;

0 commit comments

Comments
 (0)