From c177d6491a40cb841f7db9cb08bf2274009c86b8 Mon Sep 17 00:00:00 2001 From: Matthias Grob Date: Fri, 6 Oct 2017 10:49:43 +0200 Subject: [PATCH] mc_pos_control: simplify unnecessary complicated boolean conditions --- .../mc_pos_control/mc_pos_control_main.cpp | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/modules/mc_pos_control/mc_pos_control_main.cpp b/src/modules/mc_pos_control/mc_pos_control_main.cpp index 084db316c0..a5d30e86c5 100644 --- a/src/modules/mc_pos_control/mc_pos_control_main.cpp +++ b/src/modules/mc_pos_control/mc_pos_control_main.cpp @@ -809,22 +809,14 @@ MulticopterPositionControl::poll_subscriptions() /* we need either a valid position setpoint or a valid velocity setpoint */ - if (PX4_ISFINITE(_pos_sp_triplet.current.lat) && PX4_ISFINITE(_pos_sp_triplet.current.lon) - && PX4_ISFINITE(_pos_sp_triplet.current.alt) && _pos_sp_triplet.current.valid) { - _pos_sp_triplet.current.valid = true; - } else if (PX4_ISFINITE(_pos_sp_triplet.current.alt) && _pos_sp_triplet.current.valid) { - _pos_sp_triplet.current.valid = true; - - } else { + if (!PX4_ISFINITE(_pos_sp_triplet.current.alt)) { _pos_sp_triplet.current.valid = false; } - if (PX4_ISFINITE(_pos_sp_triplet.previous.lat) && PX4_ISFINITE(_pos_sp_triplet.previous.lon) - && PX4_ISFINITE(_pos_sp_triplet.previous.alt) && _pos_sp_triplet.previous.valid) { - _pos_sp_triplet.previous.valid = true; - - } else { + if (!PX4_ISFINITE(_pos_sp_triplet.previous.lat) || + !PX4_ISFINITE(_pos_sp_triplet.previous.lon) || + !PX4_ISFINITE(_pos_sp_triplet.previous.alt)) { _pos_sp_triplet.previous.valid = false; } } @@ -3132,10 +3124,12 @@ MulticopterPositionControl::task_main() * attitude setpoints for the transition). * - if not armed */ - if (_control_mode.flag_armed && (!(_control_mode.flag_control_offboard_enabled && - !(_control_mode.flag_control_position_enabled || - _control_mode.flag_control_velocity_enabled || - _control_mode.flag_control_acceleration_enabled)))) { + + if (_control_mode.flag_armed && + (!(_control_mode.flag_control_offboard_enabled && + !(_control_mode.flag_control_position_enabled || + _control_mode.flag_control_velocity_enabled || + _control_mode.flag_control_acceleration_enabled)))) { if (_att_sp_pub != nullptr) { orb_publish(_attitude_setpoint_id, _att_sp_pub, &_att_sp);