uint16_t LSM9DS0_begin( LSM9DS0_t* lsm_t, LMS9DS0_Init_t* init_t ) { #if (DEBUG0==1) uint8_t test[8]; #endif uint8_t gTest, xmTest; if(init_t==NULL) init_t = &LMS_Device_Defaults; // Store the given scales in class variables. These scale variables // are used throughout to calculate the actual g's, DPS,and Gs's. lsm_t->gScale = init_t->gScl; lsm_t->aScale = init_t->aScl; lsm_t->mScale = init_t->mScl; // Once we have the scale values, we can calculate the resolution // of each sensor. That's what these functions are for. One for each sensor calcgRes(lsm_t); // Calculate DPS / ADC tick, stored in gRes variable calcmRes(lsm_t); // Calculate Gs / ADC tick, stored in mRes variable calcaRes(lsm_t); // Calculate g / ADC tick, stored in aRes variable // Now, initialize our hardware interface. #if(LSM_I2C_SUPPORT==1) if (lsm_t->interfaceMode == MODE_I2C) // If we're using I2C LSM_initI2C(); // Initialize I2C else if (lsm_t->interfaceMode == MODE_SPI) // else, if we're using SPI #endif //LSM_initSPI(); // Initialize SPI // To verify communication, we can read from the WHO_AM_I register of // each device. Store those in a variable so we can return them. gTest = gReadByte(lsm_t,WHO_AM_I_G); // Read the gyro WHO_AM_I xmTest = xmReadByte(lsm_t,WHO_AM_I_XM); // Read the accel/mag WHO_AM_I // Gyro initialization stuff: initGyro(lsm_t); // This will "turn on" the gyro. Setting up interrupts, etc. setGyroODR(lsm_t,init_t->gODR); // Set the gyro output data rate and bandwidth. setGyroScale(lsm_t,lsm_t->gScale); // Set the gyro range // Accelerometer initialization stuff: initAccel(lsm_t); // "Turn on" all axes of the accel. Set up interrupts, etc. setAccelODR(lsm_t,init_t->aODR); // Set the accel data rate. setAccelScale(lsm_t,lsm_t->aScale); // Set the accel range. // Magnetometer initialization stuff: initMag(lsm_t); // "Turn on" all axes of the mag. Set up interrupts, etc. setMagODR(lsm_t,init_t->mODR); // Set the magnetometer output data rate. setMagScale(lsm_t,lsm_t->mScale); // Set the magnetometer's range. LSM9DS0_Update_Ctrl(lsm_t); lsm_t->update=UPDATE_ON_SET; #if (DEBUG0==1) I2CreadBytes(lsm_t->gAddress,CTRL_REG1_G,test,5); I2CreadBytes(lsm_t->xmAddress,CTRL_REG0_XM,test,7); #endif // Once everything is initialized, return the WHO_AM_I registers we read: return (xmTest << 8) | gTest; }
uint16_t begin(LSM9DS0_t* imu, gyro_scale gScl, accel_scale aScl, mag_scale mScl, gyro_odr gODR, accel_odr aODR, mag_odr mODR) { // Store the given scales in imu struct. These scale variables // are used throughout to calculate the actual g's, DPS,and Gs's. imu->gScale = gScl; imu->aScale = aScl; imu->mScale = mScl; // Once we have the scale values, we can calculate the resolution // of each sensor. That's what these functions are for. One for each sensor calcgRes(imu); // Calculate DPS / ADC tick, stored in gRes variable calcaRes(imu); // Calculate g / ADC tick, stored in aRes variable calcmRes(imu); // Calculate Gs / ADC tick, stored in mRes variable // To verify communication, we can read from the WHO_AM_I register of // each device. Store those in a variable so we can return them. uint8_t gTest = gReadByte(imu->gyro, WHO_AM_I_G); // Read the gyro WHO_AM_I uint8_t xmTest = xmReadByte(imu->xm, WHO_AM_I_XM); // Read the accel/mag WHO_AM_I // Gyro initialization stuff: initGyro(imu->gyro); // This will "turn on" the gyro. Setting up interrupts, etc. setGyroODR(imu->gyro, gODR); // Set the gyro output data rate and bandwidth. setGyroScale(imu, imu->gScale); // Set the gyro range }
void GladiatorIMU::handleStatusByte(gladiator_rx_msg_t *msg) { //The status byte is used for a variety of things //First cut: is the msg counter 0 or 1: if ((msg->uCount == 0) && ((msg->uStatus & (1<<7)) == 0)) { //Save the SW revision numbers revNumber[msg->uCount] = msg->uStatus & 0x3f; } else if ((msg->uCount == 0) && ((msg->uStatus & (1<<7)) != 0)) { productCode = msg->uStatus & 0x3f; } else if ((msg->uCount == 1) && ((msg->uStatus & (1<<7)) == 0)) { revNumber[msg->uCount] = msg->uStatus & 0x3f; } else if ((msg->uCount == 1) && ((msg->uStatus & (1<<7)) != 0)) { releaseLevel = msg->uStatus & 0x3f; } else if (msg->uCount == 247) { filterNumber = msg->uStatus; } else if (msg->uCount >= 248 && msg->uCount < 252) { boardNumber[msg->uCount - 248] = msg->uStatus; } else if (msg->uCount >= 252) { serialNumber[msg->uCount - 252] = msg->uStatus; } else { //For other values of the msg counter, check bit six to determine flags (0) or scale factors(1) mode //According to the manual (IMU_USERGUIDE_USB_Rev_2013-06-28), this switches every other message if (msg->uStatus & 0x40) { //printf("Count: %d\n", msg->uCount); //Bit six set: scale factors uint8_t accel_bits = msg->uStatus & 0x0e; setAccelScale(accel_bits); uint8_t gyro_bits = msg->uStatus & 0x31; setGyroScale(gyro_bits); //Save the value of the status byte: statusByte[1] = msg->uStatus; } else statusByte[0] = msg->uStatus; } }
uint16_t LSM9DS0::begin(gyro_scale gScl, accel_scale aScl, mag_scale mScl, gyro_odr gODR, accel_odr aODR, mag_odr mODR) { // Store the given scales in class variables. These scale variables // are used throughout to calculate the actual g's, DPS,and Gs's. gScale = gScl; aScale = aScl; mScale = mScl; // Once we have the scale values, we can calculate the resolution // of each sensor. That's what these functions are for. One for each sensor calcgRes(); // Calculate DPS / ADC tick, stored in gRes variable calcmRes(); // Calculate Gs / ADC tick, stored in mRes variable calcaRes(); // Calculate g / ADC tick, stored in aRes variable // Now, initialize our hardware interface. if (interfaceMode == MODE_I2C) // If we're using I2C {} //initI2C(); // Initialize I2C else if (interfaceMode == MODE_SPI) // else, if we're using SPI initSPI(); // Initialize SPI // To verify communication, we can read from the WHO_AM_I register of // each device. Store those in a variable so we can return them. uint8_t gTest = gReadByte(WHO_AM_I_G); // Read the gyro WHO_AM_I uint8_t xmTest = xmReadByte(WHO_AM_I_XM); // Read the accel/mag WHO_AM_I // Gyro initialization stuff: initGyro(); // This will "turn on" the gyro. Setting up interrupts, etc. setGyroODR(gODR); // Set the gyro output data rate and bandwidth. setGyroScale(gScale); // Set the gyro range // Accelerometer initialization stuff: initAccel(); // "Turn on" all axes of the accel. Set up interrupts, etc. setAccelODR(aODR); // Set the accel data rate. setAccelScale(aScale); // Set the accel range. // Magnetometer initialization stuff: initMag(); // "Turn on" all axes of the mag. Set up interrupts, etc. setMagODR(mODR); // Set the magnetometer output data rate. setMagScale(mScale); // Set the magnetometer's range. // Once everything is initialized, return the WHO_AM_I registers we read: return (xmTest << 8) | gTest; }