Common
common packages for kyubic
 
Loading...
Searching...
No Matches
g366.hpp
Go to the documentation of this file.
1
10#ifndef _G366_HPP
11#define _G366_HPP
12
13#include <cstdint>
14#include <memory>
15#include <serial/serial.hpp>
16
22{
23
28{
29 unsigned char head;
30 short flag;
31 short gpio;
32 short count;
33 unsigned char foot;
34};
35
39struct DATA
40{
42 float temp;
43 float x_gyro;
44 float y_gyro;
45 float z_gyro;
46 float x_accl;
47 float y_accl;
48 float z_accl;
49 float qtn0;
50 float qtn1;
51 float qtn2;
52 float qtn3;
53 float roll;
54 float pitch;
55 float yaw;
56};
57
62{
63 unsigned char head;
64 short flag;
65 short temp;
66 short x_gyro;
67 short y_gyro;
68 short z_gyro;
69 short x_accl;
70 short y_accl;
71 short z_accl;
72 short qtn0;
73 short qtn1;
74 short qtn2;
75 short qtn3;
76 short roll;
77 short pitch;
78 short yaw;
79 short gpio;
80 short count;
81 unsigned char foot;
82};
83
89using command = const unsigned char;
90command window0_select_wcomm[3] = {0xFE, 0x00, 0x0d};
91command window1_select_wcomm[3] = {0xFE, 0x01, 0x0d};
92
93command burst_request_wcomm0[3] = {0x80, 0x00, 0x0d};
94command config_mode_wcomm0[3] = {0x83, 0x00, 0x0d};
95command sampling_mode_wcomm0[3] = {0x83, 0x01, 0x0d};
96command diag_stat_rcomm0[3] = {0x04, 0x00, 0x0d};
97command self_test_wcomm1[3] = {0x83, 0x04, 0x0d};
98command self_test_rcomm1[3] = {0x02, 0x00, 0x0d};
99command software_reset_wcomm1[3] = {0x8A, 0x80, 0x0d};
100command check_ready_rcomm1[3] = {0x0A, 0x00, 0x0d};
101command filter_ctrl_wcomm1[3] = {0x86, 0x00, 0x0d};
102command filter_ctrl_rcomm1[3] = {0x06, 0x00, 0x0d};
103command atti_motion_wcomm1[3] = {0x96, 0x00, 0x0d};
104command atti_motion_rcomm1[3] = {0x16, 0x00, 0x0d};
105command baud_rate_460_wcomm1[3] = {0x89, 0x00, 0x0d};
106command baud_rate_230_wcomm1[3] = {0x89, 0x01, 0x0d};
107command baud_rate_921_wcomm1[3] = {0x89, 0x02, 0x0d};
108
110 0xFE, 0x01, 0x0d,
111 0x85, 0x09, 0x0d,
112 0x88, 0x00, 0x0d,
113 0x8C, 0x06, 0x0d,
114 0x8D, 0xF3, 0x0d,
115 0x8F, 0x00, 0x0d,
116 0x93, 0x00, 0x0d,
117 0x94, 0x00, 0x0d,
118 0x95, 0x0c, 0x0d,
119};
120
121const int default_baudrate = 460800;
122
126const double temp_sf = 0.00699411;
127const double gyro_sf = 1.0 / 66.0;
128const double accel_sf = 1.0 / 4.0;
129const double qtn_sf = 1.0 / (1 << 14);
130const double atti_sf = 0.00699411;
131
135class G366
136{
137public:
144 explicit G366(const char * _portname, const int _baudrate);
145
146 ~G366();
147
151 uint16_t concat_8bit(uint8_t msb, uint8_t lsb);
152
157 void set_baud_rate(int baudrate);
158
164 void set_filter(uint8_t filter_type = 8);
165
171 void set_atti_motion_profile(uint8_t motion_type = 32);
172
177 uint16_t self_test();
178
182 void software_reset();
183
188 bool is_ready();
189
194 std::shared_ptr<DATA> get_data();
195
199 bool setup();
200
205 bool update();
206
207private:
208 const char * portname_;
209 const int baudrate_;
210
211 DATA data;
212
213 std::shared_ptr<serial::Serial> serial_;
214
219 uint16_t diagnostic_status();
220
224 void print_diag_status(uint16_t status);
225};
226
227// class G366HWReseter
228// {
229// public:
230// /**
231// * @
232// */
233// explicit G366HWReseter(const char * _portname, const int _baudrate);
234//
235// void reset();
236//
237// private:
238// const char * portname;
239// const int baudrate;
240//
241// std::shared_ptr<serial::Serial> serial_;
242//
243// const unsigned char reset_comm = 'r';
244// };
245
246} // namespace driver::imu_driver::g366
247
248#endif
for 16bit attitude data [degree/LSB]
Definition: g366.hpp:136
uint16_t self_test()
Run a self-test.
Definition: g366.cpp:302
~G366()
Definition: g366.cpp:29
void software_reset()
Run a software reset.
Definition: g366.cpp:334
uint16_t concat_8bit(uint8_t msb, uint8_t lsb)
Concatenate 8bit to 16bit.
Definition: g366.cpp:159
std::shared_ptr< DATA > get_data()
Get G366 data.
Definition: g366.cpp:359
void set_atti_motion_profile(uint8_t motion_type=32)
Set attitude motion profile.
Definition: g366.cpp:212
bool update()
Update g366 data.
Definition: g366.cpp:80
bool is_ready()
Check ready.
Definition: g366.cpp:342
void set_baud_rate(int baudrate)
Set baudrate.
Definition: g366.cpp:164
bool setup()
Setting G366 configuration.
Definition: g366.cpp:31
void set_filter(uint8_t filter_type=8)
Set filter.
Definition: g366.cpp:180
Definition: g366.hpp:22
command software_reset_wcomm1[3]
Read self test status.
Definition: g366.hpp:99
command baud_rate_921_wcomm1[3]
Set baud rate (230400bps)
Definition: g366.hpp:107
const double accel_sf
for 16bit gyro data [(degree/s)/LSB]
Definition: g366.hpp:128
command atti_motion_wcomm1[3]
Read set filter status.
Definition: g366.hpp:103
const double atti_sf
for 16bit quaternion data [-/LSB]
Definition: g366.hpp:130
command config_mode_wcomm0[3]
Burst command (BURST Mode). Read data.
Definition: g366.hpp:94
const int default_baudrate
Definition: g366.hpp:121
command diag_stat_rcomm0[3]
Select sampling mode.
Definition: g366.hpp:96
command window1_select_wcomm[3]
Select Window 0.
Definition: g366.hpp:91
command self_test_rcomm1[3]
Self test command.
Definition: g366.hpp:98
command sampling_mode_wcomm0[3]
Select configuration mode.
Definition: g366.hpp:95
command baud_rate_460_wcomm1[3]
Read set profile status.
Definition: g366.hpp:105
command filter_ctrl_rcomm1[3]
Set Filter command.
Definition: g366.hpp:102
command burst_request_wcomm0[3]
Select Window 1.
Definition: g366.hpp:93
command config_comm[33]
Set baud rate (921600bps)
Definition: g366.hpp:109
command check_ready_rcomm1[3]
Software reset command.
Definition: g366.hpp:100
command window0_select_wcomm[3]
Definition: g366.hpp:90
command filter_ctrl_wcomm1[3]
Read ready status.
Definition: g366.hpp:101
command baud_rate_230_wcomm1[3]
Set baud rate (460800bps)
Definition: g366.hpp:106
command self_test_wcomm1[3]
Read Diagnostic status.
Definition: g366.hpp:97
command atti_motion_rcomm1[3]
Set attitude mortion profile.
Definition: g366.hpp:104
const double qtn_sf
for 16bit, output range ±8 acceleration data [(mG)/LSB]
Definition: g366.hpp:129
const double temp_sf
Default baudrate.
Definition: g366.hpp:126
const double gyro_sf
for 16bit attitude data [degree celsius/LSB]
Definition: g366.hpp:127
const unsigned char command
Commands to configure the G366.
Definition: g366.hpp:89
serial library
Store meta data of G366.
Definition: g366.hpp:28
unsigned char head
Definition: g366.hpp:29
short flag
Definition: g366.hpp:30
unsigned char foot
Definition: g366.hpp:33
short count
Definition: g366.hpp:32
short gpio
Definition: g366.hpp:31
Store data with modified type of G366.
Definition: g366.hpp:40
float y_accl
Definition: g366.hpp:47
DATA_META meta
Definition: g366.hpp:41
float temp
Definition: g366.hpp:42
float x_gyro
Definition: g366.hpp:43
float pitch
Definition: g366.hpp:54
float roll
Definition: g366.hpp:53
float z_gyro
Definition: g366.hpp:45
float yaw
Definition: g366.hpp:55
float qtn0
Definition: g366.hpp:49
float y_gyro
Definition: g366.hpp:44
float x_accl
Definition: g366.hpp:46
float qtn3
Definition: g366.hpp:52
float z_accl
Definition: g366.hpp:48
float qtn2
Definition: g366.hpp:51
float qtn1
Definition: g366.hpp:50
Store raw data of G355.
Definition: g366.hpp:62
short pitch
Definition: g366.hpp:77
unsigned char foot
Definition: g366.hpp:81
short x_gyro
Definition: g366.hpp:66
short qtn3
Definition: g366.hpp:75
short y_accl
Definition: g366.hpp:70
short qtn2
Definition: g366.hpp:74
short count
Definition: g366.hpp:80
short y_gyro
Definition: g366.hpp:67
short flag
Definition: g366.hpp:64
short qtn0
Definition: g366.hpp:72
short gpio
Definition: g366.hpp:79
short roll
Definition: g366.hpp:76
short yaw
Definition: g366.hpp:78
short z_accl
Definition: g366.hpp:71
short x_accl
Definition: g366.hpp:69
short qtn1
Definition: g366.hpp:73
short temp
Definition: g366.hpp:65
short z_gyro
Definition: g366.hpp:68
unsigned char head
Definition: g366.hpp:63