From e5d237088c4ad418edd373aef6dc8f0d673e160a Mon Sep 17 00:00:00 2001 From: Matthias Grob Date: Tue, 28 Nov 2017 21:59:31 +0100 Subject: [PATCH] FlightTasks: refactoring for CamelCase naming convention, small comment and declaration order renicements --- src/lib/FlightTasks/FlightTasks.hpp | 23 ++++++++++--------- src/lib/FlightTasks/tasks/FlightTask.cpp | 4 ++-- src/lib/FlightTasks/tasks/FlightTask.hpp | 19 +++++++-------- .../FlightTasks/tasks/FlightTaskManual.cpp | 8 +++---- .../FlightTasks/tasks/FlightTaskManual.hpp | 1 + src/lib/FlightTasks/tasks/FlightTaskOrbit.cpp | 6 ++--- src/lib/FlightTasks/tasks/FlightTaskOrbit.hpp | 1 - 7 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/lib/FlightTasks/FlightTasks.hpp b/src/lib/FlightTasks/FlightTasks.hpp index 62147c9c2c..c0eef19df3 100644 --- a/src/lib/FlightTasks/FlightTasks.hpp +++ b/src/lib/FlightTasks/FlightTasks.hpp @@ -69,7 +69,7 @@ public: */ bool update() { - if (is_any_task_active()) { + if (isAnyTaskActive()) { _subscription_array.update(); return _current_task->updateInitialize() && _current_task->update(); } @@ -80,9 +80,9 @@ public: /** * Get the output data from the current task */ - const vehicle_local_position_setpoint_s &get_position_setpoint() + const vehicle_local_position_setpoint_s &getPositionSetpoint() { - return _current_task->get_position_setpoint(); + return _current_task->getPositionSetpoint(); } /** @@ -90,24 +90,24 @@ public: */ inline const vehicle_local_position_setpoint_s &operator()() { - return get_position_setpoint(); + return getPositionSetpoint(); } /** * Switch to the next task in the available list (for testing) * @return true on success, false on error */ - int switch_task() + int switchTask() { - return switch_task(_current_task_index + 1); + return switchTask(_current_task_index + 1); } /** * Switch to a specific task (for normal usage) * @param task number to switch to - * @return true on success, false on error + * @return 0 on success, <0 on error */ - int switch_task(int task_number) + int switchTask(int task_number) { /* switch to the running task, nothing to do */ if (task_number == _current_task_index) { @@ -161,17 +161,18 @@ public: * Get the number of the active task * @return number of active task, -1 if there is none */ - int get_active_task() const { return _current_task_index; } + int getActiveTask() const { return _current_task_index; } /** * Check if any task is active * @return true if a task is active, false if not */ - bool is_any_task_active() const { return _current_task; } + bool isAnyTaskActive() const { return _current_task; } private: - /** union with all existing tasks: we use it to make sure that only the memory of the largest existing + /** + * Union with all existing tasks: we use it to make sure that only the memory of the largest existing * task is needed, and to avoid using dynamic memory allocations. */ union TaskUnion { diff --git a/src/lib/FlightTasks/tasks/FlightTask.cpp b/src/lib/FlightTasks/tasks/FlightTask.cpp index 9104aa1890..0678a14a25 100644 --- a/src/lib/FlightTasks/tasks/FlightTask.cpp +++ b/src/lib/FlightTasks/tasks/FlightTask.cpp @@ -25,10 +25,10 @@ bool FlightTask::updateInitialize() _time = (_time_stamp_current - _time_stamp_activate) / 1e6f; _deltatime = math::min((_time_stamp_current - _time_stamp_last), _timeout) / 1e6f; _time_stamp_last = _time_stamp_current; - return _evaluate_vehicle_position(); + return _evaluateVehiclePosition(); } -bool FlightTask::_evaluate_vehicle_position() +bool FlightTask::_evaluateVehiclePosition() { if ((_time_stamp_current - _sub_vehicle_local_position->get().timestamp) < _timeout) { _position = matrix::Vector3f(&_sub_vehicle_local_position->get().x); diff --git a/src/lib/FlightTasks/tasks/FlightTask.hpp b/src/lib/FlightTasks/tasks/FlightTask.hpp index b790cd98a8..39f8063d1f 100644 --- a/src/lib/FlightTasks/tasks/FlightTask.hpp +++ b/src/lib/FlightTasks/tasks/FlightTask.hpp @@ -60,7 +60,7 @@ public: virtual ~FlightTask() = default; /** - * initialize the uORB subscriptions using an array + * Initialize the uORB subscriptions using an array * @return true on success, false on error */ virtual bool initializeSubscriptions(SubscriptionArray &subscription_array); @@ -87,13 +87,13 @@ public: /** * Get the output data */ - const vehicle_local_position_setpoint_s &get_position_setpoint() + const vehicle_local_position_setpoint_s &getPositionSetpoint() { return _vehicle_local_position_setpoint; } protected: - /* time abstraction */ + /* Time abstraction */ static constexpr uint64_t _timeout = 500000; /**< maximal time in us before a loop or data times out */ float _time = 0; /**< passed time in seconds since the task was activated */ float _deltatime = 0; /**< passed time in seconds since the task was last updated */ @@ -101,25 +101,26 @@ protected: hrt_abstime _time_stamp_current = 0; /**< time stamp at the beginning of the current task update */ hrt_abstime _time_stamp_last = 0; /**< time stamp when task was last updated */ - /* Current vehicle position for every task */ + /* Current vehicle position */ matrix::Vector3f _position; /**< current vehicle position */ matrix::Vector3f _velocity; /**< current vehicle velocity */ float _yaw = 0.f; + bool _evaluateVehiclePosition(); /* Put the position vector produced by the task into the setpoint message */ - void _set_position_setpoint(const matrix::Vector3f &position_setpoint) { position_setpoint.copyToRaw(&_vehicle_local_position_setpoint.x); } + void _setPositionSetpoint(const matrix::Vector3f &position_setpoint) { position_setpoint.copyToRaw(&_vehicle_local_position_setpoint.x); } /* Put the velocity vector produced by the task into the setpoint message */ - void _set_velocity_setpoint(const matrix::Vector3f &velocity_setpoint) { velocity_setpoint.copyToRaw(&_vehicle_local_position_setpoint.vx); } + void _setVelocitySetpoint(const matrix::Vector3f &velocity_setpoint) { velocity_setpoint.copyToRaw(&_vehicle_local_position_setpoint.vx); } /* Put the acceleration vector produced by the task into the setpoint message */ - void _set_acceleration_setpoint(const matrix::Vector3f &acceleration_setpoint) { acceleration_setpoint.copyToRaw(&_vehicle_local_position_setpoint.acc_x); } + void _setAccelerationSetpoint(const matrix::Vector3f &acceleration_setpoint) { acceleration_setpoint.copyToRaw(&_vehicle_local_position_setpoint.acc_x); } /* Put the yaw angle produced by the task into the setpoint message */ - void _set_yaw_setpoint(const float yaw) { _vehicle_local_position_setpoint.yaw = yaw; } + void _setYawSetpoint(const float yaw) { _vehicle_local_position_setpoint.yaw = yaw; } /* Put the yaw anglular rate produced by the task into the setpoint message */ - void _set_yawspeed_setpoint(const float &yawspeed) { _vehicle_local_position_setpoint.yawspeed = yawspeed; } + void _setYawspeedSetpoint(const float &yawspeed) { _vehicle_local_position_setpoint.yawspeed = yawspeed; } private: uORB::Subscription *_sub_vehicle_local_position{nullptr}; diff --git a/src/lib/FlightTasks/tasks/FlightTaskManual.cpp b/src/lib/FlightTasks/tasks/FlightTaskManual.cpp index 59b48d95cc..65738f6cda 100644 --- a/src/lib/FlightTasks/tasks/FlightTaskManual.cpp +++ b/src/lib/FlightTasks/tasks/FlightTaskManual.cpp @@ -90,7 +90,7 @@ bool FlightTaskManual::initializeSubscriptions(SubscriptionArray &subscription_a bool FlightTaskManual::updateInitialize() { - return FlightTask::updateInitialize() && _evaluate_sticks(); + return FlightTask::updateInitialize() && _evaluateSticks(); } bool FlightTaskManual::update() @@ -117,7 +117,7 @@ bool FlightTaskManual::update() /* smooth out velocity setpoint by slewrate and return it */ vel_sp_slewrate(stick_xy, _sticks(3), velocity_setpoint); - _set_velocity_setpoint(velocity_setpoint); + _setVelocitySetpoint(velocity_setpoint); /* handle position and altitude hold */ const bool stick_xy_zero = stick_xy_norm <= FLT_EPSILON; @@ -143,11 +143,11 @@ bool FlightTaskManual::update() _hold_position(2) = NAN; } - _set_position_setpoint(_hold_position); + _setPositionSetpoint(_hold_position); return true; } -bool FlightTaskManual::_evaluate_sticks() +bool FlightTaskManual::_evaluateSticks() { if ((_time_stamp_current - _sub_manual_control_setpoint->get().timestamp) < _timeout) { /* get data and scale correctly */ diff --git a/src/lib/FlightTasks/tasks/FlightTaskManual.hpp b/src/lib/FlightTasks/tasks/FlightTaskManual.hpp index 41f688013b..a2625e27e3 100644 --- a/src/lib/FlightTasks/tasks/FlightTaskManual.hpp +++ b/src/lib/FlightTasks/tasks/FlightTaskManual.hpp @@ -62,6 +62,7 @@ public: protected: matrix::Vector _sticks; + bool _evaluateSticks(); float get_input_frame_yaw() { return _yaw; } diff --git a/src/lib/FlightTasks/tasks/FlightTaskOrbit.cpp b/src/lib/FlightTasks/tasks/FlightTaskOrbit.cpp index 54aa96958b..1ab8c7974e 100644 --- a/src/lib/FlightTasks/tasks/FlightTaskOrbit.cpp +++ b/src/lib/FlightTasks/tasks/FlightTaskOrbit.cpp @@ -80,8 +80,8 @@ bool FlightTaskOrbit::update() float yaw = atan2f(center_to_position(1), center_to_position(0)) + M_PI_F; - _set_position_setpoint(Vector3f(NAN, NAN, _z)); - _set_velocity_setpoint(Vector3f(velocity_xy(0), velocity_xy(1), 0.f)); - _set_yaw_setpoint(yaw); + _setPositionSetpoint(Vector3f(NAN, NAN, _z)); + _setVelocitySetpoint(Vector3f(velocity_xy(0), velocity_xy(1), 0.f)); + _setYawSetpoint(yaw); return true; } diff --git a/src/lib/FlightTasks/tasks/FlightTaskOrbit.hpp b/src/lib/FlightTasks/tasks/FlightTaskOrbit.hpp index eb4012ce99..f45536632c 100644 --- a/src/lib/FlightTasks/tasks/FlightTaskOrbit.hpp +++ b/src/lib/FlightTasks/tasks/FlightTaskOrbit.hpp @@ -55,7 +55,6 @@ public: bool update() override; private: - float _r = 0.f; /**< radius with which to orbit the target */ float _v = 0.f; /**< linear velocity for orbiting in m/s */ float _z = 0.f; /**< local z coordinate in meters */