From 99eb051c0f9bd74881ad931bf126ced2dfdbf5c3 Mon Sep 17 00:00:00 2001 From: Matthias Grob Date: Mon, 20 Nov 2017 16:58:45 +0100 Subject: [PATCH] FlightTasks: adapt POSIX convention to return negative values on error --- src/lib/FlightTasks/FlightTasks.hpp | 6 +++--- src/lib/FlightTasks/tasks/FlightTask.cpp | 8 +++++--- src/lib/FlightTasks/tasks/FlightTask.hpp | 8 ++++---- src/lib/FlightTasks/tasks/FlightTaskManual.cpp | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/lib/FlightTasks/FlightTasks.hpp b/src/lib/FlightTasks/FlightTasks.hpp index 78c33b8011..7f56433f81 100644 --- a/src/lib/FlightTasks/FlightTasks.hpp +++ b/src/lib/FlightTasks/FlightTasks.hpp @@ -57,7 +57,7 @@ public: /** * Call regularly in the control loop cycle to execute the task - * @return 0 on success, >0 on error + * @return 0 on success, <0 on error */ int update() { @@ -87,7 +87,7 @@ public: /** * Switch to the next task in the available list (for testing) - * @return 0 on success, >0 on error + * @return 0 on success, <0 on error */ void switch_task() { @@ -97,7 +97,7 @@ public: /** * Switch to a specific task (for normal usage) * @param task number to switch to - * @return 0 on success, >0 on error + * @return 0 on success, <0 on error */ int switch_task(int task_number) { diff --git a/src/lib/FlightTasks/tasks/FlightTask.cpp b/src/lib/FlightTasks/tasks/FlightTask.cpp index 9d758890d7..4adf7500bb 100644 --- a/src/lib/FlightTasks/tasks/FlightTask.cpp +++ b/src/lib/FlightTasks/tasks/FlightTask.cpp @@ -10,18 +10,20 @@ int FlightTask::update() _deltatime = math::min((_time_stamp_current - _time_stamp_last), _timeout) / 1e6f; _time_stamp_last = _time_stamp_current; updateSubscriptions(); - _evaluate_vehicle_position(); - return 0; + int ret = _evaluate_vehicle_position(); + return ret; } -void FlightTask::_evaluate_vehicle_position() +int FlightTask::_evaluate_vehicle_position() { if ((_time_stamp_current - _sub_vehicle_local_position.get().timestamp) < _timeout) { _position = matrix::Vector3f(&_sub_vehicle_local_position.get().x); _velocity = matrix::Vector3f(&_sub_vehicle_local_position.get().vx); _yaw = _sub_vehicle_local_position.get().yaw; + return 0; } else { _velocity.zero(); /* default velocity is all zero */ + return -1; } } diff --git a/src/lib/FlightTasks/tasks/FlightTask.hpp b/src/lib/FlightTasks/tasks/FlightTask.hpp index 1aca5aac2e..99ceaf32c2 100644 --- a/src/lib/FlightTasks/tasks/FlightTask.hpp +++ b/src/lib/FlightTasks/tasks/FlightTask.hpp @@ -59,7 +59,7 @@ public: /** * Call once on the event where you switch to the task - * @return 0 on success, >0 on error + * @return 0 on success, <0 on error */ virtual int activate() { @@ -70,13 +70,13 @@ public: /** * Call once on the event of switching away from the task - * @return 0 on success, >0 on error + * @return 0 on success, <0 on error */ virtual int disable() { return 0; }; /** * To be called regularly in the control loop cycle to execute the task - * @return 0 on success, >0 on error + * @return 0 on success, <0 on error */ virtual int update(); @@ -122,5 +122,5 @@ private: vehicle_local_position_setpoint_s _vehicle_local_position_setpoint; /**< Output position setpoint that every task has */ - void _evaluate_vehicle_position(); + int _evaluate_vehicle_position(); }; diff --git a/src/lib/FlightTasks/tasks/FlightTaskManual.cpp b/src/lib/FlightTasks/tasks/FlightTaskManual.cpp index 267aa39eb2..14e0f9199b 100644 --- a/src/lib/FlightTasks/tasks/FlightTaskManual.cpp +++ b/src/lib/FlightTasks/tasks/FlightTaskManual.cpp @@ -136,7 +136,7 @@ int FlightTaskManual::_evaluate_sticks() } else { _sticks.zero(); /* default is all zero */ - return 1; + return -1; } }