Galaxis Codebase  1.0.0
Team Galaxis software stack for the Carolo Cup 2023 - ROS2 based software
marvelmind.h
Go to the documentation of this file.
1 #pragma once
2 #include <stdint.h>
3 #include <stdbool.h>
4 #include <stddef.h>
5 #include <pthread.h>
6 
7 #define DATA_INPUT_SEMAPHORE "/mm_data_input_semaphore"
8 
9 struct PositionValue {
10  uint8_t address;
11  uint32_t timestamp;
12  int32_t x, y, z; // coordinates in millimeters
13 
14  double angle;
15 
17 
18  bool ready;
19  bool processed;
20 };
21 
22 struct RawIMUValue {
23  int16_t acc_x;
24  int16_t acc_y;
25  int16_t acc_z;
26 
27  int16_t gyro_x;
28  int16_t gyro_y;
29  int16_t gyro_z;
30 
31  int16_t compass_x;
32  int16_t compass_y;
33  int16_t compass_z;
34 
35  uint32_t timestamp;
36 
37  bool updated;
38 };
39 
41  int32_t x;
42  int32_t y;
43  int32_t z; // coordinates in mm
44 
45  int16_t qw;
46  int16_t qx;
47  int16_t qy;
48  int16_t qz; // quaternion, normalized to 10000
49 
50  int16_t vx;
51  int16_t vy;
52  int16_t vz; // velocity, mm/s
53 
54  int16_t ax;
55  int16_t ay;
56  int16_t az; // acceleration, mm/s^2
57 
58  uint32_t timestamp;
59 
60  bool updated;
61 };
62 
64  uint8_t address_beacon;
65  uint32_t distance; // distance, mm
66 };
67 struct RawDistances {
68  uint8_t address_hedge;
70 
71  bool updated;
72 };
73 
75  uint8_t address;
76  int32_t x, y, z; // coordinates in millimeters
77 
79 };
80 #define MAX_STATIONARY_BEACONS 30
82  uint8_t numBeacons;
84 
85  bool updated;
86 };
87 
88 #define MAX_BUFFERED_POSITIONS 3
90  // serial port device name (physical or USB/virtual). It should be provided as
91  // an argument:
92  // /dev/ttyACM0 - typical for Linux / Raspberry Pi
93  // /dev/tty.usbmodem1451 - typical for Mac OS X
94  const char* ttyFileName;
95 
96  // Baud rate. Should be match to baudrate of hedgehog-beacon
97  // default: 9600
98  uint32_t baudRate;
99 
100  // buffer of measurements
102 
104 
107 
109 
110  // verbose flag which activate console output
111  // default: False
112  bool verbose;
113 
114  // pause flag. If True, class would not read serial data
115  bool pause;
116 
117  // If True, thread would exit from main loop and stop
119 
120  // receiveDataCallback is callback function to recieve data
121  void (*receiveDataCallback)(struct PositionValue position);
123 
124  // private variables
128 #ifdef WIN32
129  HANDLE thread_;
130  CRITICAL_SECTION lock_;
131 #else
132  pthread_t thread_;
133  pthread_mutex_t lock_;
134 #endif
135 };
136 
137 #define POSITION_DATAGRAM_ID 0x0001
138 #define BEACONS_POSITIONS_DATAGRAM_ID 0x0002
139 #define POSITION_DATAGRAM_HIGHRES_ID 0x0011
140 #define BEACONS_POSITIONS_DATAGRAM_HIGHRES_ID 0x0012
141 #define IMU_RAW_DATAGRAM_ID 0x0003
142 #define BEACON_RAW_DISTANCE_DATAGRAM_ID 0x0004
143 #define IMU_FUSION_DATAGRAM_ID 0x0005
144 
146 void destroyMarvelmindHedge(struct MarvelmindHedge* hedge);
147 void startMarvelmindHedge(struct MarvelmindHedge* hedge);
148 
150  bool onlyNew);
152  struct PositionValue* position);
153 
155  struct StationaryBeaconsPositions* positions);
157  bool onlyNew);
158 
160  struct RawDistances* rawDistances);
162  bool onlyNew);
163 
165  struct RawIMUValue* rawIMU);
167  bool onlyNew);
168 
170  struct FusionIMUValue* fusionIMU);
172  bool onlyNew);
173 
174 void stopMarvelmindHedge(struct MarvelmindHedge* hedge);
175 
176 #ifdef WIN32
177 #define DEFAULT_TTY_FILENAME "\\\\.\\COM3"
178 #else
179 #define DEFAULT_TTY_FILENAME "/dev/ttyACM0"
180 #endif // WIN32
StationaryBeaconPosition::x
int32_t x
Definition: marvelmind.h:76
MarvelmindHedge::positionsBeacons
struct StationaryBeaconsPositions positionsBeacons
Definition: marvelmind.h:103
RawIMUValue
Definition: marvelmind.h:22
MarvelmindHedge::anyInputPacketCallback
void(* anyInputPacketCallback)()
Definition: marvelmind.h:122
PositionValue::z
int32_t z
Definition: marvelmind.h:12
FusionIMUValue::y
int32_t y
Definition: marvelmind.h:42
MarvelmindHedge::fusionIMU
struct FusionIMUValue fusionIMU
Definition: marvelmind.h:106
MarvelmindHedge::terminationRequired
bool terminationRequired
Definition: marvelmind.h:118
MarvelmindHedge::lastValuesCount_
uint8_t lastValuesCount_
Definition: marvelmind.h:125
FusionIMUValue::z
int32_t z
Definition: marvelmind.h:43
FusionIMUValue::qx
int16_t qx
Definition: marvelmind.h:46
MarvelmindHedge::verbose
bool verbose
Definition: marvelmind.h:112
StationaryBeaconPosition::y
int32_t y
Definition: marvelmind.h:76
MarvelmindHedge
Definition: marvelmind.h:89
destroyMarvelmindHedge
void destroyMarvelmindHedge(struct MarvelmindHedge *hedge)
Definition: marvelmind.c:1077
printRawDistancesFromMarvelmindHedge
void printRawDistancesFromMarvelmindHedge(struct MarvelmindHedge *hedge, bool onlyNew)
Definition: marvelmind.c:939
FusionIMUValue::qw
int16_t qw
Definition: marvelmind.h:45
RawIMUValue::acc_y
int16_t acc_y
Definition: marvelmind.h:24
FusionIMUValue::az
int16_t az
Definition: marvelmind.h:56
RawIMUValue::gyro_x
int16_t gyro_x
Definition: marvelmind.h:27
MarvelmindHedge::thread_
pthread_t thread_
Definition: marvelmind.h:132
RawDistances::address_hedge
uint8_t address_hedge
Definition: marvelmind.h:68
MAX_STATIONARY_BEACONS
#define MAX_STATIONARY_BEACONS
Definition: marvelmind.h:80
MarvelmindHedge::pause
bool pause
Definition: marvelmind.h:115
createMarvelmindHedge
struct MarvelmindHedge * createMarvelmindHedge()
Definition: marvelmind.c:688
StationaryBeaconsPositions::updated
bool updated
Definition: marvelmind.h:85
FusionIMUValue::x
int32_t x
Definition: marvelmind.h:41
FusionIMUValue::qy
int16_t qy
Definition: marvelmind.h:47
RawIMUValue::gyro_z
int16_t gyro_z
Definition: marvelmind.h:29
MarvelmindHedge::rawDistances
struct RawDistances rawDistances
Definition: marvelmind.h:108
printRawIMUFromMarvelmindHedge
void printRawIMUFromMarvelmindHedge(struct MarvelmindHedge *hedge, bool onlyNew)
Definition: marvelmind.c:983
getRawIMUFromMarvelmindHedge
bool getRawIMUFromMarvelmindHedge(struct MarvelmindHedge *hedge, struct RawIMUValue *rawIMU)
Definition: marvelmind.c:964
MarvelmindHedge::baudRate
uint32_t baudRate
Definition: marvelmind.h:98
FusionIMUValue
Definition: marvelmind.h:40
PositionValue::y
int32_t y
Definition: marvelmind.h:12
RawDistanceItem::address_beacon
uint8_t address_beacon
Definition: marvelmind.h:64
RawDistanceItem::distance
uint32_t distance
Definition: marvelmind.h:65
getStationaryBeaconsPositionsFromMarvelmindHedge
bool getStationaryBeaconsPositionsFromMarvelmindHedge(struct MarvelmindHedge *hedge, struct StationaryBeaconsPositions *positions)
Definition: marvelmind.c:869
PositionValue
Definition: marvelmind.h:9
FusionIMUValue::qz
int16_t qz
Definition: marvelmind.h:48
StationaryBeaconPosition
Definition: marvelmind.h:74
RawIMUValue::updated
bool updated
Definition: marvelmind.h:37
RawIMUValue::compass_x
int16_t compass_x
Definition: marvelmind.h:31
PositionValue::address
uint8_t address
Definition: marvelmind.h:10
MarvelmindHedge::positionBuffer
struct PositionValue * positionBuffer
Definition: marvelmind.h:101
MarvelmindHedge::ttyFileName
const char * ttyFileName
Definition: marvelmind.h:94
RawDistances::updated
bool updated
Definition: marvelmind.h:71
startMarvelmindHedge
void startMarvelmindHedge(struct MarvelmindHedge *hedge)
Definition: marvelmind.c:718
StationaryBeaconPosition::highResolution
bool highResolution
Definition: marvelmind.h:78
MarvelmindHedge::haveNewValues_
bool haveNewValues_
Definition: marvelmind.h:127
RawIMUValue::acc_x
int16_t acc_x
Definition: marvelmind.h:23
RawIMUValue::compass_y
int16_t compass_y
Definition: marvelmind.h:32
RawDistanceItem
Definition: marvelmind.h:63
PositionValue::processed
bool processed
Definition: marvelmind.h:19
RawIMUValue::acc_z
int16_t acc_z
Definition: marvelmind.h:25
PositionValue::timestamp
uint32_t timestamp
Definition: marvelmind.h:11
printStationaryBeaconsPositionsFromMarvelmindHedge
void printStationaryBeaconsPositionsFromMarvelmindHedge(struct MarvelmindHedge *hedge, bool onlyNew)
Definition: marvelmind.c:888
StationaryBeaconsPositions::beacons
struct StationaryBeaconPosition beacons[MAX_STATIONARY_BEACONS]
Definition: marvelmind.h:83
RawDistances::distances
struct RawDistanceItem distances[4]
Definition: marvelmind.h:69
FusionIMUValue::updated
bool updated
Definition: marvelmind.h:60
FusionIMUValue::vy
int16_t vy
Definition: marvelmind.h:51
PositionValue::angle
double angle
Definition: marvelmind.h:14
RawDistances
Definition: marvelmind.h:67
StationaryBeaconsPositions
Definition: marvelmind.h:81
printPositionFromMarvelmindHedge
void printPositionFromMarvelmindHedge(struct MarvelmindHedge *hedge, bool onlyNew)
Definition: marvelmind.c:825
FusionIMUValue::ax
int16_t ax
Definition: marvelmind.h:54
RawIMUValue::gyro_y
int16_t gyro_y
Definition: marvelmind.h:28
FusionIMUValue::ay
int16_t ay
Definition: marvelmind.h:55
StationaryBeaconsPositions::numBeacons
uint8_t numBeacons
Definition: marvelmind.h:82
MarvelmindHedge::rawIMU
struct RawIMUValue rawIMU
Definition: marvelmind.h:105
StationaryBeaconPosition::z
int32_t z
Definition: marvelmind.h:76
getFusionIMUFromMarvelmindHedge
bool getFusionIMUFromMarvelmindHedge(struct MarvelmindHedge *hedge, struct FusionIMUValue *fusionIMU)
Definition: marvelmind.c:1002
MarvelmindHedge::lastValues_next
uint8_t lastValues_next
Definition: marvelmind.h:126
stopMarvelmindHedge
void stopMarvelmindHedge(struct MarvelmindHedge *hedge)
Definition: marvelmind.c:1062
MarvelmindHedge::lock_
pthread_mutex_t lock_
Definition: marvelmind.h:133
FusionIMUValue::vz
int16_t vz
Definition: marvelmind.h:52
PositionValue::ready
bool ready
Definition: marvelmind.h:18
PositionValue::highResolution
bool highResolution
Definition: marvelmind.h:16
getRawDistancesFromMarvelmindHedge
bool getRawDistancesFromMarvelmindHedge(struct MarvelmindHedge *hedge, struct RawDistances *rawDistances)
Definition: marvelmind.c:920
StationaryBeaconPosition::address
uint8_t address
Definition: marvelmind.h:75
FusionIMUValue::timestamp
uint32_t timestamp
Definition: marvelmind.h:58
PositionValue::x
int32_t x
Definition: marvelmind.h:12
MarvelmindHedge::receiveDataCallback
void(* receiveDataCallback)(struct PositionValue position)
Definition: marvelmind.h:121
FusionIMUValue::vx
int16_t vx
Definition: marvelmind.h:50
printFusionIMUFromMarvelmindHedge
void printFusionIMUFromMarvelmindHedge(struct MarvelmindHedge *hedge, bool onlyNew)
Definition: marvelmind.c:1021
getPositionFromMarvelmindHedge
bool getPositionFromMarvelmindHedge(struct MarvelmindHedge *hedge, struct PositionValue *position)
Definition: marvelmind.c:816
RawIMUValue::compass_z
int16_t compass_z
Definition: marvelmind.h:33
RawIMUValue::timestamp
uint32_t timestamp
Definition: marvelmind.h:35