-
Notifications
You must be signed in to change notification settings - Fork 13.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UAVCAN pre-arm checks on escs_status (cleanup of #12153) #12641
Conversation
Signed-off-by: Claudio Micheli <[email protected]>
Signed-off-by: Claudio Micheli <[email protected]>
@@ -1010,6 +1010,12 @@ bool prearm_check(orb_advert_t *mavlink_log_pub, const vehicle_status_flags_s &s | |||
|
|||
} | |||
|
|||
if (status_flags.condition_escs_error && !status_flags.circuit_breaker_engaged_escs_check) { | |||
mavlink_log_critical(mavlink_log_pub, "Arming denied! One or more ESCs are offline"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (prearm_ok && reportFailures) {
src/lib/mixer/mixer_group.cpp
Outdated
if (rotor_count > 0) { | ||
break; | ||
|
||
} else { mixer = mixer -> _next;} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace with:
}
mixer = mixer->_next;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh, In the original PR was like that but in the review I was suggested to use break for exiting the while loop.
What is the best practice for exiting the while loop?
The reference says that breaks can be used for exiting while loops, so i guess is just a madder of best choice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not about the break, you can leave it in. But if you break
you don't need the else
, and removing it makes the code more readable.
As for best practices, it depends: exiting a larger loop from within many nested cases is prone to errors and harder to understand. Adding a break in a simple loop on the other hand can make the code simpler.
src/drivers/uavcan/uavcan_main.cpp
Outdated
@@ -1123,6 +1123,11 @@ UavcanNode::ioctl(file *filp, int cmd, unsigned long arg) | |||
} else { | |||
|
|||
_mixers->groups_required(_groups_required); | |||
PX4_INFO("Groups required %d", _groups_required); | |||
|
|||
_rotor_count = _mixers->get_multirotor_count(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep this locally:
_rotor_count = _mixers->get_multirotor_count(); | |
int rotor_count = _mixers->get_multirotor_count(); |
msg/vehicle_status_flags.msg
Outdated
@@ -14,14 +14,15 @@ bool condition_local_velocity_valid # set to true by the commander app if the q | |||
bool condition_local_altitude_valid | |||
bool condition_power_input_valid # set if input power is valid | |||
bool condition_battery_healthy # set if battery is available and not low | |||
|
|||
bool condition_escs_error # set to true in case of standard ESCs that do not provide status OR if all the ESCs are online |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment looks incorrect.
src/lib/mixer/mixer_group.cpp
Outdated
|
||
rotor_count = mixer->get_multirotor_count(); | ||
|
||
if (rotor_count > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you not summing all up? Would IMO be more robust.
src/drivers/uavcan/actuators/esc.cpp
Outdated
|
||
uint8_t UavcanEscController::check_escs_status() | ||
{ | ||
int esc_status_flags = 255; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you only set the bits for the ones that are really online?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually yes, I think in an early implementation I used this logic to fix something but after reviewing makes completely sense to re-invert the logic :)!
* Circuit breaker for ESCs status check | ||
* | ||
* Setting this parameter to 271828 will disable offline ESCs detection. | ||
* If this check is enabled, then the ESCs check will fail is not all the ESCs are reporting their status. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* If this check is enabled, then the ESCs check will fail is not all the ESCs are reporting their status. | |
* If this check is enabled, then the ESCs check will fail if not all the ESCs are reporting their status. |
src/modules/commander/Commander.cpp
Outdated
@@ -1610,6 +1614,18 @@ Commander::run() | |||
} | |||
} | |||
|
|||
if (orb_exists(ORB_ID(esc_status), 0) == PX4_OK) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you really need this? Is it not enough to check if it's updated and the timestamp is valid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, this is a left over that I introduced then the logic was still reasoning on "is valid" and thus i needed to initialize that to true in case of escs not reporting status. Changing the message to condition_escs_error
(and thus inverting the logic) automatically solved this corner case. Will get rid of that
src/modules/commander/Commander.cpp
Outdated
else if (esc_status.esc_online_flags < _last_esc_online_flags) { | ||
|
||
for (int index = 0; index < esc_status.esc_count; index++) { | ||
if ((bool)!(esc_status.esc_online_flags & (1 << index))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ((bool)!(esc_status.esc_online_flags & (1 << index))) { | |
if ((esc_status.esc_online_flags & (1 << index)) == 0) { |
How about a simple boolean parameter like |
@dagar thanks for the hint will have a look |
src/drivers/uavcan/actuators/esc.cpp
Outdated
|
||
for (int index = 0; index < esc_status_s::CONNECTED_ESC_MAX; index++) { | ||
|
||
if (hrt_elapsed_time(&_esc_status.esc[index].timestamp) < 800000.0f && _esc_status.esc[index].timestamp > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you reverse the order of the two statements you can avoid the (presumably more expensive) hrt_elapsed_time()
call when the timestamp is invalid.
Signed-off-by: Claudio Micheli <[email protected]>
…shed. Signed-off-by: Claudio Micheli <[email protected]>
Signed-off-by: Claudio Micheli <[email protected]>
Signed-off-by: Claudio Micheli <[email protected]>
c54e76a
to
e7e0769
Compare
@bkueng thanks for the review, all your comments have been addressed; I think the PR is now ready to go. |
msg/vehicle_status_flags.msg
Outdated
bool circuit_breaker_engaged_power_check | ||
bool circuit_breaker_engaged_airspd_check | ||
bool circuit_breaker_engaged_enginefailure_check | ||
bool circuit_breaker_engaged_gpsfailure_check | ||
bool circuit_breaker_flight_termination_disabled | ||
bool circuit_breaker_engaged_usb_check | ||
bool circuit_breaker_engaged_posfailure_check # set to true when the position valid checks have been disabled | ||
bool circuit_breaker_engaged_escs_check |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it's not a circuit breaker anymore, can you rename this as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct this can actually be removed.
src/drivers/uavcan/actuators/esc.cpp
Outdated
|
||
for (int index = 0; index < esc_status_s::CONNECTED_ESC_MAX; index++) { | ||
|
||
if (_esc_status.esc[index].timestamp > 0 && hrt_elapsed_time(&_esc_status.esc[index].timestamp) < 800000.0f) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 more things you can do here: pull the hrt_absolute_time
call out of the loop: hrt_abstime now = hrt_absolute_time();
, and use the time literals: now - _esc_status.esc[index].timestamp < 800_ms) {
(add using namespace time_literals;
at the top of the file).
Signed-off-by: Claudio Micheli <[email protected]>
Signed-off-by: Claudio Micheli <[email protected]>
Signed-off-by: Claudio Micheli <[email protected]>
Signed-off-by: Claudio Micheli <[email protected]>
1add79e
to
b7d489e
Compare
This is a cleaned-up version of #12153.
Addressed @RomanBapst review comments:
condition_escs_error
)Test log:
https://logs.px4.io/plot_app?log=5b7f4b1c-9c1a-4f52-bdb8-25d6bb5e13e1