Skip to content
Snippets Groups Projects
Commit 164fe00d authored by Mark Sauder's avatar Mark Sauder Committed by Daniel Agar
Browse files

mc_att_control: replace math::min() and additional limit logic with...

mc_att_control: replace math::min() and additional limit logic with math::constrain() calls (#11658)
parent 4c228eaf
No related branches found
No related tags found
No related merge requests found
...@@ -808,11 +808,7 @@ MulticopterAttitudeControl::run() ...@@ -808,11 +808,7 @@ MulticopterAttitudeControl::run()
_motor_limits_sub = orb_subscribe(ORB_ID(multirotor_motor_limits)); _motor_limits_sub = orb_subscribe(ORB_ID(multirotor_motor_limits));
_battery_status_sub = orb_subscribe(ORB_ID(battery_status)); _battery_status_sub = orb_subscribe(ORB_ID(battery_status));
_gyro_count = math::min(orb_group_count(ORB_ID(sensor_gyro)), MAX_GYRO_COUNT); _gyro_count = math::constrain(orb_group_count(ORB_ID(sensor_gyro)), 1, MAX_GYRO_COUNT);
if (_gyro_count == 0) {
_gyro_count = 1;
}
for (unsigned s = 0; s < _gyro_count; s++) { for (unsigned s = 0; s < _gyro_count; s++) {
_sensor_gyro_sub[s] = orb_subscribe_multi(ORB_ID(sensor_gyro), s); _sensor_gyro_sub[s] = orb_subscribe_multi(ORB_ID(sensor_gyro), s);
...@@ -862,16 +858,10 @@ MulticopterAttitudeControl::run() ...@@ -862,16 +858,10 @@ MulticopterAttitudeControl::run()
/* run controller on gyro changes */ /* run controller on gyro changes */
if (poll_fds.revents & POLLIN) { if (poll_fds.revents & POLLIN) {
const hrt_abstime now = hrt_absolute_time(); const hrt_abstime now = hrt_absolute_time();
float dt = (now - last_run) / 1e6f;
last_run = now;
/* guard against too small (< 0.2ms) and too large (> 20ms) dt's */ // Guard against too small (< 0.2ms) and too large (> 20ms) dt's.
if (dt < 0.0002f) { const float dt = math::constrain(((now - last_run) / 1e6f), 0.0002f, 0.02f);
dt = 0.0002f; last_run = now;
} else if (dt > 0.02f) {
dt = 0.02f;
}
/* copy gyro data */ /* copy gyro data */
orb_copy(ORB_ID(sensor_gyro), _sensor_gyro_sub[_selected_gyro], &_sensor_gyro); orb_copy(ORB_ID(sensor_gyro), _sensor_gyro_sub[_selected_gyro], &_sensor_gyro);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment