mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-03 11:24:10 +01:00
Use the updated L3GD20 format and make attitude.c use the gyro data from the
fifo
This commit is contained in:
parent
c9263cb8c0
commit
b6c056fef2
@ -143,7 +143,7 @@ static const struct pios_exti_cfg pios_exti_l3gd20_cfg __exti_config = {
|
|||||||
|
|
||||||
static const struct pios_l3gd20_cfg pios_l3gd20_cfg = {
|
static const struct pios_l3gd20_cfg pios_l3gd20_cfg = {
|
||||||
.exti_cfg = &pios_exti_l3gd20_cfg,
|
.exti_cfg = &pios_exti_l3gd20_cfg,
|
||||||
.gyro_range = PIOS_L3GD20_SCALE_500_DEG,
|
.range = PIOS_L3GD20_SCALE_500_DEG,
|
||||||
};
|
};
|
||||||
#endif /* PIOS_INCLUDE_L3GD20 */
|
#endif /* PIOS_INCLUDE_L3GD20 */
|
||||||
|
|
||||||
@ -687,12 +687,13 @@ void PIOS_Board_Init(void) {
|
|||||||
if (PIOS_SPI_Init(&pios_spi_gyro_id, &pios_spi_gyro_cfg)) {
|
if (PIOS_SPI_Init(&pios_spi_gyro_id, &pios_spi_gyro_cfg)) {
|
||||||
PIOS_Assert(0);
|
PIOS_Assert(0);
|
||||||
}
|
}
|
||||||
PIOS_L3GD20_Attach(pios_spi_gyro_id);
|
PIOS_L3GD20_Init(pios_spi_gyro_id, 0, &pios_l3gd20_cfg);
|
||||||
PIOS_L3GD20_Init(&pios_l3gd20_cfg);
|
PIOS_Assert(PIOS_L3GD20_Test() == 0);
|
||||||
#endif /* PIOS_INCLUDE_L3GD20 */
|
#endif /* PIOS_INCLUDE_L3GD20 */
|
||||||
|
|
||||||
#if defined(PIOS_INCLUDE_BMA180)
|
#if defined(PIOS_INCLUDE_BMA180)
|
||||||
PIOS_BMA180_Init(pios_spi_flash_accel_id, 0, &pios_bma180_cfg);
|
PIOS_BMA180_Init(pios_spi_flash_accel_id, 0, &pios_bma180_cfg);
|
||||||
|
PIOS_Assert(PIOS_BMA180_Test() == 0);
|
||||||
#endif /* PIOS_INCLUDE_BMA180 */
|
#endif /* PIOS_INCLUDE_BMA180 */
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -381,17 +381,15 @@ static int32_t updateSensorsCC3D(AccelsData * accelsData, GyrosData * gyrosData)
|
|||||||
// Unfortunately if the BMA180 ever misses getting read, then it will not
|
// Unfortunately if the BMA180 ever misses getting read, then it will not
|
||||||
// trigger more interrupts. In this case we must force a read to kickstart
|
// trigger more interrupts. In this case we must force a read to kickstart
|
||||||
// it.
|
// it.
|
||||||
struct pios_bma180_data data;
|
PIOS_BMA180_ReadAccels(&accel);
|
||||||
PIOS_BMA180_ReadAccels(&data);
|
|
||||||
lastSysTime = xTaskGetTickCount();
|
lastSysTime = xTaskGetTickCount();
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
while(accel_read_good == 0) {
|
while(accel_read_good == 0) {
|
||||||
accel_samples++;
|
accel_samples++;
|
||||||
|
|
||||||
accel_accum[0] += -accel.x;
|
accel_accum[0] += accel.x;
|
||||||
accel_accum[1] += -accel.y;
|
accel_accum[1] += accel.y;
|
||||||
accel_accum[2] += accel.z;
|
accel_accum[2] += accel.z;
|
||||||
|
|
||||||
accel_read_good = PIOS_BMA180_ReadFifo(&accel);
|
accel_read_good = PIOS_BMA180_ReadFifo(&accel);
|
||||||
@ -400,37 +398,40 @@ static int32_t updateSensorsCC3D(AccelsData * accelsData, GyrosData * gyrosData)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PIOS_INCLUDE_L3GD20)
|
#if defined(PIOS_INCLUDE_L3GD20)
|
||||||
// int32_t gyro_read_good;
|
int32_t gyro_read_good;
|
||||||
// gyro_samples = 0;
|
gyro_samples = 0;
|
||||||
// bool gyro_error = false;
|
bool gyro_error = false;
|
||||||
//
|
|
||||||
// while((gyro_read_good = PIOS_L3GD20_ReadFifo(&gyro) != 0) && !gyro_error)
|
while((gyro_read_good = PIOS_L3GD20_ReadFifo(&gyro) != 0) && !gyro_error)
|
||||||
// gyro_error = ((xTaskGetTickCount() - lastSysTime) > 5) ? true : gyro_error;
|
gyro_error = ((xTaskGetTickCount() - lastSysTime) > 5) ? true : gyro_error;
|
||||||
// while(gyro_read_good == 0) {
|
if (gyro_error) {
|
||||||
// gyro_samples++;
|
// Unfortunately if the L3GD20 ever misses getting read, then it will not
|
||||||
//
|
// trigger more interrupts. In this case we must force a read to kickstart
|
||||||
// gyro_accum[0] += gyro.gyro_x;
|
// it.
|
||||||
// gyro_accum[1] += gyro.gyro_y;
|
PIOS_L3GD20_ReadGyros(&gyro);
|
||||||
// gyro_accum[2] += gyro.gyro_z;
|
lastSysTime = xTaskGetTickCount();
|
||||||
//
|
|
||||||
// gyro_read_good = PIOS_L3GD20_ReadFifo(&gyro);
|
|
||||||
// }
|
|
||||||
if(PIOS_L3GD20_ReadGyros(&gyro) < 0)
|
|
||||||
return -1;
|
return -1;
|
||||||
gyro_accum[0] += gyro.gyro_x;
|
}
|
||||||
gyro_accum[1] += gyro.gyro_y;
|
|
||||||
gyro_accum[2] += gyro.gyro_z;
|
while(gyro_read_good == 0) {
|
||||||
gyro_samples =1;
|
gyro_samples++;
|
||||||
|
|
||||||
|
gyro_accum[0] += gyro.gyro_x;
|
||||||
|
gyro_accum[1] += gyro.gyro_y;
|
||||||
|
gyro_accum[2] += gyro.gyro_z;
|
||||||
|
|
||||||
|
gyro_read_good = PIOS_L3GD20_ReadFifo(&gyro);
|
||||||
|
}
|
||||||
gyro_scaling = PIOS_L3GD20_GetScale();
|
gyro_scaling = PIOS_L3GD20_GetScale();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
float accels[3] = {(float) accel_accum[1] / accel_samples, (float) accel_accum[0] / accel_samples, -(float) accel_accum[2] / accel_samples};
|
float accels[3] = {(float) -accel_accum[1] / accel_samples, (float) -accel_accum[0] / accel_samples, -(float) accel_accum[2] / accel_samples};
|
||||||
|
|
||||||
accelsData->x = accels[0] * accel_scaling - accelbias[0];
|
accelsData->x = accels[0] * accel_scaling - accelbias[0];
|
||||||
accelsData->y = accels[1] * accel_scaling - accelbias[1];
|
accelsData->y = accels[1] * accel_scaling - accelbias[1];
|
||||||
accelsData->z = accels[2] * accel_scaling - accelbias[2];
|
accelsData->z = accels[2] * accel_scaling - accelbias[2];
|
||||||
|
|
||||||
float gyros[3] = {(float) gyro_accum[1] / gyro_samples, (float) gyro_accum[0] / gyro_samples, -(float) gyro_accum[2] / gyro_samples};
|
float gyros[3] = {(float) gyro_accum[0] / gyro_samples, (float) -gyro_accum[1] / gyro_samples, -(float) gyro_accum[2] / gyro_samples};
|
||||||
|
|
||||||
gyrosData->x = gyros[0] * gyro_scaling;
|
gyrosData->x = gyros[0] * gyro_scaling;
|
||||||
gyrosData->y = gyros[1] * gyro_scaling;
|
gyrosData->y = gyros[1] * gyro_scaling;
|
||||||
|
@ -1577,7 +1577,7 @@ static const struct pios_exti_cfg pios_exti_l3gd20_cfg __exti_config = {
|
|||||||
|
|
||||||
static const struct pios_l3gd20_cfg pios_l3gd20_cfg = {
|
static const struct pios_l3gd20_cfg pios_l3gd20_cfg = {
|
||||||
.exti_cfg = &pios_exti_l3gd20_cfg,
|
.exti_cfg = &pios_exti_l3gd20_cfg,
|
||||||
.gyro_range = PIOS_L3GD20_SCALE_500_DEG,
|
.range = PIOS_L3GD20_SCALE_500_DEG,
|
||||||
};
|
};
|
||||||
#endif /* PIOS_INCLUDE_L3GD20 */
|
#endif /* PIOS_INCLUDE_L3GD20 */
|
||||||
|
|
||||||
@ -1761,14 +1761,15 @@ void PIOS_Board_Init(void) {
|
|||||||
|
|
||||||
#if defined(PIOS_INCLUDE_BMA180)
|
#if defined(PIOS_INCLUDE_BMA180)
|
||||||
PIOS_BMA180_Init(pios_spi_accel_id, 0, &pios_bma180_cfg);
|
PIOS_BMA180_Init(pios_spi_accel_id, 0, &pios_bma180_cfg);
|
||||||
|
PIOS_Assert(PIOS_BMA180_Test() == 0);
|
||||||
#endif
|
#endif
|
||||||
#if defined(PIOS_INCLUDE_MPU6000)
|
#if defined(PIOS_INCLUDE_MPU6000)
|
||||||
PIOS_MPU6000_Attach(pios_spi_gyro_id);
|
PIOS_MPU6000_Attach(pios_spi_gyro_id);
|
||||||
PIOS_MPU6000_Init(&pios_mpu6000_cfg);
|
PIOS_MPU6000_Init(&pios_mpu6000_cfg);
|
||||||
|
PIOS_Assert(PIOS_MPU6000_Test() == 0);
|
||||||
#elif defined(PIOS_INCLUDE_L3GD20)
|
#elif defined(PIOS_INCLUDE_L3GD20)
|
||||||
PIOS_L3GD20_Attach(pios_spi_gyro_id);
|
PIOS_L3GD20_Init(pios_spi_gyro_id, 0, &pios_l3gd20_cfg);
|
||||||
PIOS_Assert(PIOS_L3GD20_Test() == 0);
|
PIOS_Assert(PIOS_L3GD20_Test() == 0);
|
||||||
PIOS_L3GD20_Init(&pios_l3gd20_cfg);
|
|
||||||
#else
|
#else
|
||||||
PIOS_Assert(0);
|
PIOS_Assert(0);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user