mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-31 02:16:53 +08:00
FlightTasks: FlightTask definition to cpp, fix include chain, fix cmake
This commit is contained in:
@@ -33,7 +33,7 @@
|
|||||||
px4_add_module(
|
px4_add_module(
|
||||||
MODULE lib__flight_tasks
|
MODULE lib__flight_tasks
|
||||||
SRCS
|
SRCS
|
||||||
FlightTask.h
|
tasks/FlightTask.cpp
|
||||||
tasks/FlightTaskManual.cpp
|
tasks/FlightTaskManual.cpp
|
||||||
tasks/FlightTaskOrbit.cpp
|
tasks/FlightTaskOrbit.cpp
|
||||||
DEPENDS
|
DEPENDS
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
#include "FlightTask.hpp"
|
||||||
|
#include <mathlib/mathlib.h>
|
||||||
|
|
||||||
|
int FlightTask::update()
|
||||||
|
{
|
||||||
|
_time = hrt_elapsed_time(&_starting_time_stamp) / 1e6f;
|
||||||
|
_deltatime = math::min((int)hrt_elapsed_time(&_last_time_stamp), _timeout) / 1e6f;
|
||||||
|
_last_time_stamp = hrt_absolute_time();
|
||||||
|
updateSubscriptions();
|
||||||
|
_evaluate_vehicle_position();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FlightTask::_evaluate_vehicle_position()
|
||||||
|
{
|
||||||
|
if (hrt_elapsed_time(&_sub_vehicle_local_position.get().timestamp) < _timeout) {
|
||||||
|
_position = matrix::Vector3f(&_sub_vehicle_local_position.get().x);
|
||||||
|
_velocity = matrix::Vector3f(&_sub_vehicle_local_position.get().vx);
|
||||||
|
_yaw = _sub_vehicle_local_position.get().yaw;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
_velocity.zero(); /* default velocity is all zero */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FlightTask::_set_position_setpoint(const matrix::Vector3f position_setpoint)
|
||||||
|
{
|
||||||
|
_vehicle_local_position_setpoint.x = position_setpoint(0);
|
||||||
|
_vehicle_local_position_setpoint.y = position_setpoint(1);
|
||||||
|
_vehicle_local_position_setpoint.z = position_setpoint(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FlightTask::_set_velocity_setpoint(const matrix::Vector3f velocity_setpoint)
|
||||||
|
{
|
||||||
|
_vehicle_local_position_setpoint.vx = velocity_setpoint(0);
|
||||||
|
_vehicle_local_position_setpoint.vy = velocity_setpoint(1);
|
||||||
|
_vehicle_local_position_setpoint.vz = velocity_setpoint(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FlightTask::_set_acceleration_setpoint(const matrix::Vector3f acceleration_setpoint)
|
||||||
|
{
|
||||||
|
_vehicle_local_position_setpoint.acc_x = acceleration_setpoint(0);
|
||||||
|
_vehicle_local_position_setpoint.acc_y = acceleration_setpoint(1);
|
||||||
|
_vehicle_local_position_setpoint.acc_z = acceleration_setpoint(2);
|
||||||
|
}
|
||||||
@@ -41,7 +41,12 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <controllib/blocks.hpp>
|
||||||
|
#include <drivers/drv_hrt.h>
|
||||||
#include <matrix/matrix/math.hpp>
|
#include <matrix/matrix/math.hpp>
|
||||||
|
#include <uORB/topics/vehicle_local_position.h>
|
||||||
|
#include <uORB/topics/vehicle_local_position_setpoint.h>
|
||||||
|
|
||||||
|
|
||||||
class FlightTask : public control::SuperBlock
|
class FlightTask : public control::SuperBlock
|
||||||
{
|
{
|
||||||
@@ -54,7 +59,6 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 and output pointers first!
|
|
||||||
* @return 0 on success, >0 on error
|
* @return 0 on success, >0 on error
|
||||||
*/
|
*/
|
||||||
virtual int activate()
|
virtual int activate()
|
||||||
@@ -66,7 +70,7 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Call once on the event of switching away from the task
|
* Call once on the event of switching away from the task
|
||||||
* @return 0 on success, >0 on error
|
* @return 0 on success, >0 on error
|
||||||
*/
|
*/
|
||||||
virtual int disable() { return 0; };
|
virtual int disable() { return 0; };
|
||||||
|
|
||||||
@@ -74,15 +78,7 @@ public:
|
|||||||
* To be called regularly in the control loop cycle to execute the task
|
* To be called regularly in the control loop cycle to execute the task
|
||||||
* @return 0 on success, >0 on error
|
* @return 0 on success, >0 on error
|
||||||
*/
|
*/
|
||||||
virtual int update()
|
virtual int update();
|
||||||
{
|
|
||||||
_time = hrt_elapsed_time(&_starting_time_stamp) / 1e6f;
|
|
||||||
_deltatime = math::min((int)hrt_elapsed_time(&_last_time_stamp), _timeout) / 1e6f;
|
|
||||||
_last_time_stamp = hrt_absolute_time();
|
|
||||||
updateSubscriptions();
|
|
||||||
_evaluate_vehicle_position();
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the output data
|
* Get the output data
|
||||||
@@ -106,32 +102,17 @@ protected:
|
|||||||
/**
|
/**
|
||||||
* Put the position vector produced by the task into the setpoint message
|
* Put the position vector produced by the task into the setpoint message
|
||||||
*/
|
*/
|
||||||
void _set_position_setpoint(const matrix::Vector3f position_setpoint)
|
void _set_position_setpoint(const matrix::Vector3f position_setpoint);
|
||||||
{
|
|
||||||
_vehicle_local_position_setpoint.x = position_setpoint(0);
|
|
||||||
_vehicle_local_position_setpoint.y = position_setpoint(1);
|
|
||||||
_vehicle_local_position_setpoint.z = position_setpoint(2);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put the velocity vector produced by the task into the setpoint message
|
* Put the velocity vector produced by the task into the setpoint message
|
||||||
*/
|
*/
|
||||||
void _set_velocity_setpoint(const matrix::Vector3f velocity_setpoint)
|
void _set_velocity_setpoint(const matrix::Vector3f velocity_setpoint);
|
||||||
{
|
|
||||||
_vehicle_local_position_setpoint.vx = velocity_setpoint(0);
|
|
||||||
_vehicle_local_position_setpoint.vy = velocity_setpoint(1);
|
|
||||||
_vehicle_local_position_setpoint.vz = velocity_setpoint(2);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put the acceleration vector produced by the task into the setpoint message
|
* Put the acceleration vector produced by the task into the setpoint message
|
||||||
*/
|
*/
|
||||||
void _set_acceleration_setpoint(const matrix::Vector3f acceleration_setpoint)
|
void _set_acceleration_setpoint(const matrix::Vector3f acceleration_setpoint);
|
||||||
{
|
|
||||||
_vehicle_local_position_setpoint.acc_x = acceleration_setpoint(0);
|
|
||||||
_vehicle_local_position_setpoint.acc_y = acceleration_setpoint(1);
|
|
||||||
_vehicle_local_position_setpoint.acc_z = acceleration_setpoint(2);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put the yaw angle produced by the task into the setpoint message
|
* Put the yaw angle produced by the task into the setpoint message
|
||||||
@@ -147,15 +128,5 @@ private:
|
|||||||
/* Output position setpoint that every task has */
|
/* Output position setpoint that every task has */
|
||||||
vehicle_local_position_setpoint_s _vehicle_local_position_setpoint;
|
vehicle_local_position_setpoint_s _vehicle_local_position_setpoint;
|
||||||
|
|
||||||
void _evaluate_vehicle_position()
|
void _evaluate_vehicle_position();
|
||||||
{
|
|
||||||
if (hrt_elapsed_time(&_sub_vehicle_local_position.get().timestamp) < _timeout) {
|
|
||||||
_position = matrix::Vector3f(&_sub_vehicle_local_position.get().x);
|
|
||||||
_velocity = matrix::Vector3f(&_sub_vehicle_local_position.get().vx);
|
|
||||||
_yaw = _sub_vehicle_local_position.get().yaw;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
_velocity.zero(); /* default velocity is all zero */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -41,6 +41,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "FlightTaskManual.hpp"
|
#include "FlightTaskManual.hpp"
|
||||||
|
#include <float.h>
|
||||||
#include <mathlib/mathlib.h>
|
#include <mathlib/mathlib.h>
|
||||||
|
|
||||||
using namespace matrix;
|
using namespace matrix;
|
||||||
|
|||||||
@@ -44,6 +44,8 @@
|
|||||||
|
|
||||||
#include "FlightTask.hpp"
|
#include "FlightTask.hpp"
|
||||||
#include <mathlib/math/filter/LowPassFilter2p.hpp>
|
#include <mathlib/math/filter/LowPassFilter2p.hpp>
|
||||||
|
#include <systemlib/hysteresis/hysteresis.h>
|
||||||
|
#include <uORB/topics/manual_control_setpoint.h>
|
||||||
|
|
||||||
class FlightTaskManual : public FlightTask
|
class FlightTaskManual : public FlightTask
|
||||||
{
|
{
|
||||||
@@ -76,6 +78,9 @@ public:
|
|||||||
};
|
};
|
||||||
virtual ~FlightTaskManual() {};
|
virtual ~FlightTaskManual() {};
|
||||||
|
|
||||||
|
int activate() override;
|
||||||
|
int disable() override;
|
||||||
|
int update() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
matrix::Vector<float, 4> _sticks;
|
matrix::Vector<float, 4> _sticks;
|
||||||
|
|||||||
@@ -41,6 +41,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "FlightTaskOrbit.hpp"
|
#include "FlightTaskOrbit.hpp"
|
||||||
|
#include <mathlib/mathlib.h>
|
||||||
|
|
||||||
using namespace matrix;
|
using namespace matrix;
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,10 @@ public:
|
|||||||
{};
|
{};
|
||||||
virtual ~FlightTaskOrbit() {};
|
virtual ~FlightTaskOrbit() {};
|
||||||
|
|
||||||
|
int activate() override;
|
||||||
|
int disable() override;
|
||||||
|
int update() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
float r = 0.f; /* radius with which to orbit the target */
|
float r = 0.f; /* radius with which to orbit the target */
|
||||||
|
|||||||
Reference in New Issue
Block a user