Skip to content
Snippets Groups Projects
Commit a310980a authored by Matthias Grob's avatar Matthias Grob Committed by Beat Küng
Browse files

mc_pos_control: refactor loop polling

parent 013a2655
No related branches found
No related tags found
No related merge requests found
...@@ -593,21 +593,16 @@ MulticopterPositionControl::run() ...@@ -593,21 +593,16 @@ MulticopterPositionControl::run()
// Let's be safe and have the landing gear down by default // Let's be safe and have the landing gear down by default
_att_sp.landing_gear = vehicle_attitude_setpoint_s::LANDING_GEAR_DOWN; _att_sp.landing_gear = vehicle_attitude_setpoint_s::LANDING_GEAR_DOWN;
// wakeup source // setup file descriptor to poll the local position as loop wakeup source
px4_pollfd_struct_t fds[1]; px4_pollfd_struct_t poll_fd = {.fd = _local_pos_sub, .events = POLLIN};
fds[0].fd = _local_pos_sub;
fds[0].events = POLLIN;
while (!should_exit()) { while (!should_exit()) {
// wait for up to 20ms for data // poll for new data on the local position state topic (wait for up to 20ms)
int pret = px4_poll(&fds[0], (sizeof(fds) / sizeof(fds[0])), 20); const int poll_return = px4_poll(&poll_fd, 1, 20);
// poll_return == 0: go through the loop anyway to copy manual input at 50 Hz
// pret == 0: go through the loop anyway to copy manual input at 50 Hz.
// this is undesirable but not much we can do // this is undesirable but not much we can do
if (pret < 0) { if (poll_return < 0) {
PX4_ERR("poll error %d, %d", pret, errno); PX4_ERR("poll error: %d, %s", poll_return, strerror(errno));
continue; continue;
} }
......
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