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