sensor_epsonG330_G366.c
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // sensor_epsonG330_G366.c - Epson IMU sensor protocol specific code for
4 // G330PDG0, G366PDG0
5 //
6 //
7 // THE SOFTWARE IS RELEASED INTO THE PUBLIC DOMAIN.
8 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
10 // NONINFRINGEMENT, SECURITY, SATISFACTORY QUALITY, AND FITNESS FOR A
11 // PARTICULAR PURPOSE. IN NO EVENT SHALL EPSON BE LIABLE FOR ANY LOSS, DAMAGE
12 // OR CLAIM, ARISING FROM OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF THE
13 // SOFTWARE.
14 //
15 //==============================================================================
16 #include "hcl.h"
17 #include "hcl_gpio.h"
18 #include "sensor_epsonCommon.h"
19 
20 /*****************************************************************************
21 ** Function name: sensorInitOptions
22 ** Description: Initialize the sensor hardware to desired settings
23 ** based on EpsonOptions
24 ** Parameters: struct EpsonOptions
25 ** Return value: OK or NG
26 **
27 *****************************************************************************/
28 int sensorInitOptions(struct EpsonOptions options) {
29  unsigned int debug = FALSE;
30 
31  // SIG_CTRL
32  // ND flags for gyro_delta_out X,Y,Z are enabled if gyro_delta_out is enabled
33  // ND flags for accel_delta_out X,Y,Z are enabled if accel_delta_out is
34  // enabled
35 
36  int sig_ctrl_lo = (options.gyro_delta_out & 0x01) << 2 |
37  (options.gyro_delta_out & 0x01) << 3 |
38  (options.gyro_delta_out & 0x01) << 4 |
39  (options.accel_delta_out & 0x01) << 5 |
40  (options.accel_delta_out & 0x01) << 6 |
41  (options.accel_delta_out & 0x01) << 7;
42 
43  // ND flags for gyro_out X,Y,Z are enabled if gyro_out is enabled
44  // ND flags for accel_out X,Y,Z are enabled if accel_out is enabled
45  // ND flag for temp_out is enabled if temp_out is enabled
46 
47  int sig_ctrl_hi =
48  (options.accel_out & 0x01) << 1 | (options.accel_out & 0x01) << 2 |
49  (options.accel_out & 0x01) << 3 | (options.gyro_out & 0x01) << 4 |
50  (options.gyro_out & 0x01) << 5 | (options.gyro_out & 0x01) << 6 |
51  (options.temp_out & 0x01) << 7;
52 
53  // MSC_CTRL
54  // Configure DRDY function (if needed) & EXT pin function on GPIO2 (if needed)
55  // External Counter Reset is typically used when GPIO2 is connected to a
56  // PPS-like signal
57 
58  int msc_ctrl_lo =
59  (options.drdy_pol & 0x01) << 1 | (options.drdy_on & 0x01) << 2 |
60  (options.ext_pol & 0x01) << 5 | (options.ext_sel & 0x03) << 6;
61 
62  // SMPL_CTRL
63  // Configures the Data Output Rate of the IMU.
64  // Refer to Datasheet for valid Data Output Rate & Filter Setting combinations
65 
66  int smpl_ctrl_hi = (options.dout_rate & 0x0F);
67 
68  // FILTER_CTRL
69  // Configures the FIR filter of the IMU.
70  // Refer to Datasheet for valid Data Output Rate & Filter Setting combinations
71  // If External Trigger is enabled on GPIO2, then it is recommended to set the
72  // the FILTER_SEL=0. And program the GYRO_LPF_FC & ACCL_LPF_FC to meet Nyquist
73  // based on the Trigger Frequency.
74 
75  int filter_ctrl_lo = (options.filter_sel & 0x1F);
76 
77  // BURST_CTRL1
78  // These enable or disable certain data fields in the burst read packet
79  // For G330 or G366 specifically, attitude output can be enabled or disabled.
80 
81  int burst_ctrl1_lo = (options.checksum_out & 0x1) |
82  (options.count_out & 0x1) << 1 |
83  (options.gpio_out & 0x01) << 2;
84 
85  int burst_ctrl1_hi =
86  (options.atti_out & 0x1) | (options.qtn_out & 0x1) << 1 |
87  (options.gyro_delta_out & 0x1) << 2 |
88  (options.accel_delta_out & 0x01) << 3 | (options.accel_out & 0x01) << 4 |
89  (options.gyro_out & 0x01) << 5 | (options.temp_out & 0x01) << 6 |
90  (options.flag_out & 0x01) << 7;
91 
92  // BURST_CTRL2
93  // If certain data fields are enabled, these bits determine if the
94  // data fields are 16 or 32 bit
95 
96  int burst_ctrl2_hi =
97  (options.atti_bit & 0x1) | (options.qtn_bit & 0x01) << 1 |
98  (options.gyro_delta_bit & 0x01) << 2 |
99  (options.accel_delta_bit & 0x01) << 3 | (options.accel_bit & 0x01) << 4 |
100  (options.gyro_bit & 0x01) << 5 | (options.temp_bit & 0x01) << 6;
101 
102  // DLT_CTRL
103  // Enable or disable Delta Angle/Velocity overflow flag in DIAG_STAT
104  // Set A_RANGE_CTRL to 1, if macro defined
105  // Set the Delta Angle/Velocity Scale Factor
106 
107 #ifdef ACCL_RANGE_16G
108  int dlt_ctrl_hi = (options.dlt_ovf_en & 0x01) << 1 | 1;
109 #else
110  int dlt_ctrl_hi = (options.dlt_ovf_en & 0x01) << 1;
111 #endif // ACCL_RANGE_16G
112 
113  int dlt_ctrl_lo =
114  (options.dlt_range_ctrl & 0x0F) << 4 | (options.dlt_range_ctrl & 0x0F);
115 
116  // ATTI_CTRL
117  // Attitude Output & Delta Angle/Velocity functions are mutually exclusive.
118  // User should only enable one or the other, but not both.
119  // Attitude Mode = 0=Inclination 1=Euler
120 
121  int atti_ctrl_hi = (options.gyro_delta_out & 0x01) << 1 |
122  ((options.atti_out | options.qtn_out) & 0x01) << 2 |
123  (options.atti_mode & 0x01) << 3;
124 
125  // ATTI_CTRL
126  // Refer to datasheet to determine the different Euler Angle configurations
127  int atti_ctrl_lo = (options.atti_conv & 0x1f);
128 
129  // POL_CTRL
130  // If these bits are set, then the axis values are reverse polarity
131 
132  int pol_ctrl_lo =
133  (options.invert_zaccel & 0x01) << 1 |
134  (options.invert_yaccel & 0x01) << 2 |
135  (options.invert_xaccel & 0x01) << 3 | (options.invert_zgyro & 0x01) << 4 |
136  (options.invert_ygyro & 0x01) << 5 | (options.invert_xgyro & 0x01) << 6;
137 
138  registerWriteByte(CMD_WINDOW1, ADDR_SIG_CTRL_HI, sig_ctrl_hi, debug);
139  registerWriteByte(CMD_WINDOW1, ADDR_SIG_CTRL_LO, sig_ctrl_lo, debug);
140  registerWriteByte(CMD_WINDOW1, ADDR_MSC_CTRL_LO, msc_ctrl_lo, debug);
141  registerWriteByte(CMD_WINDOW1, ADDR_SMPL_CTRL_HI, smpl_ctrl_hi, debug);
142  registerWriteByte(CMD_WINDOW1, ADDR_POL_CTRL_LO, pol_ctrl_lo, debug);
143  registerWriteByte(CMD_WINDOW1, ADDR_FILTER_CTRL_LO, filter_ctrl_lo, debug);
144 
145  // All models except V340
146  // Delay for filter config
148 
149  // Check that the FILTER_BUSY bit returns 0
150  unsigned short rxData;
151  unsigned short retryCount = 3000;
152  do {
154  retryCount--;
155  } while ((rxData & 0x0020) == 0x0020 && (retryCount != 0));
156 
157  if (retryCount == 0) {
158  printf("\r\n...Error: Filter busy bit did not return to 0b.");
159  return NG;
160  }
161 
162 #ifdef SPI // Always disable UART_AUTO mode for burst reading when using SPI IF
164 #else
166 #endif
167 
168  registerWriteByte(CMD_WINDOW1, ADDR_BURST_CTRL1_LO, burst_ctrl1_lo, debug);
169  registerWriteByte(CMD_WINDOW1, ADDR_BURST_CTRL1_HI, burst_ctrl1_hi, debug);
170  registerWriteByte(CMD_WINDOW1, ADDR_BURST_CTRL2_HI, burst_ctrl2_hi, debug);
171  registerWriteByte(CMD_WINDOW1, ADDR_DLT_CTRL_HI, dlt_ctrl_hi, debug);
172  registerWriteByte(CMD_WINDOW1, ADDR_DLT_CTRL_LO, dlt_ctrl_lo, debug);
173  registerWriteByte(CMD_WINDOW1, ADDR_ATTI_CTRL_HI, atti_ctrl_hi, debug);
174  registerWriteByte(CMD_WINDOW1, ADDR_ATTI_CTRL_LO, atti_ctrl_lo, debug);
175 
176  // Setting Attitude Motion Profile
177  int glob_cmd2_lo = (options.atti_profile & 0x03) << 4;
178 
179  registerWriteByte(CMD_WINDOW1, ADDR_GLOB_CMD2_LO, glob_cmd2_lo, debug);
181 
182  return OK;
183 }
184 
185 /*****************************************************************************
186 ** Function name: registerDump
187 ** Description: Read all registers for debug purpose
188 ** Parameters: None
189 ** Return value: None
190 *****************************************************************************/
191 void registerDump(void) {
192  unsigned int debug = TRUE;
193  printf("\r\nRegister Dump:\r\n");
194  registerRead16(0x00, 0x02, debug);
195  registerRead16(0x00, 0x04, debug);
196  registerRead16(0x00, 0x06, debug);
197  printf("\r\n");
198  registerRead16(0x00, 0x08, debug);
199  registerRead16(0x00, 0x0A, debug);
200  registerRead16(0x00, 0x0C, debug);
201  printf("\r\n");
202  registerRead16(0x00, 0x0E, debug);
203  registerRead16(0x00, 0x10, debug);
204  registerRead16(0x00, 0x12, debug);
205  printf("\r\n");
206  registerRead16(0x00, 0x14, debug);
207  registerRead16(0x00, 0x16, debug);
208  registerRead16(0x00, 0x18, debug);
209  printf("\r\n");
210  registerRead16(0x00, 0x1A, debug);
211  registerRead16(0x00, 0x1C, debug);
212  registerRead16(0x00, 0x1E, debug);
213  printf("\r\n");
214  registerRead16(0x00, 0x20, debug);
215  registerRead16(0x00, 0x22, debug);
216  registerRead16(0x00, 0x24, debug);
217  printf("\r\n");
218  registerRead16(0x00, 0x26, debug);
219  registerRead16(0x00, 0x28, debug);
220 
221  registerRead16(0x00, 0x4C, debug);
222  printf("\r\n");
223  registerRead16(0x00, 0x50, debug);
224  registerRead16(0x00, 0x52, debug);
225  registerRead16(0x00, 0x54, debug);
226  printf("\r\n");
227  registerRead16(0x00, 0x56, debug);
228  registerRead16(0x00, 0x58, debug);
229  registerRead16(0x00, 0x5A, debug);
230  printf("\r\n");
231  registerRead16(0x00, 0x5C, debug);
232  registerRead16(0x00, 0x5E, debug);
233 
234  registerRead16(0x00, 0x64, debug);
235  printf("\r\n");
236  registerRead16(0x00, 0x66, debug);
237  registerRead16(0x00, 0x68, debug);
238  registerRead16(0x00, 0x6A, debug);
239  printf("\r\n");
240  registerRead16(0x00, 0x6C, debug);
241  registerRead16(0x00, 0x6E, debug);
242  registerRead16(0x00, 0x70, debug);
243  printf("\r\n");
244  registerRead16(0x00, 0x72, debug);
245  registerRead16(0x00, 0x74, debug);
246  registerRead16(0x00, 0x76, debug);
247  printf("\r\n");
248  registerRead16(0x00, 0x78, debug);
249  registerRead16(0x00, 0x7A, debug);
250  printf("\r\n");
251  registerRead16(0x01, 0x00, debug);
252  registerRead16(0x01, 0x02, debug);
253  registerRead16(0x01, 0x04, debug);
254  printf("\r\n");
255  registerRead16(0x01, 0x06, debug);
256  registerRead16(0x01, 0x08, debug);
257  registerRead16(0x01, 0x0A, debug);
258  printf("\r\n");
259  registerRead16(0x01, 0x0C, debug);
260  registerRead16(0x01, 0x0E, debug);
261  registerRead16(0x01, 0x10, debug);
262  printf("\r\n");
263  registerRead16(0x01, 0x12, debug);
264  registerRead16(0x01, 0x14, debug);
265  registerRead16(0x01, 0x16, debug);
266  printf("\r\n");
267 
268  registerRead16(0x01, 0x6A, debug);
269  registerRead16(0x01, 0x6C, debug);
270  registerRead16(0x01, 0x6E, debug);
271  printf("\r\n");
272  registerRead16(0x01, 0x70, debug);
273  registerRead16(0x01, 0x72, debug);
274  registerRead16(0x01, 0x74, debug);
275  printf("\r\n");
276  registerRead16(0x01, 0x76, debug);
277  registerRead16(0x01, 0x78, debug);
278  registerRead16(0x01, 0x7A, debug);
279  printf("\r\n");
280  registerRead16(0x01, 0x7E, debug);
281  printf("\r\n");
282 }
EpsonOptions::invert_xgyro
int invert_xgyro
Definition: sensor_epsonCommon.h:107
EpsonOptions::accel_delta_bit
int accel_delta_bit
Definition: sensor_epsonCommon.h:102
sensor_epsonCommon.h
TRUE
#define TRUE
Definition: sensor_epsonCommon.h:23
EpsonOptions::ext_pol
int ext_pol
Definition: sensor_epsonCommon.h:73
ADDR_BURST_CTRL2_HI
#define ADDR_BURST_CTRL2_HI
Definition: sensor_epsonG320.h:126
EpsonOptions::atti_mode
int atti_mode
Definition: sensor_epsonCommon.h:119
EpsonOptions::drdy_on
int drdy_on
Definition: sensor_epsonCommon.h:74
EpsonOptions::ext_sel
int ext_sel
Definition: sensor_epsonCommon.h:72
EpsonOptions::filter_sel
int filter_sel
Definition: sensor_epsonCommon.h:81
EpsonOptions::invert_ygyro
int invert_ygyro
Definition: sensor_epsonCommon.h:108
ADDR_SIG_CTRL_HI
#define ADDR_SIG_CTRL_HI
Definition: sensor_epsonG320.h:112
seDelayMS
void seDelayMS(uint32_t millis)
Definition: hcl_linux.c:46
registerRead16
unsigned short registerRead16(unsigned char, unsigned char, unsigned int)
Definition: sensor_epsonUart.c:167
registerWriteByte
void registerWriteByte(unsigned char, unsigned char, unsigned char, unsigned int)
Definition: sensor_epsonUart.c:105
EpsonOptions::temp_bit
int temp_bit
Definition: sensor_epsonCommon.h:98
hcl_gpio.h
EpsonOptions::drdy_pol
int drdy_pol
Definition: sensor_epsonCommon.h:75
EpsonOptions::gpio_out
int gpio_out
Definition: sensor_epsonCommon.h:93
EpsonOptions
Definition: sensor_epsonCommon.h:70
EpsonOptions::dout_rate
int dout_rate
Definition: sensor_epsonCommon.h:78
ADDR_POL_CTRL_LO
#define ADDR_POL_CTRL_LO
Definition: sensor_epsonG320.h:127
hcl.h
EpsonOptions::gyro_bit
int gyro_bit
Definition: sensor_epsonCommon.h:99
ADDR_BURST_CTRL1_LO
#define ADDR_BURST_CTRL1_LO
Definition: sensor_epsonG320.h:123
EpsonOptions::qtn_out
int qtn_out
Definition: sensor_epsonCommon.h:90
sensorInitOptions
int sensorInitOptions(struct EpsonOptions options)
Definition: sensor_epsonG330_G366.c:28
EpsonOptions::accel_out
int accel_out
Definition: sensor_epsonCommon.h:87
ADDR_ATTI_CTRL_LO
#define ADDR_ATTI_CTRL_LO
Definition: sensor_epsonG330PDG0.h:167
CMD_WINDOW1
#define CMD_WINDOW1
Definition: sensor_epsonG320.h:143
EpsonOptions::atti_profile
int atti_profile
Definition: sensor_epsonCommon.h:123
ADDR_BURST_CTRL1_HI
#define ADDR_BURST_CTRL1_HI
Definition: sensor_epsonG320.h:124
ADDR_DLT_CTRL_HI
#define ADDR_DLT_CTRL_HI
Definition: sensor_epsonG330PDG0.h:166
EpsonOptions::invert_yaccel
int invert_yaccel
Definition: sensor_epsonCommon.h:111
EpsonOptions::count_out
int count_out
Definition: sensor_epsonCommon.h:94
EpsonOptions::flag_out
int flag_out
Definition: sensor_epsonCommon.h:84
EpsonOptions::checksum_out
int checksum_out
Definition: sensor_epsonCommon.h:95
EpsonOptions::atti_bit
int atti_bit
Definition: sensor_epsonCommon.h:104
EpsonOptions::invert_zgyro
int invert_zgyro
Definition: sensor_epsonCommon.h:109
ADDR_FILTER_CTRL_LO
#define ADDR_FILTER_CTRL_LO
Definition: sensor_epsonG320.h:117
ADDR_ATTI_CTRL_HI
#define ADDR_ATTI_CTRL_HI
Definition: sensor_epsonG330PDG0.h:168
ADDR_GLOB_CMD2_LO
#define ADDR_GLOB_CMD2_LO
Definition: sensor_epsonG330PDG0.h:169
EpsonOptions::atti_out
int atti_out
Definition: sensor_epsonCommon.h:91
EpsonOptions::gyro_delta_out
int gyro_delta_out
Definition: sensor_epsonCommon.h:88
EpsonOptions::dlt_ovf_en
int dlt_ovf_en
Definition: sensor_epsonCommon.h:115
EpsonOptions::gyro_out
int gyro_out
Definition: sensor_epsonCommon.h:86
FALSE
#define FALSE
Definition: sensor_epsonCommon.h:27
registerDump
void registerDump(void)
Definition: sensor_epsonG330_G366.c:191
EpsonOptions::temp_out
int temp_out
Definition: sensor_epsonCommon.h:85
ADDR_MSC_CTRL_LO
#define ADDR_MSC_CTRL_LO
Definition: sensor_epsonG320.h:113
EpsonOptions::accel_bit
int accel_bit
Definition: sensor_epsonCommon.h:100
ADDR_DLT_CTRL_LO
#define ADDR_DLT_CTRL_LO
Definition: sensor_epsonG330PDG0.h:165
EpsonOptions::atti_conv
int atti_conv
Definition: sensor_epsonCommon.h:120
NG
#define NG
Definition: hcl.h:33
EPSON_ATTI_PROFILE_DELAY
#define EPSON_ATTI_PROFILE_DELAY
Definition: sensor_epsonCommon.h:65
ADDR_SMPL_CTRL_HI
#define ADDR_SMPL_CTRL_HI
Definition: sensor_epsonG320.h:116
EPSON_FILTER_DELAY
#define EPSON_FILTER_DELAY
Definition: sensor_epsonCommon.h:64
ADDR_UART_CTRL_LO
#define ADDR_UART_CTRL_LO
Definition: sensor_epsonG320.h:119
EpsonOptions::invert_zaccel
int invert_zaccel
Definition: sensor_epsonCommon.h:112
EpsonOptions::accel_delta_out
int accel_delta_out
Definition: sensor_epsonCommon.h:89
EpsonOptions::qtn_bit
int qtn_bit
Definition: sensor_epsonCommon.h:103
OK
#define OK
Definition: hcl.h:29
EpsonOptions::invert_xaccel
int invert_xaccel
Definition: sensor_epsonCommon.h:110
EpsonOptions::gyro_delta_bit
int gyro_delta_bit
Definition: sensor_epsonCommon.h:101
EpsonOptions::dlt_range_ctrl
int dlt_range_ctrl
Definition: sensor_epsonCommon.h:116
ADDR_SIG_CTRL_LO
#define ADDR_SIG_CTRL_LO
Definition: sensor_epsonG320.h:111


ess_imu_ros1_uart_driver
Author(s):
autogenerated on Sun Dec 3 2023 03:11:32