I would like to develop a simple application to log sensors data (mag gyro and acc) from the iNemo to
my pc. I am using the serial-over-usb driver to communicate with Matlab through the serial port.
For data acquisition I am using the PLAY library.
These are my sensor configurations:
Code: Select all
// Gyro configuration
static const L3GD20_Config l3gd20_cfg_1 = {
L3GD20_FS_500DPS,
L3GD20_PM_SLEEP_NORMAL,
L3GD20_ODR_380Hz_Fc_25,
L3GD20_AE_XYZ,
L3GD20_End_LITTLE,
L3GD20_BDU_CONTINOUS
};
// ACC configuration
static const LSM303DLHC_ACC_Config lsm303dlhc_acc_cfg_1 = {
LSM303DLHC_ACC_FS_4G,
LSM303DLHC_ACC_PM_NORMAL,
LSM303DLHC_ACC_ODR_1344Hz,
LSM303DLHC_ACC_AE_XYZ,
LSM303DLHC_ACC_BDU_BLOCKED,
LSM303DLHC_ACC_HR_Enabled
};
// COMP configuration
static const LSM303DLHC_COMP_Config lsm303dlhc_comp_cfg_1 = {
LSM303DLHC_COMP_FS_1_9_GA,
LSM303DLHC_COMP_ODR_220_Hz,
LSM303DLHC_COMP_WM_CONTINUOS
};
I have two threads: one to acquire data and another to write on the serial port.
Code: Select all
static msg_t Thread1(void *arg) {
// *** some code ****//
while (TRUE) {
chSysLock();
// Gyro acquisition
gyroStartAcquiringDevice(&GYROD1, &gyro_cfg_1);
gyroGetData(&GYROD1, &gyro_d_1);
gyroStopReleasingDevice(&GYROD1);
// Acc acquisition
accelStartAcquiringDevice(&ACCELD1, &accel_cfg_1);
accelGetData(&ACCELD1, &accel_d_1);
accelStopReleasingDevice(&ACCELD1);
compStartAcquiringDevice(&COMPD1, &comp_cfg_1);
compGetData(&COMPD1, &comp_d_1);
compStopReleasingDevice(&COMPD1);
chSysUnlock();
}
static msg_t Thread2(void *arg) {
//*** some code ***//
while(TRUE) {
chprintf(//*** sensor data from gyro_d_1, accel_d_a, comp_d_1***//);
chThdSleepMilliseconds(TC);
}
}
Both threads have the same priority.
My problem is as following:
if TC > 50 msec everything is ok. If TC < 50 msec i get some repetitions in the data I read. For example, in two
consecutive timestamps i get the same gyro sample but different acc and mag values.
I thought that it could happen when Thread1 is preempted by Thread2 during the execution of the data acquisition code,
which represents the critical section. That is why I locked the code of data acquisition in Thread1 but it did not solved
the problem.
I have two questions:
1) How to speed up the data acquisition (maybe with some sensor configuration)?
2) Why did not the synchronization of Thread2 with Thread1 on the shared resources work?
Thank you for your help!