main_screen.c
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // main_screen.c - Epson IMU sensor test application
4 // - This program initializes the Epson IMU and
5 // sends sensor output to console
6 //
7 //
8 // THE SOFTWARE IS RELEASED INTO THE PUBLIC DOMAIN.
9 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
10 // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT,
11 // SECURITY, SATISFACTORY QUALITY, AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
12 // SHALL EPSON BE LIABLE FOR ANY LOSS, DAMAGE OR CLAIM, ARISING FROM OR IN CONNECTION
13 // WITH THE SOFTWARE OR THE USE OF THE SOFTWARE.
14 //
15 //==============================================================================
16 #include <stdint.h>
17 #include <stdio.h>
18 #include <time.h>
19 
20 #include "hcl.h"
21 #include "hcl_gpio.h"
22 #include "sensor_epsonCommon.h"
23 
24 
25 #include <termios.h> // Low-level functions for UART communication
26 #include "hcl_uart.h"
27 
28 int comPort;
29 // Modify below as needed for hardware
30 const char *IMUSERIAL = "/dev/ttyUSB0";
31 const int IMUBAUD = B460800;
32 
33 // Determines the number of samples to readout before exiting the program
34 const unsigned int NUM_SAMPLES = 1000;
35 
36 int main(int argc, char *argv[])
37 {
38  int i;
39  unsigned int sample = 0;
40  signed short readData[SENSOR_READ_LEN];
41  double ppSensorData[6];
42  unsigned short chksum16_ver;
43 
44  // 1) Initialize the Seiko Epson HCL layer
45  printf("\r\nInitializing HCL layer...");
46  if (!seInit()){
47  printf("\r\nError: could not initialize the Seiko Epson HCL layer. Exiting...\r\n");
48  return -1;
49  }
50  printf("...done.\r\n");
51 
52  // 2) Initialize the GPIO interfaces, For GPIO control of pins SPI CS, RESET, DRDY
53  printf("\r\nInitializing GPIO interface...");
54  if (!gpioInit()){
55  printf("\r\nError: could not initialize the GPIO layer. Exiting...\r\n");
56  return -1;
57  }
58  printf("...done.");
59 
60  // 3) Initialize UART Interface
61  printf("\r\nInitializing UART interface...");
63  if(comPort == -1)
64  {
65  printf("\r\nError: could not initialize UART interface. Exiting...\r\n");
66  return -1;
67  }
68  printf("...done.");
69 
70  // 4) Power on sequence - force sensor to config mode, HW reset sensor
71  // Check for errors
72  printf("\r\nChecking sensor NOT_READY status...");
73  if(!sensorPowerOn())
74  {
75  printf("\r\nError: failed to power on Sensor. Exiting...\r\n");
77  return -1;
78  }
79  printf("...done.");
80 
81  // Initialize sensor with desired settings
82  printf("\r\nInitializing Sensor...");
83  if(!sensorInit())
84  {
85  printf("\r\nError: could not initialize Epson Sensor. Exiting...\r\n");
87  return -1;
88  }
89  else
90  {
91  printf("...Epson IMU initialized.");
92  }
93  // Initialize text files for data logs
94  const time_t date = time(NULL); // Functions for obtaining and printing time and date
95  struct tm tm = *localtime(&date);
96 
97  // Epson IMU Data
98  printf("Date: ");
99  printf("%s",ctime(&date));
100  printf("\r\nEpson IMU\r\nSAMPLE,\tXGYRO,\tYGYRO,\tZGYRO,\tXACCL,\tYACCL,\tZACCL,\tCount");
101  printf("\r\n...Epson IMU Logging.\r\n");
102  sensorStart();
103 
104  while (1)
105  {
106  // For SPI interface, check if DRDY pin asserted
107  // For UART interface, check if UART recv buffer contains a sensor sample packet
108  if(sensorDataReady())
109  {
110 #if defined G350 || defined V340 // 16-bit Sensor Output
112  ppSensorDataRead16N(ppSensorData, readData, 2); // GyroX is located at index 2 of readData
113  printf("\r\n%u,\t%+08f,\t%+08f,\t%+08f,\t%+08f,\t%+08f,\t%+08f,\t%5d", sample, ppSensorData[0], ppSensorData[1], ppSensorData[2], ppSensorData[3], ppSensorData[4], ppSensorData[5], (unsigned short)readData[9]);
114 #endif
115 
116 #if defined G354 || defined G364 || defined G352 || defined G362 || defined G320 || defined G364DCA || defined G364DC0 // 32-bit Sensor Output
118  unsigned short tmp16 = calChecksum16(readData, SENSOR_READ_LEN-1);
119  ppSensorDataRead32N(ppSensorData, readData, 0); // GyroX is located at index 0 of readData
120 
121  printf("\r\n%u,\t%+08f,\t%+08f,\t%+08f,\t%+08f,\t%+08f,\t%+08f,\t%5d,\t0x%04hX,\t0x%04hX", sample, ppSensorData[0], ppSensorData[1], ppSensorData[2], ppSensorData[3], ppSensorData[4], ppSensorData[5], (unsigned short)readData[12],
122  (unsigned short)readData[13], tmp16);
123  if (tmp16 == (unsigned short)readData[SENSOR_READ_LEN-1])
124  printf(", OK");
125  else
126  printf(", ERROR");
127 #endif
128  sample++;
129  }
130  if (sample > (NUM_SAMPLES-1))
131  break;
132  }
133 
134  const time_t end = time(NULL); // Functions for obtaining and printing time and data
135  tm = *localtime(&end);
136  printf("\r\nEnd: ");
137  printf("%s", ctime(&end));
138 
139  sensorStop();
140  sleep(1);
142  gpioRelease();
143  seRelease();
144  printf("\r\n");
145 
146  printf("\r\nThe following arguments were passed to main(): ");
147  for(i=1; i<argc; i++) printf("%s ", argv[i]);
148  printf("\r\n");
149  return 0;
150 }
const unsigned int NUM_SAMPLES
Definition: main_screen.c:34
#define SENSOR_READ_LEN
int seInit(void)
Definition: hcl_linux.c:28
int gpioInit(void)
Definition: hcl_gpio.c:29
int sensorDataReady(void)
int uartInit(const char *comPortPath, int baudRate)
Definition: hcl_uart.c:222
void sensorStop(void)
const char * IMUSERIAL
Definition: main_screen.c:30
int gpioRelease(void)
Definition: hcl_gpio.c:41
unsigned short calChecksum16(unsigned short sensorReadData[], unsigned int endOffset)
const int IMUBAUD
Definition: main_screen.c:31
int uartRelease(ComPortHandle comPort)
Definition: hcl_uart.c:236
void ppSensorDataRead32N(double ppSensorReadData[], signed short sensorReadData[], unsigned char startIndex)
int sensorInit(void)
int comPort
Definition: main_screen.c:28
void sensorStart(void)
int seRelease(void)
Definition: hcl_linux.c:42
void sensorDataReadBurstN(signed short[], unsigned int)
int main(int argc, char *argv[])
Definition: main_screen.c:36
int sensorPowerOn(void)
void ppSensorDataRead16N(double ppSensorReadData[], signed short sensorReadData[], unsigned char startIndex)


epson_g364_imu_driver
Author(s):
autogenerated on Mon Jun 10 2019 13:12:32