2017-04-03 17:53:50 -03:00
|
|
|
/*
|
2017-05-08 13:10:01 -03: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/>.
|
|
|
|
*/
|
|
|
|
/*
|
2018-05-18 09:48:00 -03:00
|
|
|
Original C Code by Marvelmind (https://github.com/MarvelmindRobotics/marvelmind.c)
|
2017-05-08 13:10:01 -03:00
|
|
|
Adapted into Ardupilot by Karthik Desai, Amilcar Lucas
|
|
|
|
April 2017
|
2017-04-03 17:53:50 -03:00
|
|
|
*/
|
|
|
|
|
2022-01-27 20:09:43 -04:00
|
|
|
#include "AP_Beacon_Marvelmind.h"
|
|
|
|
|
|
|
|
#if AP_BEACON_MARVELMIND_ENABLED
|
|
|
|
|
2017-04-03 17:53:50 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2019-04-19 07:47:11 -03:00
|
|
|
#include <AP_Math/crc.h>
|
2017-04-03 17:53:50 -03:00
|
|
|
|
2017-10-30 19:56:01 -03:00
|
|
|
#define AP_BEACON_MARVELMIND_POSITION_DATAGRAM_ID 0x0001
|
|
|
|
#define AP_BEACON_MARVELMIND_POSITIONS_DATAGRAM_ID 0x0002
|
2017-11-01 08:27:20 -03:00
|
|
|
#define AP_BEACON_MARVELMIND_DISTANCES_DATAGRAM_ID 0x0004
|
2017-10-30 19:56:01 -03:00
|
|
|
#define AP_BEACON_MARVELMIND_POSITION_DATAGRAM_HIGHRES_ID 0x0011
|
|
|
|
#define AP_BEACON_MARVELMIND_POSITIONS_DATAGRAM_HIGHRES_ID 0x0012
|
|
|
|
|
2017-04-03 17:53:50 -03:00
|
|
|
extern const AP_HAL::HAL& hal;
|
|
|
|
|
2018-05-18 10:44:38 -03:00
|
|
|
#define MM_DEBUG_LEVEL 0
|
|
|
|
|
|
|
|
#if MM_DEBUG_LEVEL
|
|
|
|
#include <GCS_MAVLink/GCS.h>
|
2024-08-07 00:17:20 -03:00
|
|
|
#define Debug(level, fmt, args ...) do { if (level <= MM_DEBUG_LEVEL) { GCS_SEND_TEXT(MAV_SEVERITY_INFO, fmt, ## args); } } while (0)
|
2018-05-18 10:44:38 -03:00
|
|
|
#else
|
|
|
|
#define Debug(level, fmt, args ...)
|
|
|
|
#endif
|
|
|
|
|
2018-05-18 10:25:52 -03:00
|
|
|
void AP_Beacon_Marvelmind::process_position_datagram()
|
2017-04-03 17:53:50 -03:00
|
|
|
{
|
2018-05-18 10:25:52 -03:00
|
|
|
hedge.cur_position.address = input_buffer[16];
|
|
|
|
hedge.cur_position.timestamp = input_buffer[5]
|
|
|
|
| (((uint32_t) input_buffer[6]) << 8)
|
|
|
|
| (((uint32_t) input_buffer[7]) << 16)
|
|
|
|
| (((uint32_t) input_buffer[8]) << 24);
|
2017-04-03 17:53:50 -03:00
|
|
|
const int16_t vx = input_buffer[9] | (((uint16_t) input_buffer[10]) << 8);
|
2018-05-18 10:25:52 -03:00
|
|
|
hedge.cur_position.x__mm = vx * 10; // centimeters -> millimeters
|
2017-04-03 17:53:50 -03:00
|
|
|
const int16_t vy = input_buffer[11] | (((uint16_t) input_buffer[12]) << 8);
|
2018-05-18 10:25:52 -03:00
|
|
|
hedge.cur_position.y__mm = vy * 10; // centimeters -> millimeters
|
2017-04-03 17:53:50 -03:00
|
|
|
const int16_t vz = input_buffer[13] | (((uint16_t) input_buffer[14]) << 8);
|
2018-05-18 10:25:52 -03:00
|
|
|
hedge.cur_position.z__mm = vz * 10; // centimeters -> millimeters
|
|
|
|
hedge.cur_position.high_resolution = false;
|
|
|
|
hedge._have_new_values = true;
|
2017-04-03 17:53:50 -03:00
|
|
|
}
|
|
|
|
|
2018-05-18 10:25:52 -03:00
|
|
|
void AP_Beacon_Marvelmind::process_position_highres_datagram()
|
2017-04-03 17:53:50 -03:00
|
|
|
{
|
2018-05-18 10:25:52 -03:00
|
|
|
hedge.cur_position.address = input_buffer[22];
|
|
|
|
hedge.cur_position.timestamp = input_buffer[5]
|
|
|
|
| (((uint32_t) input_buffer[6]) << 8)
|
|
|
|
| (((uint32_t) input_buffer[7]) << 16)
|
|
|
|
| (((uint32_t) input_buffer[8]) << 24);
|
|
|
|
hedge.cur_position.x__mm = input_buffer[9] | (((uint32_t) input_buffer[10]) << 8)
|
|
|
|
| (((uint32_t) input_buffer[11]) << 16)
|
|
|
|
| (((uint32_t) input_buffer[12]) << 24);
|
|
|
|
hedge.cur_position.y__mm = input_buffer[13] | (((uint32_t) input_buffer[14]) << 8)
|
|
|
|
| (((uint32_t) input_buffer[15]) << 16)
|
|
|
|
| (((uint32_t) input_buffer[16]) << 24);
|
|
|
|
hedge.cur_position.z__mm = input_buffer[17] | (((uint32_t) input_buffer[18]) << 8)
|
|
|
|
| (((uint32_t) input_buffer[19]) << 16)
|
|
|
|
| (((uint32_t) input_buffer[20]) << 24);
|
|
|
|
hedge.cur_position.high_resolution = true;
|
|
|
|
hedge._have_new_values = true;
|
2017-04-03 17:53:50 -03:00
|
|
|
}
|
|
|
|
|
2017-05-08 13:10:01 -03:00
|
|
|
AP_Beacon_Marvelmind::StationaryBeaconPosition* AP_Beacon_Marvelmind::get_or_alloc_beacon(uint8_t address)
|
2017-04-03 17:53:50 -03:00
|
|
|
{
|
2018-05-18 10:25:52 -03:00
|
|
|
const uint8_t n_used = hedge.positions_beacons.num_beacons;
|
|
|
|
for (uint8_t i = 0; i < n_used; i++) {
|
|
|
|
if (hedge.positions_beacons.beacons[i].address == address) {
|
|
|
|
return &hedge.positions_beacons.beacons[i];
|
2017-04-03 17:53:50 -03:00
|
|
|
}
|
|
|
|
}
|
2017-05-08 13:10:01 -03:00
|
|
|
if (n_used >= AP_BEACON_MAX_BEACONS) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-05-18 10:25:52 -03:00
|
|
|
hedge.positions_beacons.num_beacons = (n_used + 1);
|
|
|
|
return &hedge.positions_beacons.beacons[n_used];
|
2017-04-03 17:53:50 -03:00
|
|
|
}
|
|
|
|
|
2017-05-08 13:10:01 -03:00
|
|
|
void AP_Beacon_Marvelmind::process_beacons_positions_datagram()
|
2017-04-03 17:53:50 -03:00
|
|
|
{
|
2017-05-08 13:10:01 -03:00
|
|
|
const uint8_t n = input_buffer[5]; // number of beacons in packet
|
|
|
|
StationaryBeaconPosition *stationary_beacon;
|
|
|
|
if ((1 + n * 8) != input_buffer[4]) {
|
2018-05-18 10:44:38 -03:00
|
|
|
Debug(1, "beacon pos lo pkt size %d != %d", input_buffer[4], (1 + n * 8));
|
2017-05-08 13:10:01 -03:00
|
|
|
return; // incorrect size
|
|
|
|
}
|
|
|
|
for (uint8_t i = 0; i < n; i++) {
|
|
|
|
const uint8_t ofs = 6 + i * 8;
|
|
|
|
const uint8_t address = input_buffer[ofs];
|
|
|
|
const int16_t x = input_buffer[ofs + 1]
|
|
|
|
| (((uint16_t) input_buffer[ofs + 2]) << 8);
|
|
|
|
const int16_t y = input_buffer[ofs + 3]
|
|
|
|
| (((uint16_t) input_buffer[ofs + 4]) << 8);
|
|
|
|
const int16_t z = input_buffer[ofs + 5]
|
|
|
|
| (((uint16_t) input_buffer[ofs + 6]) << 8);
|
|
|
|
stationary_beacon = get_or_alloc_beacon(address);
|
|
|
|
if (stationary_beacon != nullptr) {
|
|
|
|
stationary_beacon->address = address; //The instance and the address are the same
|
2018-05-18 10:42:08 -03:00
|
|
|
stationary_beacon->x__mm = x * 10; // centimeters -> millimeters
|
|
|
|
stationary_beacon->y__mm = y * 10; // centimeters -> millimeters
|
|
|
|
stationary_beacon->z__mm = z * 10; // centimeters -> millimeters
|
2017-05-08 13:10:01 -03:00
|
|
|
stationary_beacon->high_resolution = false;
|
2018-05-18 10:25:52 -03:00
|
|
|
hedge.positions_beacons.updated = true;
|
2017-05-08 13:10:01 -03:00
|
|
|
}
|
|
|
|
}
|
2017-05-12 04:54:02 -03:00
|
|
|
order_stationary_beacons();
|
2017-04-03 17:53:50 -03:00
|
|
|
}
|
|
|
|
|
2017-05-08 13:10:01 -03:00
|
|
|
void AP_Beacon_Marvelmind::process_beacons_positions_highres_datagram()
|
2017-04-03 17:53:50 -03:00
|
|
|
{
|
2017-05-08 13:10:01 -03:00
|
|
|
const uint8_t n = input_buffer[5]; // number of beacons in packet
|
|
|
|
StationaryBeaconPosition *stationary_beacon;
|
|
|
|
if ((1 + n * 14) != input_buffer[4]) {
|
2018-05-18 10:44:38 -03:00
|
|
|
Debug(1, "beacon pos hi pkt size %d != %d", input_buffer[4], (1 + n * 14));
|
2017-05-08 13:10:01 -03:00
|
|
|
return; // incorrect size
|
2017-04-03 17:53:50 -03:00
|
|
|
}
|
2017-05-08 13:10:01 -03:00
|
|
|
for (uint8_t i = 0; i < n; i++) {
|
|
|
|
const uint8_t ofs = 6 + i * 14;
|
|
|
|
const uint8_t address = input_buffer[ofs];
|
|
|
|
const int32_t x = input_buffer[ofs + 1]
|
|
|
|
| (((uint32_t) input_buffer[ofs + 2]) << 8)
|
|
|
|
| (((uint32_t) input_buffer[ofs + 3]) << 16)
|
|
|
|
| (((uint32_t) input_buffer[ofs + 4]) << 24);
|
|
|
|
const int32_t y = input_buffer[ofs + 5]
|
|
|
|
| (((uint32_t) input_buffer[ofs + 6]) << 8)
|
|
|
|
| (((uint32_t) input_buffer[ofs + 7]) << 16)
|
|
|
|
| (((uint32_t) input_buffer[ofs + 8]) << 24);
|
|
|
|
const int32_t z = input_buffer[ofs + 9]
|
|
|
|
| (((uint32_t) input_buffer[ofs + 10]) << 8)
|
|
|
|
| (((uint32_t) input_buffer[ofs + 11]) << 16)
|
|
|
|
| (((uint32_t) input_buffer[ofs + 12]) << 24);
|
|
|
|
stationary_beacon = get_or_alloc_beacon(address);
|
|
|
|
if (stationary_beacon != nullptr) {
|
|
|
|
stationary_beacon->address = address; //The instance and the address are the same
|
2018-05-18 10:42:08 -03:00
|
|
|
stationary_beacon->x__mm = x; // millimeters
|
|
|
|
stationary_beacon->y__mm = y; // millimeters
|
|
|
|
stationary_beacon->z__mm = z; // millimeters
|
2017-05-08 13:10:01 -03:00
|
|
|
stationary_beacon->high_resolution = true;
|
2018-05-18 10:25:52 -03:00
|
|
|
hedge.positions_beacons.updated = true;
|
2017-05-08 13:10:01 -03:00
|
|
|
}
|
2017-04-03 17:53:50 -03:00
|
|
|
}
|
2017-05-12 04:54:02 -03:00
|
|
|
order_stationary_beacons();
|
2017-04-03 17:53:50 -03:00
|
|
|
}
|
|
|
|
|
2017-11-01 08:27:20 -03:00
|
|
|
void AP_Beacon_Marvelmind::process_beacons_distances_datagram()
|
|
|
|
{
|
|
|
|
if (32 != input_buffer[4]) {
|
2018-05-18 10:20:15 -03:00
|
|
|
Debug(1, "beacon dist pkt size %d != 32", input_buffer[4]);
|
2017-11-01 08:27:20 -03:00
|
|
|
return; // incorrect size
|
|
|
|
}
|
2018-05-18 10:20:15 -03:00
|
|
|
bool set = false;
|
|
|
|
for (uint8_t i = 0; i < hedge.positions_beacons.num_beacons; i++) {
|
2017-11-01 08:27:20 -03:00
|
|
|
const uint8_t ofs = 6 + i * 6;
|
2018-05-18 10:20:15 -03:00
|
|
|
const uint8_t address = input_buffer[ofs];
|
|
|
|
const int8_t instance = find_beacon_instance(address);
|
|
|
|
if (instance != -1) {
|
|
|
|
const uint32_t distance = input_buffer[ofs + 1]
|
|
|
|
| (((uint32_t) input_buffer[ofs + 2]) << 8)
|
|
|
|
| (((uint32_t) input_buffer[ofs + 3]) << 16)
|
|
|
|
| (((uint32_t) input_buffer[ofs + 4]) << 24);
|
|
|
|
hedge.positions_beacons.beacons[instance].distance__m = distance * 0.001f; // millimeters -> meters
|
|
|
|
set_beacon_distance(instance, hedge.positions_beacons.beacons[instance].distance__m);
|
|
|
|
set = true;
|
|
|
|
Debug(2, "Beacon %d is %.2fm", instance, hedge.positions_beacons.beacons[instance].distance__m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (set) {
|
|
|
|
last_update_ms = AP_HAL::millis();
|
2017-11-01 08:27:20 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-18 09:57:12 -03:00
|
|
|
int8_t AP_Beacon_Marvelmind::find_beacon_instance(uint8_t address) const
|
|
|
|
{
|
|
|
|
for (uint8_t i = 0; i < hedge.positions_beacons.num_beacons; i++) {
|
|
|
|
if (hedge.positions_beacons.beacons[i].address == address) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-04-03 17:53:50 -03:00
|
|
|
void AP_Beacon_Marvelmind::update(void)
|
|
|
|
{
|
2018-05-18 10:25:52 -03:00
|
|
|
if (uart == nullptr) {
|
2017-04-03 17:53:50 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// read any available characters
|
2023-07-13 20:56:39 -03:00
|
|
|
uint16_t num_bytes_read = MIN(uart->available(), 16384U);
|
2017-04-03 17:53:50 -03:00
|
|
|
while (num_bytes_read-- > 0) {
|
|
|
|
bool good_byte = false;
|
2023-07-13 20:56:39 -03:00
|
|
|
if (!uart->read(input_buffer[num_bytes_in_block_received])) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
const uint8_t received_char = input_buffer[num_bytes_in_block_received];
|
2017-04-03 17:53:50 -03:00
|
|
|
switch (parse_state) {
|
|
|
|
case RECV_HDR:
|
|
|
|
switch (num_bytes_in_block_received) {
|
|
|
|
case 0:
|
|
|
|
good_byte = (received_char == 0xff);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
good_byte = (received_char == 0x47);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
good_byte = true;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
data_id = (((uint16_t)received_char) << 8) + input_buffer[2];
|
|
|
|
good_byte = (data_id == AP_BEACON_MARVELMIND_POSITION_DATAGRAM_ID)
|
2017-05-08 13:10:01 -03:00
|
|
|
|| (data_id == AP_BEACON_MARVELMIND_POSITIONS_DATAGRAM_ID)
|
2017-11-01 08:27:20 -03:00
|
|
|
|| (data_id == AP_BEACON_MARVELMIND_DISTANCES_DATAGRAM_ID)
|
2017-05-08 13:10:01 -03:00
|
|
|
|| (data_id == AP_BEACON_MARVELMIND_POSITION_DATAGRAM_HIGHRES_ID)
|
|
|
|
|| (data_id == AP_BEACON_MARVELMIND_POSITIONS_DATAGRAM_HIGHRES_ID);
|
2017-04-03 17:53:50 -03:00
|
|
|
break;
|
|
|
|
case 4: {
|
|
|
|
switch (data_id) {
|
|
|
|
case AP_BEACON_MARVELMIND_POSITION_DATAGRAM_ID: {
|
|
|
|
good_byte = (received_char == 0x10);
|
|
|
|
break;
|
|
|
|
}
|
2017-11-01 08:27:20 -03:00
|
|
|
case AP_BEACON_MARVELMIND_DISTANCES_DATAGRAM_ID:
|
2017-04-03 17:53:50 -03:00
|
|
|
case AP_BEACON_MARVELMIND_POSITIONS_DATAGRAM_ID:
|
|
|
|
case AP_BEACON_MARVELMIND_POSITIONS_DATAGRAM_HIGHRES_ID:
|
|
|
|
good_byte = true;
|
|
|
|
break;
|
|
|
|
case AP_BEACON_MARVELMIND_POSITION_DATAGRAM_HIGHRES_ID: {
|
|
|
|
good_byte = (received_char == 0x16);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (good_byte) {
|
|
|
|
parse_state = RECV_DGRAM;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (good_byte) {
|
|
|
|
// correct header byte
|
|
|
|
num_bytes_in_block_received++;
|
|
|
|
} else {
|
|
|
|
// ...or incorrect
|
|
|
|
parse_state = RECV_HDR;
|
|
|
|
num_bytes_in_block_received = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RECV_DGRAM:
|
|
|
|
num_bytes_in_block_received++;
|
|
|
|
if (num_bytes_in_block_received >= 7 + input_buffer[4]) {
|
|
|
|
// parse dgram
|
|
|
|
uint16_t block_crc = calc_crc_modbus(input_buffer, num_bytes_in_block_received);
|
|
|
|
if (block_crc == 0) {
|
|
|
|
switch (data_id) {
|
2017-05-08 13:10:01 -03:00
|
|
|
case AP_BEACON_MARVELMIND_POSITION_DATAGRAM_ID:
|
|
|
|
{
|
|
|
|
// add to position_buffer
|
2018-05-18 10:25:52 -03:00
|
|
|
process_position_datagram();
|
2017-05-08 13:10:01 -03:00
|
|
|
vehicle_position_initialized = true;
|
2017-11-01 08:27:20 -03:00
|
|
|
set_stationary_beacons_positions();
|
2017-05-08 13:10:01 -03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case AP_BEACON_MARVELMIND_POSITIONS_DATAGRAM_ID:
|
|
|
|
{
|
|
|
|
process_beacons_positions_datagram();
|
|
|
|
beacon_position_initialized = true;
|
2017-11-01 08:27:20 -03:00
|
|
|
set_stationary_beacons_positions();
|
2017-05-08 13:10:01 -03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-11-01 08:27:20 -03:00
|
|
|
case AP_BEACON_MARVELMIND_DISTANCES_DATAGRAM_ID:
|
|
|
|
{
|
|
|
|
process_beacons_distances_datagram();
|
2018-03-19 07:39:15 -03:00
|
|
|
break;
|
2017-11-01 08:27:20 -03:00
|
|
|
}
|
|
|
|
|
2017-05-08 13:10:01 -03:00
|
|
|
case AP_BEACON_MARVELMIND_POSITION_DATAGRAM_HIGHRES_ID:
|
|
|
|
{
|
2018-05-18 10:25:52 -03:00
|
|
|
process_position_highres_datagram();
|
2017-05-08 13:10:01 -03:00
|
|
|
vehicle_position_initialized = true;
|
2017-11-01 08:27:20 -03:00
|
|
|
set_stationary_beacons_positions();
|
2017-05-08 13:10:01 -03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case AP_BEACON_MARVELMIND_POSITIONS_DATAGRAM_HIGHRES_ID:
|
|
|
|
{
|
|
|
|
process_beacons_positions_highres_datagram();
|
|
|
|
beacon_position_initialized = true;
|
2017-11-01 08:27:20 -03:00
|
|
|
set_stationary_beacons_positions();
|
2017-05-08 13:10:01 -03:00
|
|
|
break;
|
2017-04-03 17:53:50 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// and repeat
|
|
|
|
parse_state = RECV_HDR;
|
|
|
|
num_bytes_in_block_received = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-08 13:10:01 -03:00
|
|
|
bool AP_Beacon_Marvelmind::healthy()
|
|
|
|
{
|
|
|
|
// healthy if we have parsed a message within the past 300ms
|
|
|
|
return ((AP_HAL::millis() - last_update_ms) < AP_BEACON_TIMEOUT_MS);
|
|
|
|
}
|
|
|
|
|
2017-11-01 08:27:20 -03:00
|
|
|
void AP_Beacon_Marvelmind::set_stationary_beacons_positions()
|
2017-05-08 13:10:01 -03:00
|
|
|
{
|
2018-05-18 10:46:46 -03:00
|
|
|
bool set = false;
|
2017-05-08 13:10:01 -03:00
|
|
|
if (vehicle_position_initialized && beacon_position_initialized) {
|
2018-05-18 10:25:52 -03:00
|
|
|
if (hedge._have_new_values) {
|
|
|
|
vehicle_position_NED__m = Vector3f(hedge.cur_position.y__mm * 0.001f,
|
|
|
|
hedge.cur_position.x__mm * 0.001f,
|
|
|
|
-hedge.cur_position.z__mm * 0.001f); //Transform Marvelmind ENU to Ardupilot NED
|
2017-05-08 13:10:01 -03:00
|
|
|
//TODO: Calculate Accuracy of the received signal. Marvelmind *advertises* +/- 2cms
|
2018-05-22 07:20:03 -03:00
|
|
|
// But we are conservative here and use 20cm instead (until MM provides us with a proper accuracy value)
|
|
|
|
set_vehicle_position(vehicle_position_NED__m, 0.2f);
|
2018-05-18 10:46:46 -03:00
|
|
|
set = true;
|
2018-05-18 10:25:52 -03:00
|
|
|
Debug(2,
|
2018-05-18 10:44:38 -03:00
|
|
|
"Hedge is at N%.2f, E%.2f, D%.2f",
|
2018-05-18 10:25:52 -03:00
|
|
|
vehicle_position_NED__m[0],
|
|
|
|
vehicle_position_NED__m[1],
|
|
|
|
vehicle_position_NED__m[2]);
|
2017-05-08 13:10:01 -03:00
|
|
|
}
|
2018-05-18 10:25:52 -03:00
|
|
|
hedge._have_new_values = false;
|
|
|
|
for (uint8_t i = 0; i < hedge.positions_beacons.num_beacons; ++i) {
|
|
|
|
if (hedge.positions_beacons.updated) {
|
|
|
|
beacon_position_NED__m[i] = Vector3f(hedge.positions_beacons.beacons[i].y__mm * 0.001f,
|
|
|
|
hedge.positions_beacons.beacons[i].x__mm * 0.001f,
|
|
|
|
-hedge.positions_beacons.beacons[i].z__mm * 0.001f); //Transform Marvelmind ENU to Ardupilot NED
|
2017-05-08 13:10:01 -03:00
|
|
|
set_beacon_position(i, beacon_position_NED__m[i]);
|
2018-05-18 10:46:46 -03:00
|
|
|
set = true;
|
2018-05-18 10:44:38 -03:00
|
|
|
Debug(2,
|
|
|
|
"Beacon %d is at N%.2f, E%.2f, D%.2f",
|
|
|
|
i,
|
|
|
|
beacon_position_NED__m[i][0],
|
|
|
|
beacon_position_NED__m[i][1],
|
|
|
|
beacon_position_NED__m[i][2]);
|
2017-05-08 13:10:01 -03:00
|
|
|
}
|
|
|
|
}
|
2018-05-18 10:25:52 -03:00
|
|
|
hedge.positions_beacons.updated = false;
|
|
|
|
|
|
|
|
}
|
2018-05-18 10:46:46 -03:00
|
|
|
if (set) {
|
|
|
|
last_update_ms = AP_HAL::millis();
|
2017-05-08 13:10:01 -03:00
|
|
|
}
|
|
|
|
}
|
2017-05-12 04:54:02 -03:00
|
|
|
|
|
|
|
void AP_Beacon_Marvelmind::order_stationary_beacons()
|
|
|
|
{
|
2018-05-18 10:25:52 -03:00
|
|
|
if (hedge.positions_beacons.updated) {
|
2017-05-12 04:54:02 -03:00
|
|
|
bool swapped = false;
|
2018-05-18 10:25:52 -03:00
|
|
|
uint8_t j = hedge.positions_beacons.num_beacons;
|
2017-05-12 04:54:02 -03:00
|
|
|
do
|
|
|
|
{
|
|
|
|
swapped = false;
|
|
|
|
StationaryBeaconPosition beacon_to_swap;
|
2018-05-18 10:25:52 -03:00
|
|
|
for (uint8_t i = 1; i < j; i++) {
|
|
|
|
if (hedge.positions_beacons.beacons[i-1].address > hedge.positions_beacons.beacons[i].address) {
|
|
|
|
beacon_to_swap = hedge.positions_beacons.beacons[i];
|
|
|
|
hedge.positions_beacons.beacons[i] = hedge.positions_beacons.beacons[i-1];
|
|
|
|
hedge.positions_beacons.beacons[i-1] = beacon_to_swap;
|
2017-05-12 04:54:02 -03:00
|
|
|
swapped = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
j--;
|
|
|
|
} while(swapped);
|
|
|
|
}
|
|
|
|
}
|
2022-01-27 20:09:43 -04:00
|
|
|
|
|
|
|
#endif // AP_BEACON_MARVELMIND_ENABLED
|