imu_imar
Imar.hpp
Go to the documentation of this file.
1 
5 #ifndef _IMAR_HPP_
6 #define _IMAR_HPP_
7 
8 #include <iostream>
9 #include <Eigen/Geometry>
10 #include <unsupported/Eigen/FFT>
11 #include <boost/circular_buffer.hpp>
14 namespace imu_imar
15 {
16 
17  enum CONSTS {
18  NUMAXIS = 3,
19  PKG_SIZE = 50,
21  };
22 
24  SYNC_WORD = 0x7E,
25  POLY = 0x8408
26  };
27 
28  typedef struct {
29  unsigned char data[2];
30  }UINT16;
33  typedef struct {
34  bool synchronized;
35  unsigned char counter;
36  int size;
37  int read;
38  int write;
39  unsigned char data[(2*imu_imar::PKG_SIZE) + 1]; /* vector of elements */
41 
43  typedef struct {
44  unsigned char counter;
45  unsigned int microseconds;
46  int length;
47 // unsigned char ibit[8]; /** Init Build in Test (IBIT) information check info **/
48  float acc[imu_imar::NUMAXIS];
49  float gyro[imu_imar::NUMAXIS];
50  float euler[imu_imar::NUMAXIS];
52  } ImuData;
53 
54 
55 
56  class iVRU_BB
57  {
58 
59 
60 
61  private:
62  int fd;
63  CircularBuffer myBuffer;
64  ImuData myIMU;
65  boost::circular_buffer<float> cbAccX;
66  boost::circular_buffer<float> cbAccY;
67  boost::circular_buffer<float> cbAccZ;
68  Eigen::Matrix <double,imu_imar::NUMAXIS,1> velocity;
69  Eigen::Matrix <double,imu_imar::NUMAXIS,1> displacement;
70 
71  public:
72 
77  iVRU_BB();
78 
79  ~iVRU_BB();
80 
89  void welcome();
90 
104  bool open_port (const char* name);
105 
122  bool init_serial (const char *name, const int bauds);
123 
124 
138  bool write_serial(char* command, int nbytes);
139 
140 
154  bool read_serial(unsigned char * bufferpr, int nbytes);
155 
166  bool close_port ();
167 
176  int getDescriptor();
177 
178 
188  int cbIsFull();
189 
199  int cbIsEmpty();
200 
213  bool cbIsSynchronized();
214 
215 
230  void cbWritePckg(int nbytes, unsigned char * values);
231 
244  bool cbSynchronize ();
245 
259  bool cbCopyPckg(unsigned char *pckg, int len);
260 
274  bool cbReadValues();
275 
284  void cbPrintValues();
285 
294  int cbNumberElements();
295 
304  int getPacketCounter();
305 
314  Eigen::Matrix <double,imu_imar::NUMAXIS,1> getAccelerometers();
315 
324  Eigen::Matrix <double,imu_imar::NUMAXIS,1> getGyroscopes();
325 
326 
335  Eigen::Quaternion <double> getAttitude();
336 
337 
338  void cbCalculateAccIntegration (const float omega);
339 
340  Eigen::Matrix <double,imu_imar::NUMAXIS,1> getVelocity();
341 
342  Eigen::Matrix <double,imu_imar::NUMAXIS,1> getPosition();
343 
344  unsigned short crc16(unsigned char *data_p, int length);
345 
346  unsigned int Crc16_0(unsigned char const * pByte, unsigned Size);
347 
348  void cbReset();
349 
350  };
351 
352 } // end namespace
353 
354 #endif // _IMAR_HPP_
int getPacketCounter()
It gives the package counter.
Definition: Imar.cpp:678
int cbIsFull()
Returns if the circular buffer is full.
Definition: Imar.cpp:321
unsigned char counter
Definition: Imar.hpp:35
Eigen::Matrix< double, imu_imar::NUMAXIS, 1 > getAccelerometers()
It gets the Accelerometers values.
Definition: Imar.cpp:643
Definition: Imar.hpp:43
DATAGRAN_CONST
Definition: Imar.hpp:23
Eigen::Matrix< double, imu_imar::NUMAXIS, 1 > getVelocity()
Definition: Imar.cpp:754
Definition: Imar.hpp:25
bool cbIsSynchronized()
Returns if the driver is Synchronized.
Definition: Imar.cpp:337
Definition: Imar.hpp:28
bool open_port(const char *name)
This method opens a serial port.
Definition: Imar.cpp:71
bool read_serial(unsigned char *bufferpr, int nbytes)
Function to read values from a serial port connection.
Definition: Imar.cpp:270
bool init_serial(const char *name, const int bauds)
This method opens and configures a serial port.
Definition: Imar.cpp:181
int length
Definition: Imar.hpp:46
UINT16 crc
Definition: Imar.hpp:51
void cbWritePckg(int nbytes, unsigned char *values)
It writes information in the Cicular Buffer.
Definition: Imar.cpp:342
Definition: Imar.hpp:20
void cbCalculateAccIntegration(const float omega)
Definition: Imar.cpp:684
Eigen::Quaternion< double > getAttitude()
It gets the attitude or orientation.
Definition: Imar.cpp:667
void cbReset()
Definition: Imar.cpp:847
bool write_serial(char *command, int nbytes)
This method write values in the serial port.
Definition: Imar.cpp:246
CONSTS
Definition: Imar.hpp:17
bool cbReadValues()
It reads a IMU packages.
Definition: Imar.cpp:477
bool cbSynchronize()
It synchronizes the circular buffer.
Definition: Imar.cpp:356
bool cbCopyPckg(unsigned char *pckg, int len)
It reads a information from the circular buffer.
Definition: Imar.cpp:441
int size
Definition: Imar.hpp:36
iVRU_BB()
Definition: Imar.cpp:49
unsigned short crc16(unsigned char *data_p, int length)
Definition: Imar.cpp:761
Definition: Imar.hpp:18
Definition: Imar.hpp:33
int read
Definition: Imar.hpp:37
Eigen::Matrix< double, imu_imar::NUMAXIS, 1 > getGyroscopes()
It gets the Gyroscopes values.
Definition: Imar.cpp:655
void cbPrintValues()
It prints the values stored in ImuData.
Definition: Imar.cpp:632
unsigned int microseconds
Definition: Imar.hpp:45
void welcome()
Dummy Welcome method.
Definition: Imar.cpp:305
Definition: Imar.hpp:19
int cbIsEmpty()
Returns if the circular buffer is Empty.
Definition: Imar.cpp:329
int getDescriptor()
Returns file decriptor.
Definition: Imar.cpp:313
~iVRU_BB()
Definition: Imar.cpp:63
int write
Definition: Imar.hpp:38
unsigned int Crc16_0(unsigned char const *pByte, unsigned Size)
Definition: Imar.cpp:833
bool close_port()
Function to close an open serial port connection.
Definition: Imar.cpp:291
unsigned char counter
Definition: Imar.hpp:44
Definition: Imar.hpp:24
Definition: Imar.hpp:56
Eigen::Matrix< double, imu_imar::NUMAXIS, 1 > getPosition()
Definition: Imar.cpp:749
int cbNumberElements()
It gives the number of elements stored in the Circular Buffer.
Definition: Imar.cpp:423