Skip to content

Commit

Permalink
Merge pull request #2 from AvSquirrel/working
Browse files Browse the repository at this point in the history
Add runtime toggle for IMU fusion
  • Loading branch information
cyoung committed Feb 3, 2016
2 parents af55080 + 03f2241 commit 56658ff
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
20 changes: 20 additions & 0 deletions libimu.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@
#include "libimu.h"



// static void fused_euler_angles(mpudata_t *mpu);
// static void fused_quaternion(mpudata_t *mpu);
// static void calibrated_accel(mpudata_t *mpu);
// static void calibrated_mag(mpudata_t *mpu);



int i2c_bus;
int sample_rate;
int yaw_mix_factor;
Expand All @@ -52,6 +54,8 @@ void close_mpu(void)





int init_mpu(int sample_rate, int yaw_mix_factor)
{
int ret;
Expand All @@ -71,6 +75,19 @@ int init_mpu(int sample_rate, int yaw_mix_factor)
return ret;
}

int enableFusion(void) {
if (enableAccelerometerFusion()) {
return -1;
}
return 0;
}

int disableFusion(void) {
if (disableAccelerometerFusion()) {
return -1;
}
return 0;
}
int read_mpu(float *pitch, float *roll, float *heading)
{
int ret;
Expand All @@ -94,6 +111,7 @@ int read_mpu(float *pitch, float *roll, float *heading)
// mpu->fusedEuler[VEC3_Z] * RAD_TO_DEGREE;
// }


// void fused_quaternions(mpudata_t *mpu)
// {
// mpu->fusedQuat[QUAT_W];
Expand Down Expand Up @@ -151,6 +169,7 @@ int set_cal(int mag, char *cal_file)
}
}


memset(buff, 0, sizeof(buff));

for (i = 0; i < 6; i++) {
Expand All @@ -159,6 +178,7 @@ int set_cal(int mag, char *cal_file)
break;
}


val[i] = atoi(buff);

if (val[i] == 0) {
Expand Down
2 changes: 2 additions & 0 deletions libimu.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ extern int init_mpu(int sample_rate, int yaw_mix_factor);
extern int read_mpu(float *pitch, float *roll, float *heading);
extern int set_cal(int mag, char *cal_file);

extern int enableFusion(void);
extern int disableFusion(void);
#ifdef __cplusplus
}
#endif
Expand Down
10 changes: 9 additions & 1 deletion mpu/mpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,21 @@ import (
)

// Current version.
var PackageVersion = "v0.1"
var PackageVersion = "v0.2b"

// InitMPU
func InitMPU(sample_rate, yaw_mix_factor int) int {
return int(C.init_mpu(C.int(sample_rate), C.int(yaw_mix_factor)))
}

func EnableFusion() int {
return int(C.enableFusion())
}

func DisableFusion() int {
return int(C.disableFusion())
}

// CloseMPU
func CloseMPU() {
C.close_mpu()
Expand Down
23 changes: 22 additions & 1 deletion mpu9150/mpu9150.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ int mpu9150_init(int i2c_bus, int sample_rate, int mix_factor)
printf(".");
fflush(stdout);

if (dmp_enable_feature(/*DMP_FEATURE_6X_LP_QUAT*/ DMP_FEATURE_LP_QUAT | DMP_FEATURE_SEND_RAW_ACCEL
if (dmp_enable_feature(DMP_FEATURE_6X_LP_QUAT | DMP_FEATURE_SEND_RAW_ACCEL
| DMP_FEATURE_SEND_CAL_GYRO | DMP_FEATURE_GYRO_CAL)) {
printf("\ndmp_enable_feature() failed\n");
return -1;
Expand All @@ -161,6 +161,27 @@ int mpu9150_init(int i2c_bus, int sample_rate, int mix_factor)
return 0;
}

/* New functions to enable / disable 6axis on the fly */


int enableAccelerometerFusion(void) {
if (dmp_enable_feature(DMP_FEATURE_6X_LP_QUAT | DMP_FEATURE_SEND_RAW_ACCEL | DMP_FEATURE_SEND_CAL_GYRO | DMP_FEATURE_GYRO_CAL)) {
printf("Failure enabling accelerometer fusion\n");
return -1;
}
printf("mpu9150.c: Accelerometer fusion enabled\n");
return 0;
}

int disableAccelerometerFusion(void) {
if (dmp_enable_feature(DMP_FEATURE_LP_QUAT | DMP_FEATURE_SEND_RAW_ACCEL | DMP_FEATURE_SEND_CAL_GYRO | DMP_FEATURE_GYRO_CAL)) {
printf("Failure disabling accelerometer fusion\n");
return -1;
}
printf("mpu9150.c: Accelerometer fusion disabled\n");
return 0;
}

void mpu9150_exit()
{
// turn off the DMP on exit
Expand Down
2 changes: 2 additions & 0 deletions mpu9150/mpu9150.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,7 @@ int mpu9150_read_mag(mpudata_t *mpu);
void mpu9150_set_accel_cal(caldata_t *cal);
void mpu9150_set_mag_cal(caldata_t *cal);

int enableAccelerometerFusion(void);
int disableAccelerometerFusion(void);
#endif /* MPU9150_H */

0 comments on commit 56658ff

Please sign in to comment.