mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-06 12:48:54 +08:00
FlightTasks: switch input from pointers in parameters passed on every run to private pointers of the base class with safety getter and setter
This commit is contained in:
@@ -55,7 +55,7 @@ public:
|
||||
* @param TODO
|
||||
* @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
|
||||
|
||||
@@ -47,11 +47,17 @@
|
||||
class FlightTask
|
||||
{
|
||||
public:
|
||||
FlightTask() {};
|
||||
FlightTask()
|
||||
{
|
||||
_vehicle_local_position = NULL;
|
||||
_manual_control_setpoint = NULL;
|
||||
_reset_time();
|
||||
};
|
||||
virtual ~FlightTask() {};
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
virtual int activate()
|
||||
@@ -67,22 +73,33 @@ public:
|
||||
virtual int disable() = 0;
|
||||
|
||||
/**
|
||||
* Call regularly in the control loop cycle to execute the task
|
||||
* @param TODO
|
||||
* To be called regularly in the control loop cycle to execute the task
|
||||
* @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;
|
||||
return 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Call to get result of the task execution
|
||||
* @return pointer to
|
||||
* Get the resulting setpoints of the task execution via pointer
|
||||
* @return pointer to setpoint struct
|
||||
*/
|
||||
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:
|
||||
|
||||
float _get_time() { return _time; }
|
||||
@@ -111,8 +128,15 @@ protected:
|
||||
|
||||
private:
|
||||
|
||||
/* local time for a task */
|
||||
float _time = 0; /*< passed time in seconds since the 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;
|
||||
|
||||
};
|
||||
|
||||
@@ -70,9 +70,9 @@ public:
|
||||
* @param TODO
|
||||
* @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 altitude = 2; /* altitude in meters */
|
||||
_set_position_setpoint(matrix::Vector3f(1.f * cosf(v * _get_time()), 1.f * sinf(v * _get_time()), -altitude));
|
||||
|
||||
Reference in New Issue
Block a user