2017-11-08 10:57:56 +01:00
|
|
|
#include "FlightTask.hpp"
|
|
|
|
|
#include <mathlib/mathlib.h>
|
|
|
|
|
|
2017-11-08 22:31:14 +01:00
|
|
|
constexpr uint64_t FlightTask::_timeout;
|
|
|
|
|
|
2017-11-20 21:55:28 +01:00
|
|
|
|
|
|
|
|
bool FlightTask::initializeSubscriptions(SubscriptionArray &subscription_array)
|
|
|
|
|
{
|
|
|
|
|
if (!subscription_array.get(ORB_ID(vehicle_local_position), _sub_vehicle_local_position)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-27 21:31:47 +01:00
|
|
|
int FlightTask::activate()
|
|
|
|
|
{
|
|
|
|
|
_time_stamp_activate = hrt_absolute_time();
|
|
|
|
|
update(); /* to get subscriptions and evaluate them */
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-08 10:57:56 +01:00
|
|
|
int FlightTask::update()
|
|
|
|
|
{
|
2017-11-20 14:27:56 +01:00
|
|
|
_time_stamp_current = hrt_absolute_time();
|
|
|
|
|
_time = (_time_stamp_current - _time_stamp_activate) / 1e6f;
|
|
|
|
|
_deltatime = math::min((_time_stamp_current - _time_stamp_last), _timeout) / 1e6f;
|
|
|
|
|
_time_stamp_last = _time_stamp_current;
|
2017-11-28 18:17:39 +01:00
|
|
|
return _evaluate_vehicle_position();
|
2017-11-08 10:57:56 +01:00
|
|
|
}
|
|
|
|
|
|
2017-11-20 16:58:45 +01:00
|
|
|
int FlightTask::_evaluate_vehicle_position()
|
2017-11-08 10:57:56 +01:00
|
|
|
{
|
2017-11-20 21:55:28 +01:00
|
|
|
if ((_time_stamp_current - _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;
|
2017-11-20 16:58:45 +01:00
|
|
|
return 0;
|
2017-11-08 10:57:56 +01:00
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
_velocity.zero(); /* default velocity is all zero */
|
2017-11-20 16:58:45 +01:00
|
|
|
return -1;
|
2017-11-08 10:57:56 +01:00
|
|
|
}
|
|
|
|
|
}
|