Skip to content

Commit

Permalink
Updated code style to fix confusing if conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
Timothy Scott authored and julianoes committed Jun 13, 2019
1 parent a134da6 commit 714c90b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
3 changes: 1 addition & 2 deletions msg/vehicle_status.msg
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ uint8 system_type # system type, contains mavlink MAV_TYPE
uint8 system_id # system id, contains MAVLink's system ID field
uint8 component_id # subsystem / component id, contains MAVLink's component ID field

#bool is_rotary_wing # True if system is in rotary wing configuration, so for a VTOL this is only true while flying as a multicopter
uint8 vehicle_type
uint8 vehicle_type # Type of vehicle (fixed-wing, rotary wing, ground)

bool is_vtol # True if the system is VTOL capable
bool vtol_fw_permanent_stab # True if VTOL should stabilize attitude for fw in manual mode
Expand Down
18 changes: 13 additions & 5 deletions src/modules/commander/Commander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1407,14 +1407,18 @@ Commander::run()
status.system_type = (uint8_t)system_type;
}

bool is_rotary = is_rotary_wing(&status) || (is_vtol(&status) && vtol_status.vtol_in_rw_mode);
bool is_fixed = is_fixed_wing(&status) || (is_vtol(&status) && !vtol_status.vtol_in_rw_mode);
bool is_ground = is_ground_rover(&status);

/* disable manual override for all systems that rely on electronic stabilization */
if (is_rotary_wing(&status) || (is_vtol(&status) && vtol_status.vtol_in_rw_mode)) {
if (is_rotary) {
status.vehicle_type = vehicle_status_s::VEHICLE_TYPE_ROTARY_WING;

} else if (is_fixed_wing(&status) || is_vtol(&status)) {
} else if (is_fixed) {
status.vehicle_type = vehicle_status_s::VEHICLE_TYPE_FIXED_WING;

} else if (is_ground_rover(&status)) {
} else if (is_ground) {
status.vehicle_type = vehicle_status_s::VEHICLE_TYPE_GROUND;
}

Expand Down Expand Up @@ -1638,7 +1642,9 @@ Commander::run()
if (is_vtol(&status)) {

// Check if there has been any change while updating the flags
if ((status.vehicle_type == vehicle_status_s::VEHICLE_TYPE_ROTARY_WING) != vtol_status.vtol_in_rw_mode) {
bool is_rotary = status.vehicle_type == vehicle_status_s::VEHICLE_TYPE_ROTARY_WING;

if (is_rotary != vtol_status.vtol_in_rw_mode) {
status.vehicle_type = vtol_status.vtol_in_rw_mode ?
vehicle_status_s::VEHICLE_TYPE_ROTARY_WING :
vehicle_status_s::VEHICLE_TYPE_FIXED_WING;
Expand All @@ -1660,7 +1666,9 @@ Commander::run()
status_changed = true;
}

if (armed.soft_stop != (status.vehicle_type == vehicle_status_s::VEHICLE_TYPE_FIXED_WING)) {
const bool is_not_rotary_wing = (status.vehicle_type != vehicle_status_s::VEHICLE_TYPE_ROTARY_WING);

if (armed.soft_stop != is_not_rotary_wing) {
armed.soft_stop = status.vehicle_type == vehicle_status_s::VEHICLE_TYPE_FIXED_WING;
status_changed = true;
}
Expand Down

0 comments on commit 714c90b

Please sign in to comment.