Browse Source

FlightTasks: switch input from pointers in parameters passed on every run to private pointers of the base class with safety getter and setter

sbg
Matthias Grob 8 years ago committed by Beat Küng
parent
commit
32a1ff733d
  1. 2
      src/lib/FlightTasks/FlightTasks.hpp
  2. 36
      src/lib/FlightTasks/tasks/FlightTask.hpp
  3. 4
      src/lib/FlightTasks/tasks/FlightTaskOrbit.hpp

2
src/lib/FlightTasks/FlightTasks.hpp

@ -55,7 +55,7 @@ public:
* @param TODO * @param TODO
* @return 0 on success, >0 on error otherwise * @return 0 on success, >0 on error otherwise
*/ */
int update(manual_control_setpoint_s *manual_control_setpoint, vehicle_local_position_s *vehicle_position) { return Orbit.update(NULL, NULL); }; int update() { return Orbit.update(); };
/** /**
* Call to get result of the task execution * Call to get result of the task execution

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

@ -47,11 +47,17 @@
class FlightTask class FlightTask
{ {
public: public:
FlightTask() {}; FlightTask()
{
_vehicle_local_position = NULL;
_manual_control_setpoint = NULL;
_reset_time();
};
virtual ~FlightTask() {}; virtual ~FlightTask() {};
/** /**
* Call once on the event where you switch to the task * 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 otherwise
*/ */
virtual int activate() virtual int activate()
@ -67,22 +73,33 @@ public:
virtual int disable() = 0; virtual int disable() = 0;
/** /**
* Call regularly in the control loop cycle to execute the task * To be called regularly in the control loop cycle to execute the task
* @param TODO
* @return 0 on success, >0 on error otherwise * @return 0 on success, >0 on error otherwise
*/ */
virtual int update(manual_control_setpoint_s *manual_control_setpoint, vehicle_local_position_s *vehicle_position) virtual int update()
{ {
_time = hrt_elapsed_time(&_starting_time_stamp) / 1e6; _time = hrt_elapsed_time(&_starting_time_stamp) / 1e6;
return 0; return 0;
}; };
/** /**
* Call to get result of the task execution * Get the resulting setpoints of the task execution via pointer
* @return pointer to * @return pointer to setpoint struct
*/ */
const vehicle_local_position_setpoint_s *get_position_setpoint() const { return &_vehicle_position_setpoint; }; const vehicle_local_position_setpoint_s *get_position_setpoint() const { return &_vehicle_position_setpoint; };
/**
* Set vehicle local position data pointer
* @param pointer to vehicle local position
*/
void set_vehicle_local_position_pointer(const vehicle_local_position_s *vehicle_local_position) { _vehicle_local_position = vehicle_local_position; };
/**
* Set manual control setpoint data pointer if it's needed for the task
* @param pointer to manual control setpoint
*/
void set_manual_control_setpoint_pointer(const manual_control_setpoint_s *manual_control_setpoint) { _manual_control_setpoint = manual_control_setpoint; };
protected: protected:
float _get_time() { return _time; } float _get_time() { return _time; }
@ -111,8 +128,15 @@ protected:
private: private:
/* local time for a task */
float _time = 0; /*< passed time in seconds since the task was activated */ float _time = 0; /*< passed time in seconds since the task was activated */
hrt_abstime _starting_time_stamp; /*< time stamp when task was activated */ hrt_abstime _starting_time_stamp; /*< time stamp when task was activated */
/* General Input */
const vehicle_local_position_s *_vehicle_local_position;
const manual_control_setpoint_s *_manual_control_setpoint;
/* General Output */
vehicle_local_position_setpoint_s _vehicle_position_setpoint; vehicle_local_position_setpoint_s _vehicle_position_setpoint;
}; };

4
src/lib/FlightTasks/tasks/FlightTaskOrbit.hpp

@ -70,9 +70,9 @@ public:
* @param TODO * @param TODO
* @return 0 on success, >0 on error otherwise * @return 0 on success, >0 on error otherwise
*/ */
virtual int update(manual_control_setpoint_s *manual_control_setpoint, vehicle_local_position_s *vehicle_position) virtual int update()
{ {
FlightTask::update(NULL, NULL); FlightTask::update();
float v = 2 * M_PI_F * 0.1f; /* velocity for orbiting in radians per second */ float v = 2 * M_PI_F * 0.1f; /* velocity for orbiting in radians per second */
float altitude = 2; /* altitude in meters */ float altitude = 2; /* altitude in meters */
_set_position_setpoint(matrix::Vector3f(1.f * cosf(v * _get_time()), 1.f * sinf(v * _get_time()), -altitude)); _set_position_setpoint(matrix::Vector3f(1.f * cosf(v * _get_time()), 1.f * sinf(v * _get_time()), -altitude));

Loading…
Cancel
Save