Browse Source

commander: only process one vehicle_command/action_request per cycle

- things like arming requests can be dependent on current nav state
that might requested by a previous command, but the state machine
transition will only happen after command processing
v1.13.0-BW
Daniel Agar 3 years ago
parent
commit
879622547c
  1. 20
      src/modules/commander/Commander.cpp
  2. 2
      src/modules/commander/Commander.hpp

20
src/modules/commander/Commander.cpp

@ -2710,14 +2710,14 @@ Commander::run() @@ -2710,14 +2710,14 @@ Commander::run()
}
/* handle commands last, as the system needs to be updated to handle them */
while (_cmd_sub.updated()) {
if (_vehicle_command_sub.updated()) {
/* got command */
const unsigned last_generation = _cmd_sub.get_last_generation();
const unsigned last_generation = _vehicle_command_sub.get_last_generation();
vehicle_command_s cmd;
if (_cmd_sub.copy(&cmd)) {
if (_cmd_sub.get_last_generation() != last_generation + 1) {
PX4_ERR("vehicle_command lost, generation %u -> %u", last_generation, _cmd_sub.get_last_generation());
if (_vehicle_command_sub.copy(&cmd)) {
if (_vehicle_command_sub.get_last_generation() != last_generation + 1) {
PX4_ERR("vehicle_command lost, generation %u -> %u", last_generation, _vehicle_command_sub.get_last_generation());
}
if (handle_command(cmd)) {
@ -2726,10 +2726,15 @@ Commander::run() @@ -2726,10 +2726,15 @@ Commander::run()
}
}
while (_action_request_sub.updated()) {
if (_action_request_sub.updated()) {
const unsigned last_generation = _action_request_sub.get_last_generation();
action_request_s action_request;
if (_action_request_sub.copy(&action_request)) {
if (_action_request_sub.get_last_generation() != last_generation + 1) {
PX4_ERR("action_request lost, generation %u -> %u", last_generation, _action_request_sub.get_last_generation());
}
executeActionRequest(action_request);
}
}
@ -3080,8 +3085,11 @@ Commander::run() @@ -3080,8 +3085,11 @@ Commander::run()
px4_indicate_external_reset_lockout(LockoutComponent::Commander, _armed.armed);
// sleep if there are no vehicle_commands or action_requests to process
if (!_vehicle_command_sub.updated() && !_action_request_sub.updated()) {
px4_usleep(COMMANDER_MONITORING_INTERVAL);
}
}
rgbled_set_color_and_mode(led_control_s::COLOR_WHITE, led_control_s::MODE_OFF);

2
src/modules/commander/Commander.hpp

@ -401,7 +401,6 @@ private: @@ -401,7 +401,6 @@ private:
// Subscriptions
uORB::Subscription _action_request_sub {ORB_ID(action_request)};
uORB::Subscription _actuator_controls_sub{ORB_ID_VEHICLE_ATTITUDE_CONTROLS};
uORB::Subscription _cmd_sub {ORB_ID(vehicle_command)};
uORB::Subscription _cpuload_sub{ORB_ID(cpuload)};
uORB::Subscription _esc_status_sub{ORB_ID(esc_status)};
uORB::Subscription _estimator_selector_status_sub{ORB_ID(estimator_selector_status)};
@ -415,6 +414,7 @@ private: @@ -415,6 +414,7 @@ private:
uORB::Subscription _system_power_sub{ORB_ID(system_power)};
uORB::Subscription _vehicle_angular_velocity_sub{ORB_ID(vehicle_angular_velocity)};
uORB::Subscription _vehicle_attitude_sub{ORB_ID(vehicle_attitude)};
uORB::Subscription _vehicle_command_sub{ORB_ID(vehicle_command)};
uORB::Subscription _vehicle_gps_position_sub{ORB_ID(vehicle_gps_position)};
uORB::Subscription _vtol_vehicle_status_sub{ORB_ID(vtol_vehicle_status)};
uORB::Subscription _wind_sub{ORB_ID(wind)};

Loading…
Cancel
Save