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-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-08 10:57:56 +01:00
|
|
|
updateSubscriptions();
|
|
|
|
|
_evaluate_vehicle_position();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FlightTask::_evaluate_vehicle_position()
|
|
|
|
|
{
|
2017-11-20 14:27:56 +01:00
|
|
|
if ((_time_stamp_current - _sub_vehicle_local_position.get().timestamp) < _timeout) {
|
2017-11-08 10:57:56 +01:00
|
|
|
_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 */
|
|
|
|
|
}
|
|
|
|
|
}
|