Embedded code for LPC1768 on Zumy
Dependencies: MPU6050IMU RPCInterface mbed
Fork of RPC_Serial by
main.cpp
- Committer:
- abuchan
- Date:
- 2015-10-05
- Revision:
- 2:2c0cd1aaae83
- Parent:
- 1:de34af25056a
- Child:
- 3:8b5700499eb8
File content as of revision 2:2c0cd1aaae83:
#include "mbed.h" //#include "SerialRPCInterface.h" #include "MPU6050.h" //SerialRPCInterface SerialRPC(USBTX, USBRX, 115200); typedef struct imu_struct_t{ float accel_x; float accel_y; float accel_z; float gyro_x; float gyro_y; float gyro_z; } imu_struct_t; imu_struct_t imu; //RPCVariable<imu_struct_t> rpc_imu(&imu, "imu"); MPU6050 mpu6050; DigitalOut init_done(LED1); DigitalOut imu_good(LED2); DigitalOut main_loop(LED3); int main() { init_done = 0; imu_good = 0; main_loop = 0; // setup the classes that can be created dynamically /*Base::add_rpc_class<AnalogIn>(); Base::add_rpc_class<AnalogOut>(); Base::add_rpc_class<DigitalIn>(); Base::add_rpc_class<DigitalOut>(); Base::add_rpc_class<DigitalInOut>(); Base::add_rpc_class<PwmOut>(); Base::add_rpc_class<Timer>(); Base::add_rpc_class<SPI>(); Base::add_rpc_class<BusOut>(); Base::add_rpc_class<BusIn>(); Base::add_rpc_class<BusInOut>(); Base::add_rpc_class<Serial>();*/ imu.accel_x = 0.0; imu.accel_y = 0.0; imu.accel_z = 0.0; imu.gyro_x = 0.0; imu.gyro_y = 0.0; imu.gyro_z = 0.0; //Set up I2C i2c.frequency(400000); // use fast (400 kHz) I2C bool imu_ready = false; uint8_t whoami = mpu6050.readByte(MPU6050_ADDRESS, WHO_AM_I_MPU6050); if (whoami == 0x68) // WHO_AM_I should always be 0x68 { mpu6050.MPU6050SelfTest(SelfTest); if(SelfTest[0] < 1.0f && SelfTest[1] < 1.0f && SelfTest[2] < 1.0f && SelfTest[3] < 1.0f && SelfTest[4] < 1.0f && SelfTest[5] < 1.0f) { mpu6050.resetMPU6050(); // Reset registers to default in preparation for device calibration mpu6050.calibrateMPU6050(gyroBias, accelBias); // Calibrate gyro and accelerometers, load biases in bias registers mpu6050.initMPU6050(); mpu6050.getAres(); mpu6050.getGres(); imu_ready = true; imu_good = 1; } } init_done = 1; while(1) { wait_ms(100); main_loop = !main_loop; if (imu_ready) { imu.accel_x = imu.accel_x + 0.1; /* if(mpu6050.readByte(MPU6050_ADDRESS, INT_STATUS) & 0x01) { // check if data ready interrupt mpu6050.readAccelData(accelCount); // Read the x/y/z adc values mpu6050.readGyroData(gyroCount); // Read the x/y/z adc values // Now we'll calculate the accleration value into actual g's ax = (float)accelCount[0]*aRes - accelBias[0]; // get actual g value, this depends on scale being set ay = (float)accelCount[1]*aRes - accelBias[1]; az = (float)accelCount[2]*aRes - accelBias[2]; // Calculate the gyro value into actual degrees per second gx = (float)gyroCount[0]*gRes - gyroBias[0]; // get actual gyro value, this depends on scale being set gy = (float)gyroCount[1]*gRes - gyroBias[1]; gz = (float)gyroCount[2]*gRes - gyroBias[2]; } */ } } }