PX4-Autopilot/src/lib/FlightTasks/FlightTasks.hpp

115 lines
3.4 KiB
C++

/****************************************************************************
*
* Copyright (c) 2017 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/**
* @file flight_taks.h
*
* Library class to hold and manage all implemented flight task instances
*
* @author Matthias Grob <maetugr@gmail.com>
*/
#pragma once
#include "tasks/FlightTask.hpp"
#include "tasks/FlightTaskOrbit.hpp"
class FlightTasks
{
public:
FlightTasks() {};
~FlightTasks() {};
/**
* Call regularly in the control loop cycle to execute the task
* @return 0 on success, >0 on error
*/
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)
{
for (int i = 0; i < _task_count; i++) {
_tasks[i]->set_vehicle_local_position_pointer(vehicle_local_position);
_tasks[i]->set_manual_control_setpoint_pointer(manual_control_setpoint);
}
};
/**
* 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 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 = -1;
FlightTaskOrbit Orbit;
FlightTask *_tasks[_task_count] = {&Orbit};
};