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
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "AP_Beacon_Backend.h"
|
|
|
|
|
2017-11-01 08:27:20 -03:00
|
|
|
#define AP_BEACON_MARVELMIND_BUF_SIZE 255
|
|
|
|
|
2017-04-03 17:53:50 -03:00
|
|
|
class AP_Beacon_Marvelmind : public AP_Beacon_Backend
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2017-05-08 13:10:01 -03:00
|
|
|
// constructor
|
|
|
|
AP_Beacon_Marvelmind(AP_Beacon &frontend, AP_SerialManager &serial_manager);
|
|
|
|
|
|
|
|
// return true if sensor is basically healthy (we are receiving data)
|
2018-11-07 08:11:40 -04:00
|
|
|
bool healthy() override;
|
2017-05-08 13:10:01 -03:00
|
|
|
|
|
|
|
// update
|
2018-11-07 08:11:40 -04:00
|
|
|
void update() override;
|
2017-05-08 13:10:01 -03:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Variables for Marvelmind
|
2017-04-03 17:53:50 -03:00
|
|
|
struct PositionValue
|
|
|
|
{
|
|
|
|
uint8_t address;
|
|
|
|
uint32_t timestamp;
|
2018-05-18 10:42:08 -03:00
|
|
|
int32_t x__mm, y__mm, z__mm;
|
2017-04-03 17:53:50 -03:00
|
|
|
bool high_resolution;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct StationaryBeaconPosition
|
|
|
|
{
|
|
|
|
uint8_t address;
|
2018-05-18 10:42:08 -03:00
|
|
|
int32_t x__mm, y__mm, z__mm;
|
2017-04-03 17:53:50 -03:00
|
|
|
bool high_resolution;
|
2018-05-18 10:20:15 -03:00
|
|
|
float distance__m; // Distance between beacon and hedge
|
2017-04-03 17:53:50 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct StationaryBeaconsPositions
|
|
|
|
{
|
|
|
|
uint8_t num_beacons;
|
2017-05-08 13:10:01 -03:00
|
|
|
StationaryBeaconPosition beacons[AP_BEACON_MAX_BEACONS];
|
2017-04-03 17:53:50 -03:00
|
|
|
bool updated;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MarvelmindHedge
|
|
|
|
{
|
2017-05-08 13:10:01 -03:00
|
|
|
StationaryBeaconsPositions positions_beacons;
|
2018-05-18 10:25:52 -03:00
|
|
|
PositionValue cur_position;
|
2017-04-03 17:53:50 -03:00
|
|
|
bool _have_new_values;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
RECV_HDR,
|
|
|
|
RECV_DGRAM
|
|
|
|
} parse_state; // current state of receive data
|
|
|
|
|
2018-05-18 10:25:52 -03:00
|
|
|
MarvelmindHedge hedge;
|
2017-04-03 17:53:50 -03:00
|
|
|
uint8_t input_buffer[AP_BEACON_MARVELMIND_BUF_SIZE];
|
|
|
|
uint16_t num_bytes_in_block_received;
|
|
|
|
uint16_t data_id;
|
|
|
|
|
|
|
|
uint16_t calc_crc_modbus(uint8_t *buf, uint16_t len);
|
2017-05-08 13:10:01 -03:00
|
|
|
StationaryBeaconPosition* get_or_alloc_beacon(uint8_t address);
|
|
|
|
void process_beacons_positions_datagram();
|
|
|
|
void process_beacons_positions_highres_datagram();
|
2018-05-18 10:25:52 -03:00
|
|
|
void process_position_highres_datagram();
|
|
|
|
void process_position_datagram();
|
2017-11-01 08:27:20 -03:00
|
|
|
void process_beacons_distances_datagram();
|
|
|
|
void set_stationary_beacons_positions();
|
2017-05-12 04:54:02 -03:00
|
|
|
void order_stationary_beacons();
|
2018-05-18 09:57:12 -03:00
|
|
|
int8_t find_beacon_instance(uint8_t address) const;
|
2017-05-08 13:10:01 -03:00
|
|
|
|
|
|
|
// Variables for Ardupilot
|
|
|
|
AP_HAL::UARTDriver *uart;
|
|
|
|
uint32_t last_update_ms;
|
|
|
|
|
|
|
|
// cache the vehicle position in NED coordinates [m]
|
|
|
|
Vector3f vehicle_position_NED__m;
|
|
|
|
bool vehicle_position_initialized;
|
2017-04-03 17:53:50 -03:00
|
|
|
|
2017-05-08 13:10:01 -03:00
|
|
|
// cache the beacon positions in NED coordinates [m]
|
|
|
|
Vector3f beacon_position_NED__m[AP_BEACON_MAX_BEACONS];
|
|
|
|
bool beacon_position_initialized;
|
2017-04-03 17:53:50 -03:00
|
|
|
};
|
|
|
|
|