Browse Source

FlightTasks: added simple task switching with possibility do disable FlightTasks completely

sbg
Matthias Grob 8 years ago committed by Beat Küng
parent
commit
88bf40e3cb
  1. 41
      src/lib/FlightTasks/FlightTasks.hpp
  2. 6
      src/lib/FlightTasks/tasks/FlightTask.hpp

41
src/lib/FlightTasks/FlightTasks.hpp

@ -52,10 +52,21 @@ public: @@ -52,10 +52,21 @@ public:
/**
* Call regularly in the control loop cycle to execute the task
* @return 0 on success, >0 on error otherwise
* @return 0 on success, >0 on error
*/
int update() { return _tasks[_current_task]->update(); };
int update()
{
if (is_any_task_active()) {
return _tasks[_current_task]->update();
} else {
return 1;
}
};
/**
* Call this function initially to point all tasks to the general input data
*/
void set_input_pointers(vehicle_local_position_s *vehicle_local_position,
manual_control_setpoint_s *manual_control_setpoint)
{
@ -65,15 +76,37 @@ public: @@ -65,15 +76,37 @@ public:
}
};
/**
* Switch to a different task
*/
void switch_task(int task_number)
{
if (is_any_task_active()) {
_tasks[_current_task]->disable();
}
_current_task = task_number;
if (is_any_task_active()) {
_tasks[_current_task]->activate();
}
};
/**
* Call to get result of the task execution
* @return pointer to
* @return pointer to the setpoint for the position controller
*/
const vehicle_local_position_setpoint_s *get_position_setpoint() const { return Orbit.get_position_setpoint(); };
/**
* Call to get result of the task execution
* @return pointer to
*/
bool is_any_task_active() const { return _current_task > -1 && _current_task < _task_count; };
private:
static const int _task_count = 1;
int _current_task = 0;
int _current_task = -1;
FlightTaskOrbit Orbit;
FlightTask *_tasks[_task_count] = {&Orbit};

6
src/lib/FlightTasks/tasks/FlightTask.hpp

@ -55,7 +55,7 @@ public: @@ -55,7 +55,7 @@ public:
/**
* Call once on the event where you switch to the task
* Note: Set the necessary input pointers first!
* @return 0 on success, >0 on error otherwise
* @return 0 on success, >0 on error
*/
virtual int activate()
{
@ -65,13 +65,13 @@ public: @@ -65,13 +65,13 @@ public:
/**
* Call once on the event of switching away from the task
* @return 0 on success, >0 on error otherwise
* @return 0 on success, >0 on error
*/
virtual int disable() = 0;
/**
* To be called regularly in the control loop cycle to execute the task
* @return 0 on success, >0 on error otherwise
* @return 0 on success, >0 on error
*/
virtual int update()
{

Loading…
Cancel
Save