CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_Beacon/AP_Beacon_Marvelmind.h
Views: 1798
1
/*
2
This program is free software: you can redistribute it and/or modify
3
it under the terms of the GNU General Public License as published by
4
the Free Software Foundation, either version 3 of the License, or
5
(at your option) any later version.
6
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
11
12
You should have received a copy of the GNU General Public License
13
along with this program. If not, see <http://www.gnu.org/licenses/>.
14
*/
15
/*
16
Original C Code by Marvelmind (https://github.com/MarvelmindRobotics/marvelmind.c)
17
Adapted into Ardupilot by Karthik Desai, Amilcar Lucas
18
April 2017
19
*/
20
21
#pragma once
22
23
#include "AP_Beacon_Backend.h"
24
25
#if AP_BEACON_MARVELMIND_ENABLED
26
27
#define AP_BEACON_MARVELMIND_BUF_SIZE 255
28
29
class AP_Beacon_Marvelmind : public AP_Beacon_Backend
30
{
31
public:
32
33
// constructor
34
using AP_Beacon_Backend::AP_Beacon_Backend;
35
36
// return true if sensor is basically healthy (we are receiving data)
37
bool healthy() override;
38
39
// update
40
void update() override;
41
42
private:
43
// Variables for Marvelmind
44
struct PositionValue
45
{
46
uint8_t address;
47
uint32_t timestamp;
48
int32_t x__mm, y__mm, z__mm;
49
bool high_resolution;
50
};
51
52
struct StationaryBeaconPosition
53
{
54
uint8_t address;
55
int32_t x__mm, y__mm, z__mm;
56
bool high_resolution;
57
float distance__m; // Distance between beacon and hedge
58
};
59
60
struct StationaryBeaconsPositions
61
{
62
uint8_t num_beacons;
63
StationaryBeaconPosition beacons[AP_BEACON_MAX_BEACONS];
64
bool updated;
65
};
66
67
struct MarvelmindHedge
68
{
69
StationaryBeaconsPositions positions_beacons;
70
PositionValue cur_position;
71
bool _have_new_values;
72
};
73
74
enum {
75
RECV_HDR,
76
RECV_DGRAM
77
} parse_state = RECV_HDR; // current state of receive data
78
79
MarvelmindHedge hedge;
80
uint8_t input_buffer[AP_BEACON_MARVELMIND_BUF_SIZE];
81
uint16_t num_bytes_in_block_received;
82
uint16_t data_id;
83
84
StationaryBeaconPosition* get_or_alloc_beacon(uint8_t address);
85
void process_beacons_positions_datagram();
86
void process_beacons_positions_highres_datagram();
87
void process_position_highres_datagram();
88
void process_position_datagram();
89
void process_beacons_distances_datagram();
90
void set_stationary_beacons_positions();
91
void order_stationary_beacons();
92
int8_t find_beacon_instance(uint8_t address) const;
93
94
// Variables for Ardupilot
95
uint32_t last_update_ms;
96
97
// cache the vehicle position in NED coordinates [m]
98
Vector3f vehicle_position_NED__m;
99
bool vehicle_position_initialized;
100
101
// cache the beacon positions in NED coordinates [m]
102
Vector3f beacon_position_NED__m[AP_BEACON_MAX_BEACONS];
103
bool beacon_position_initialized;
104
};
105
106
#endif // AP_BEACON_MARVELMIND_ENABLED
107
108