Browse Source

clang-tidy: enable readability-simplify-boolean-expr and fix

sbg
Daniel Agar 5 years ago
parent
commit
967446af4c
  1. 1
      .clang-tidy
  2. 6
      platforms/posix/src/px4/common/main.cpp
  3. 18
      src/lib/FlightTasks/tasks/Auto/FlightTaskAuto.cpp
  4. 2
      src/lib/FlightTasks/tasks/Utility/ObstacleAvoidance.cpp
  5. 2
      src/lib/hysteresis/hysteresis.cpp
  6. 2
      src/lib/parameters/parameters.cpp
  7. 2
      src/lib/rc/dsm.cpp
  8. 2
      src/lib/terrain_estimation/terrain_estimator.cpp
  9. 6
      src/modules/commander/Commander.cpp
  10. 20
      src/modules/commander/PreflightCheck.cpp
  11. 23
      src/modules/land_detector/MulticopterLandDetector.cpp
  12. 6
      src/modules/land_detector/RoverLandDetector.cpp
  13. 4
      src/modules/navigator/follow_target.cpp
  14. 52
      src/modules/navigator/mission_feasibility_checker.cpp
  15. 2
      src/modules/vtol_att_control/standard.cpp

1
.clang-tidy

@ -99,7 +99,6 @@ Checks: '*,
-readability-redundant-control-flow, -readability-redundant-control-flow,
-readability-redundant-declaration, -readability-redundant-declaration,
-readability-redundant-member-init, -readability-redundant-member-init,
-readability-simplify-boolean-expr,
-readability-static-accessed-through-instance, -readability-static-accessed-through-instance,
-readability-static-definition-in-anonymous-namespace, -readability-static-definition-in-anonymous-namespace,
' '

6
platforms/posix/src/px4/common/main.cpp

@ -590,11 +590,7 @@ bool is_already_running(int instance)
if (fcntl(fd, F_SETLK, &fl) == -1) { if (fcntl(fd, F_SETLK, &fl) == -1) {
// We failed to create a file lock, must be already locked. // We failed to create a file lock, must be already locked.
if (errno == EACCES || errno == EAGAIN) { return errno == EACCES || errno == EAGAIN;
return true;
}
return false;
} }
errno = 0; errno = 0;

18
src/lib/FlightTasks/tasks/Auto/FlightTaskAuto.cpp

@ -354,8 +354,8 @@ bool FlightTaskAuto::_evaluateGlobalReference()
return true; return true;
} }
double ref_lat = _sub_vehicle_local_position.get().ref_lat; double ref_lat = _sub_vehicle_local_position.get().ref_lat;
double ref_lon = _sub_vehicle_local_position.get().ref_lon; double ref_lon = _sub_vehicle_local_position.get().ref_lon;
_reference_altitude = _sub_vehicle_local_position.get().ref_alt; _reference_altitude = _sub_vehicle_local_position.get().ref_alt;
if (!_sub_vehicle_local_position.get().z_global) { if (!_sub_vehicle_local_position.get().z_global) {
@ -372,20 +372,10 @@ bool FlightTaskAuto::_evaluateGlobalReference()
} }
// init projection // init projection
map_projection_init(&_reference_position, map_projection_init(&_reference_position, ref_lat, ref_lon);
ref_lat,
ref_lon);
// check if everything is still finite // check if everything is still finite
if (PX4_ISFINITE(_reference_altitude) return PX4_ISFINITE(_reference_altitude) && PX4_ISFINITE(ref_lat) && PX4_ISFINITE(ref_lon);
&& PX4_ISFINITE(_sub_vehicle_local_position.get().ref_lat)
&& PX4_ISFINITE(_sub_vehicle_local_position.get().ref_lon)) {
return true;
} else {
// no valid reference
return false;
}
} }
void FlightTaskAuto::_setDefaultConstraints() void FlightTaskAuto::_setDefaultConstraints()

2
src/lib/FlightTasks/tasks/Utility/ObstacleAvoidance.cpp

@ -70,7 +70,7 @@ void ObstacleAvoidance::injectAvoidanceSetpoints(Vector3f &pos_sp, Vector3f &vel
const bool avoidance_data_timeout = hrt_elapsed_time((hrt_abstime *)&_sub_vehicle_trajectory_waypoint.get().timestamp) const bool avoidance_data_timeout = hrt_elapsed_time((hrt_abstime *)&_sub_vehicle_trajectory_waypoint.get().timestamp)
> TRAJECTORY_STREAM_TIMEOUT_US; > TRAJECTORY_STREAM_TIMEOUT_US;
const bool avoidance_point_valid = const bool avoidance_point_valid =
_sub_vehicle_trajectory_waypoint.get().waypoints[vehicle_trajectory_waypoint_s::POINT_0].point_valid == true; _sub_vehicle_trajectory_waypoint.get().waypoints[vehicle_trajectory_waypoint_s::POINT_0].point_valid;
_avoidance_point_not_valid_hysteresis.set_state_and_update(!avoidance_point_valid, hrt_absolute_time()); _avoidance_point_not_valid_hysteresis.set_state_and_update(!avoidance_point_valid, hrt_absolute_time());

2
src/lib/hysteresis/hysteresis.cpp

@ -45,7 +45,7 @@ namespace systemlib
void void
Hysteresis::set_hysteresis_time_from(const bool from_state, const hrt_abstime new_hysteresis_time_us) Hysteresis::set_hysteresis_time_from(const bool from_state, const hrt_abstime new_hysteresis_time_us)
{ {
if (from_state == true) { if (from_state) {
_time_from_true_us = new_hysteresis_time_us; _time_from_true_us = new_hysteresis_time_us;
} else { } else {

2
src/lib/parameters/parameters.cpp

@ -501,7 +501,7 @@ param_value_is_default(param_t param)
param_lock_reader(); param_lock_reader();
s = param_find_changed(param); s = param_find_changed(param);
param_unlock_reader(); param_unlock_reader();
return s ? false : true; return s == nullptr;
} }
bool bool

2
src/lib/rc/dsm.cpp

@ -712,7 +712,7 @@ dsm_parse(const uint64_t now, const uint8_t *frame, const unsigned len, uint16_t
dsm_partial_frame_count = 0; dsm_partial_frame_count = 0;
/* if decoding failed, set proto to desync */ /* if decoding failed, set proto to desync */
if (decode_ret == false) { if (!decode_ret) {
dsm_decode_state = DSM_DECODE_STATE_DESYNC; dsm_decode_state = DSM_DECODE_STATE_DESYNC;
dsm_frame_drops++; dsm_frame_drops++;
} }

2
src/lib/terrain_estimation/terrain_estimator.cpp

@ -186,7 +186,7 @@ void TerrainEstimator::measurement_update(uint64_t time_ref, const struct vehicl
} }
if (reinit) { if (reinit) {
memset(&_x._data[0], 0, sizeof(_x._data)); _x.zero();
_P.setZero(); _P.setZero();
_P(0, 0) = _P(1, 1) = _P(2, 2) = 0.1f; _P(0, 0) = _P(1, 1) = _P(2, 2) = 0.1f;
} }

6
src/modules/commander/Commander.cpp

@ -1983,16 +1983,14 @@ Commander::run()
/* handle the case where RC signal was regained */ /* handle the case where RC signal was regained */
if (!status_flags.rc_signal_found_once) { if (!status_flags.rc_signal_found_once) {
status_flags.rc_signal_found_once = true; status_flags.rc_signal_found_once = true;
set_health_flags(subsystem_info_s::SUBSYSTEM_TYPE_RCRECEIVER, true, true, true set_health_flags(subsystem_info_s::SUBSYSTEM_TYPE_RCRECEIVER, true, true, status_flags.rc_calibration_valid, status);
&& status_flags.rc_calibration_valid, status);
status_changed = true; status_changed = true;
} else { } else {
if (status.rc_signal_lost) { if (status.rc_signal_lost) {
mavlink_log_info(&mavlink_log_pub, "Manual control regained after %llums", mavlink_log_info(&mavlink_log_pub, "Manual control regained after %llums",
hrt_elapsed_time(&rc_signal_lost_timestamp) / 1000); hrt_elapsed_time(&rc_signal_lost_timestamp) / 1000);
set_health_flags(subsystem_info_s::SUBSYSTEM_TYPE_RCRECEIVER, true, true, true set_health_flags(subsystem_info_s::SUBSYSTEM_TYPE_RCRECEIVER, true, true, status_flags.rc_calibration_valid, status);
&& status_flags.rc_calibration_valid, status);
status_changed = true; status_changed = true;
} }
} }

20
src/modules/commander/PreflightCheck.cpp

@ -868,7 +868,7 @@ bool preflightCheck(orb_advert_t *mavlink_log_pub, vehicle_status_s &status, veh
/* ---- BARO ---- */ /* ---- BARO ---- */
if (checkSensors) { if (checkSensors) {
bool prime_found = false; //bool prime_found = false;
int32_t prime_id = -1; int32_t prime_id = -1;
param_get(param_find("CAL_BARO_PRIME"), &prime_id); param_get(param_find("CAL_BARO_PRIME"), &prime_id);
@ -887,7 +887,7 @@ bool preflightCheck(orb_advert_t *mavlink_log_pub, vehicle_status_s &status, veh
if (baroCheck(mavlink_log_pub, status, i, !required, device_id, report_fail)) { if (baroCheck(mavlink_log_pub, status, i, !required, device_id, report_fail)) {
if ((prime_id > 0) && (device_id == prime_id)) { if ((prime_id > 0) && (device_id == prime_id)) {
prime_found = true; //prime_found = true;
} }
} else { } else {
@ -900,14 +900,14 @@ bool preflightCheck(orb_advert_t *mavlink_log_pub, vehicle_status_s &status, veh
// TODO there is no logic in place to calibrate the primary baro yet // TODO there is no logic in place to calibrate the primary baro yet
// // check if the primary device is present // // check if the primary device is present
if (!prime_found && false) { // if (false) {
if (reportFailures && !failed) { // if (reportFailures && !failed) {
mavlink_log_critical(mavlink_log_pub, "Primary barometer not operational"); // mavlink_log_critical(mavlink_log_pub, "Primary barometer not operational");
} // }
set_health_flags(subsystem_info_s::SUBSYSTEM_TYPE_ABSPRESSURE, false, true, false, status); // set_health_flags(subsystem_info_s::SUBSYSTEM_TYPE_ABSPRESSURE, false, true, false, status);
failed = true; // failed = true;
} // }
} }
/* ---- IMU CONSISTENCY ---- */ /* ---- IMU CONSISTENCY ---- */

23
src/modules/land_detector/MulticopterLandDetector.cpp

@ -165,12 +165,8 @@ bool MulticopterLandDetector::_get_ground_contact_state()
bool hit_ground = _in_descend && !vertical_movement; bool hit_ground = _in_descend && !vertical_movement;
// TODO: we need an accelerometer based check for vertical movement for flying without GPS // TODO: we need an accelerometer based check for vertical movement for flying without GPS
if ((_has_low_thrust() || hit_ground) && (!_horizontal_movement || !_has_position_lock()) return (_has_low_thrust() || hit_ground) && (!_horizontal_movement || !_has_position_lock())
&& (!vertical_movement || !_has_altitude_lock())) { && (!vertical_movement || !_has_altitude_lock());
return true;
}
return false;
} }
bool MulticopterLandDetector::_get_maybe_landed_state() bool MulticopterLandDetector::_get_maybe_landed_state()
@ -215,12 +211,8 @@ bool MulticopterLandDetector::_get_maybe_landed_state()
return (_min_trust_start > 0) && (hrt_elapsed_time(&_min_trust_start) > 8_s); return (_min_trust_start > 0) && (hrt_elapsed_time(&_min_trust_start) > 8_s);
} }
if (_ground_contact_hysteresis.get_state() && _has_minimal_thrust() && !rotating) { // Ground contact, no thrust and no movement -> landed
// Ground contact, no thrust and no movement -> landed return _ground_contact_hysteresis.get_state() && _has_minimal_thrust() && !rotating;
return true;
}
return false;
} }
bool MulticopterLandDetector::_get_landed_state() bool MulticopterLandDetector::_get_landed_state()
@ -318,12 +310,7 @@ bool MulticopterLandDetector::_has_minimal_thrust()
bool MulticopterLandDetector::_get_ground_effect_state() bool MulticopterLandDetector::_get_ground_effect_state()
{ {
if (_in_descend && !_horizontal_movement) { return _in_descend && !_horizontal_movement;
return true;
} else {
return false;
}
} }
} // namespace land_detector } // namespace land_detector

6
src/modules/land_detector/RoverLandDetector.cpp

@ -51,11 +51,7 @@ bool RoverLandDetector::_get_ground_contact_state()
bool RoverLandDetector::_get_landed_state() bool RoverLandDetector::_get_landed_state()
{ {
if (!_actuator_armed.armed) { return !_actuator_armed.armed;
return true;
}
return false;
} }
} // namespace land_detector } // namespace land_detector

4
src/modules/navigator/follow_target.cpp

@ -240,7 +240,7 @@ void FollowTarget::on_active()
case TRACK_POSITION: { case TRACK_POSITION: {
if (_radius_entered == true) { if (_radius_entered) {
_follow_target_state = TRACK_VELOCITY; _follow_target_state = TRACK_VELOCITY;
} else if (target_velocity_valid()) { } else if (target_velocity_valid()) {
@ -259,7 +259,7 @@ void FollowTarget::on_active()
case TRACK_VELOCITY: { case TRACK_VELOCITY: {
if (_radius_exited == true) { if (_radius_exited) {
_follow_target_state = TRACK_POSITION; _follow_target_state = TRACK_POSITION;
} else if (target_velocity_valid()) { } else if (target_velocity_valid()) {

52
src/modules/navigator/mission_feasibility_checker.cpp

@ -352,35 +352,29 @@ MissionFeasibilityChecker::checkTakeoff(const mission_s &mission, float home_alt
return false; return false;
} }
if (missionitem.nav_cmd != NAV_CMD_IDLE && takeoff_first = !(missionitem.nav_cmd != NAV_CMD_IDLE &&
missionitem.nav_cmd != NAV_CMD_DELAY && missionitem.nav_cmd != NAV_CMD_DELAY &&
missionitem.nav_cmd != NAV_CMD_DO_JUMP && missionitem.nav_cmd != NAV_CMD_DO_JUMP &&
missionitem.nav_cmd != NAV_CMD_DO_CHANGE_SPEED && missionitem.nav_cmd != NAV_CMD_DO_CHANGE_SPEED &&
missionitem.nav_cmd != NAV_CMD_DO_SET_HOME && missionitem.nav_cmd != NAV_CMD_DO_SET_HOME &&
missionitem.nav_cmd != NAV_CMD_DO_SET_SERVO && missionitem.nav_cmd != NAV_CMD_DO_SET_SERVO &&
missionitem.nav_cmd != NAV_CMD_DO_LAND_START && missionitem.nav_cmd != NAV_CMD_DO_LAND_START &&
missionitem.nav_cmd != NAV_CMD_DO_TRIGGER_CONTROL && missionitem.nav_cmd != NAV_CMD_DO_TRIGGER_CONTROL &&
missionitem.nav_cmd != NAV_CMD_DO_DIGICAM_CONTROL && missionitem.nav_cmd != NAV_CMD_DO_DIGICAM_CONTROL &&
missionitem.nav_cmd != NAV_CMD_IMAGE_START_CAPTURE && missionitem.nav_cmd != NAV_CMD_IMAGE_START_CAPTURE &&
missionitem.nav_cmd != NAV_CMD_IMAGE_STOP_CAPTURE && missionitem.nav_cmd != NAV_CMD_IMAGE_STOP_CAPTURE &&
missionitem.nav_cmd != NAV_CMD_VIDEO_START_CAPTURE && missionitem.nav_cmd != NAV_CMD_VIDEO_START_CAPTURE &&
missionitem.nav_cmd != NAV_CMD_VIDEO_STOP_CAPTURE && missionitem.nav_cmd != NAV_CMD_VIDEO_STOP_CAPTURE &&
missionitem.nav_cmd != NAV_CMD_DO_MOUNT_CONFIGURE && missionitem.nav_cmd != NAV_CMD_DO_MOUNT_CONFIGURE &&
missionitem.nav_cmd != NAV_CMD_DO_MOUNT_CONTROL && missionitem.nav_cmd != NAV_CMD_DO_MOUNT_CONTROL &&
missionitem.nav_cmd != NAV_CMD_DO_SET_ROI && missionitem.nav_cmd != NAV_CMD_DO_SET_ROI &&
missionitem.nav_cmd != NAV_CMD_DO_SET_ROI_LOCATION && missionitem.nav_cmd != NAV_CMD_DO_SET_ROI_LOCATION &&
missionitem.nav_cmd != NAV_CMD_DO_SET_ROI_WPNEXT_OFFSET && missionitem.nav_cmd != NAV_CMD_DO_SET_ROI_WPNEXT_OFFSET &&
missionitem.nav_cmd != NAV_CMD_DO_SET_ROI_NONE && missionitem.nav_cmd != NAV_CMD_DO_SET_ROI_NONE &&
missionitem.nav_cmd != NAV_CMD_DO_SET_CAM_TRIGG_DIST && missionitem.nav_cmd != NAV_CMD_DO_SET_CAM_TRIGG_DIST &&
missionitem.nav_cmd != NAV_CMD_DO_SET_CAM_TRIGG_INTERVAL && missionitem.nav_cmd != NAV_CMD_DO_SET_CAM_TRIGG_INTERVAL &&
missionitem.nav_cmd != NAV_CMD_SET_CAMERA_MODE && missionitem.nav_cmd != NAV_CMD_SET_CAMERA_MODE &&
missionitem.nav_cmd != NAV_CMD_DO_VTOL_TRANSITION) { missionitem.nav_cmd != NAV_CMD_DO_VTOL_TRANSITION);
takeoff_first = false;
} else {
takeoff_first = true;
}
} }
} }

2
src/modules/vtol_att_control/standard.cpp

@ -127,7 +127,7 @@ void Standard::update_vtol_state()
} else if (_vtol_schedule.flight_mode == vtol_mode::FW_MODE) { } else if (_vtol_schedule.flight_mode == vtol_mode::FW_MODE) {
// transition to mc mode // transition to mc mode
if (_vtol_vehicle_status->vtol_transition_failsafe == true) { if (_vtol_vehicle_status->vtol_transition_failsafe) {
// Failsafe event, engage mc motors immediately // Failsafe event, engage mc motors immediately
_vtol_schedule.flight_mode = vtol_mode::MC_MODE; _vtol_schedule.flight_mode = vtol_mode::MC_MODE;
_pusher_throttle = 0.0f; _pusher_throttle = 0.0f;

Loading…
Cancel
Save