46 Value *baudrate, *serial;
48 if(!config.check(
"serial", serial))
50 std::cout <<
"Can't find 'serial' name in config file";
54 if(config.check(
"verbose"))
59 comPortName = serial->toString();
63 printf(
"\n\nSerial opening %s\n\n\n", comPortName.c_str());
64 fd_ser =
::open(comPortName.c_str(), O_RDWR | O_NOCTTY );
66 printf(
"can't open %s, %s\n", comPortName.c_str(), strerror(errno));
71 struct termios options;
72 tcgetattr(fd_ser, &options);
75 int baudRate = B115200;
76 cfsetospeed(&options, baudRate);
77 cfsetispeed(&options, baudRate);
90 options.c_iflag = IGNPAR;
95 options.c_cc[VMIN] = 53;
96 options.c_cc[VTIME] = 10;
99 options.c_cflag |= (CLOCAL | CREAD);
101 tcflush(fd_ser,TCIOFLUSH);
104 if ( tcsetattr(fd_ser, TCSANOW, &options) != 0)
106 printf(
"Configuring comport failed\n");
115 int nbytes_w = ::write(fd_ser, (
void*)buff, 3);
117 memset(buff, 0x00, 20);
118 int nbytes_r =
::read(fd_ser, (
void*)buff, 3);
120 printf(
"Line %d: Received response 0x%0X, 0x%0X, 0x%0X\n", __LINE__, buff[0], buff[1], buff[2]);
127 nbytes_w = ::write(fd_ser, (
void*)buff, 4);
129 memset(buff, 0x00, 20);
130 nbytes_r =
::read(fd_ser, (
void*)buff, 3);
132 printf(
"Line %d: Received response 0x%0X, 0x%0X, 0x%0X\n", __LINE__, buff[0], buff[1], buff[2]);
140 nbytes_w = ::write(fd_ser, (
void*)buff, 4);
142 memset(buff, 0x00, 20);
143 nbytes_r =
::read(fd_ser, (
void*)buff, 3);
145 printf(
"Line %d: Received response 0x%0X, 0x%0X, 0x%0X\n", __LINE__, buff[0], buff[1], buff[2]);
150 nbytes_w = ::write(fd_ser, (
void*)buff, 3);
152 memset(buff, 0x00, 20);
153 nbytes_r =
::read(fd_ser, (
void*)buff, 4);
155 printf(
"Line %d: Received response 0x%0X, 0x%0X, 0x%0X\n, 0x%0X\n", __LINE__, buff[0], buff[1], buff[2], buff[3]);
165 nbytes_w = ::write(fd_ser, (
void*)buff, 5);
167 memset(buff, 0x00, 20);
168 nbytes_r =
::read(fd_ser, (
void*)buff, 6);
170 printf(
"Line %d: gyro parameter fullscale 0x%0X.%0X.%0X.%0X.%0X.%0X\n", __LINE__, buff[0], buff[1], buff[2], buff[3], buff[4], buff[5]);
179 nbytes_w = ::write(fd_ser, (
void*)buff, 5);
181 memset(buff, 0x00, 20);
182 nbytes_r =
::read(fd_ser, (
void*)buff, 7);
184 printf(
"Line %d: gyro parameter scale factor 0x%0X.%0X.%0X.%0X.%0X.%0X.%0X\n", __LINE__, buff[0], buff[1], buff[2], buff[3], buff[4], buff[5], buff[6]);
196 printf(
"Setting sample config\n");
206 int nbytes_w = ::write(fd_ser, (
void*)buff, 7);
208 memset(buff, 0x00, 7);
209 int nbytes_r =
::read(fd_ser, (
void*)buff, 4);
210 printf(
"Received response 0x%02X, 0x%02X, 0x%02X, 0x%02X\n", buff[0], buff[1], buff[2], buff[3]);
213 printf(
"Reading back sample config\n");
218 nbytes_w = ::write(fd_ser, (
void*)buff, 3);
219 memset(buff, 0x00, 7);
220 nbytes_r =
::read(fd_ser, (
void*)buff, 7);
221 printf(
"Received response 0x%0X, 0x%0X, 0x%0X, 0x%0X, 0x%0X, 0x%0X, 0x%0X\n", buff[0], buff[1], buff[2], buff[3], buff[4], buff[5], buff[6]);
223 printf(
"Reading libbraries config\n");
228 nbytes_w = ::write(fd_ser, (
void*)buff, 3);
229 memset(buff, 0x00, 7);
230 nbytes_r =
::read(fd_ser, (
void*)buff, 4);
231 printf(
"Line %d: Received response 0x%02X, 0x%02X, 0x%02X, 0x%02X\n", __LINE__, buff[0], buff[1], buff[2], buff[3]);
247 expected_packet_size = (1 + 1 + 1) + (2 + 6 + 6 + 6 + 2 + 12 + 16);
248 expected_payload_size = expected_packet_size - 2;
250 buffer =
new char [100];
252 euler_float =
reinterpret_cast<float*
>(&(outVals.euler_raw[0]));
305 uint64_t imu_timeStamp;
308 for(
int i=0; i<3; i++, out_idx++)
309 out[out_idx] = (
double) euler_float[i];
311 for(
int i=0; i<3; i++, out_idx++)
312 out[out_idx] = (
double) outVals.accel[i] * 9.81 / 1000.0f;
314 for(
int i=0; i<3; i++, out_idx++)
315 out[out_idx] = (
double) outVals.gyro[i] * 500.0f / (2<<15);
317 for(
int i=0; i<3; i++, out_idx++)
318 out[out_idx] = (
double) outVals.magn[i];