2017-03-01 07:17:45 -04:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "AP_VisualOdom_Backend.h"
|
2020-04-06 00:17:42 -03:00
|
|
|
|
|
|
|
#if HAL_VISUALODOM_ENABLED
|
|
|
|
|
2023-04-14 21:58:02 -03:00
|
|
|
#include <AP_AHRS/AP_AHRS.h>
|
2020-03-26 01:38:51 -03:00
|
|
|
#include <GCS_MAVLink/GCS.h>
|
|
|
|
|
2017-03-01 07:17:45 -04:00
|
|
|
/*
|
|
|
|
base class constructor.
|
|
|
|
This incorporates initialisation as well.
|
|
|
|
*/
|
|
|
|
AP_VisualOdom_Backend::AP_VisualOdom_Backend(AP_VisualOdom &frontend) :
|
|
|
|
_frontend(frontend)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-03-30 02:30:42 -03:00
|
|
|
// return true if sensor is basically healthy (we are receiving data)
|
|
|
|
bool AP_VisualOdom_Backend::healthy() const
|
2017-03-01 07:17:45 -04:00
|
|
|
{
|
2020-03-30 02:30:42 -03:00
|
|
|
// healthy if we have received sensor messages within the past 300ms
|
|
|
|
return ((AP_HAL::millis() - _last_update_ms) < AP_VISUALODOM_TIMEOUT_MS);
|
2017-03-01 07:17:45 -04:00
|
|
|
}
|
2020-04-06 00:17:42 -03:00
|
|
|
|
2023-12-11 02:44:00 -04:00
|
|
|
#if HAL_GCS_ENABLED
|
2020-04-14 00:48:13 -03:00
|
|
|
// consume vision_position_delta mavlink messages
|
|
|
|
void AP_VisualOdom_Backend::handle_vision_position_delta_msg(const mavlink_message_t &msg)
|
|
|
|
{
|
|
|
|
// decode message
|
|
|
|
mavlink_vision_position_delta_t packet;
|
|
|
|
mavlink_msg_vision_position_delta_decode(&msg, &packet);
|
|
|
|
|
|
|
|
// apply rotation to angle and position delta
|
|
|
|
const enum Rotation rot = _frontend.get_orientation();
|
|
|
|
Vector3f angle_delta = Vector3f(packet.angle_delta[0], packet.angle_delta[1], packet.angle_delta[2]);
|
|
|
|
angle_delta.rotate(rot);
|
|
|
|
Vector3f position_delta = Vector3f(packet.position_delta[0], packet.position_delta[1], packet.position_delta[2]);
|
|
|
|
position_delta.rotate(rot);
|
|
|
|
|
|
|
|
const uint32_t now_ms = AP_HAL::millis();
|
|
|
|
_last_update_ms = now_ms;
|
|
|
|
|
|
|
|
// send to EKF
|
2024-03-17 01:08:07 -03:00
|
|
|
#if AP_AHRS_ENABLED || HAL_LOGGING_ENABLED
|
2022-03-15 02:59:26 -03:00
|
|
|
const float time_delta_sec = packet.time_delta_usec * 1.0E-6;
|
2024-03-17 01:08:07 -03:00
|
|
|
#endif
|
2024-01-10 18:16:57 -04:00
|
|
|
#if AP_AHRS_ENABLED
|
2021-07-20 09:16:32 -03:00
|
|
|
AP::ahrs().writeBodyFrameOdom(packet.confidence,
|
|
|
|
position_delta,
|
|
|
|
angle_delta,
|
|
|
|
time_delta_sec,
|
|
|
|
now_ms,
|
|
|
|
_frontend.get_delay_ms(),
|
|
|
|
_frontend.get_pos_offset());
|
2024-01-10 18:16:57 -04:00
|
|
|
#endif
|
2020-04-14 00:48:13 -03:00
|
|
|
|
2023-07-13 21:58:09 -03:00
|
|
|
#if HAL_LOGGING_ENABLED
|
2020-04-14 00:48:13 -03:00
|
|
|
// log sensor data
|
2021-01-22 14:30:14 -04:00
|
|
|
Write_VisualOdom(time_delta_sec,
|
2020-04-14 00:48:13 -03:00
|
|
|
angle_delta,
|
|
|
|
position_delta,
|
|
|
|
packet.confidence);
|
2023-07-13 21:58:09 -03:00
|
|
|
#endif
|
2020-04-14 00:48:13 -03:00
|
|
|
}
|
2023-12-11 02:44:00 -04:00
|
|
|
#endif // HAL_GCS_ENABLED
|
2020-04-14 00:48:13 -03:00
|
|
|
|
2020-04-10 01:36:26 -03:00
|
|
|
// returns the system time of the last reset if reset_counter has not changed
|
|
|
|
// updates the reset timestamp to the current system time if the reset_counter has changed
|
|
|
|
uint32_t AP_VisualOdom_Backend::get_reset_timestamp_ms(uint8_t reset_counter)
|
|
|
|
{
|
|
|
|
// update reset counter and timestamp if reset_counter has changed
|
|
|
|
if (reset_counter != _last_reset_counter) {
|
|
|
|
_last_reset_counter = reset_counter;
|
|
|
|
_reset_timestamp_ms = AP_HAL::millis();
|
|
|
|
}
|
|
|
|
return _reset_timestamp_ms;
|
|
|
|
}
|
|
|
|
|
2020-04-06 00:17:42 -03:00
|
|
|
#endif
|