blue mbed code for the BNO055 imu from adafruit

Dependencies:   BNO055 MODSERIAL mbed

Fork of bmbed_lidar_belt by sensory_array

Committer:
rkk
Date:
Wed Nov 25 23:23:26 2015 +0000
Revision:
17:32b83c5787fc
Parent:
16:70fce771d828
Child:
19:01d091b38d61
initial code gernation for imu testing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
baraki 0:ce4f790399d9 1 #include "mbed.h"
baraki 0:ce4f790399d9 2 #include "MODSERIAL.h"
baraki 7:660e8ddb231e 3 #include <math.h>
baraki 7:660e8ddb231e 4 #include "BNO055.h"
rkk 5:d4ed744beea2 5
baraki 0:ce4f790399d9 6 #define PC_BAUD 9600
rkk 17:32b83c5787fc 7 //#define BT_BAUD 115200
rkk 17:32b83c5787fc 8
rkk 17:32b83c5787fc 9 //#define TX_PIN p13
rkk 17:32b83c5787fc 10 //#define RX_PIN p14
baraki 7:660e8ddb231e 11 #define IMU_SDA p28
baraki 7:660e8ddb231e 12 #define IMU_SCL p27
baraki 7:660e8ddb231e 13 #define PI 3.14159265
baraki 0:ce4f790399d9 14
baraki 7:660e8ddb231e 15 BNO055 imu(p28,p27);
rkk 5:d4ed744beea2 16
rkk 17:32b83c5787fc 17 //MODSERIAL bt(TX_PIN, RX_PIN);
baraki 0:ce4f790399d9 18 MODSERIAL pc(USBTX,USBRX);
rkk 13:b22fd9c4fbb4 19
baraki 7:660e8ddb231e 20 //for calibrating IMU
baraki 9:59d23ab8d73b 21 //for IMU1:
rkk 17:32b83c5787fc 22 char cal_vals[22] = {255, 255, 220, 255, 13, 0, 83, 255, 36, 1, 80, 0, 253, 255, 0, 0, 1, 0, 232, 3, 235, 2};
baraki 7:660e8ddb231e 23
baraki 0:ce4f790399d9 24 bool newline_detected = false;
baraki 0:ce4f790399d9 25 bool newline_sent = false;
baraki 0:ce4f790399d9 26
baraki 7:660e8ddb231e 27 void setCal(){
baraki 7:660e8ddb231e 28 imu.write_calibration_data();
baraki 7:660e8ddb231e 29 }
baraki 7:660e8ddb231e 30
baraki 0:ce4f790399d9 31 // Called everytime a new character goes into
baraki 0:ce4f790399d9 32 // the RX buffer. Test that character for \n
baraki 0:ce4f790399d9 33 // Note, rxGetLastChar() gets the last char that
baraki 0:ce4f790399d9 34 // we received but it does NOT remove it from
baraki 0:ce4f790399d9 35 // the RX buffer.
baraki 0:ce4f790399d9 36 void rxCallback(MODSERIAL_IRQ_INFO *q)
baraki 0:ce4f790399d9 37 {
baraki 0:ce4f790399d9 38 MODSERIAL *serial = q->serial;
baraki 0:ce4f790399d9 39 if ( serial->rxGetLastChar() == '\n') {
baraki 0:ce4f790399d9 40 newline_detected = true;
baraki 0:ce4f790399d9 41 }
baraki 0:ce4f790399d9 42
baraki 0:ce4f790399d9 43 }
baraki 0:ce4f790399d9 44
baraki 0:ce4f790399d9 45 void txCallback(MODSERIAL_IRQ_INFO *q)
baraki 0:ce4f790399d9 46 {
baraki 0:ce4f790399d9 47 MODSERIAL *serial = q->serial;
baraki 0:ce4f790399d9 48 if ( serial->txGetLastChar() == '\0') {
baraki 0:ce4f790399d9 49 newline_sent = true;
baraki 0:ce4f790399d9 50 }
baraki 0:ce4f790399d9 51 }
baraki 0:ce4f790399d9 52
baraki 0:ce4f790399d9 53 int main()
baraki 0:ce4f790399d9 54 {
baraki 0:ce4f790399d9 55 pc.baud(PC_BAUD);
rkk 17:32b83c5787fc 56 // bt.baud(BT_BAUD);
baraki 0:ce4f790399d9 57 pc.attach(&rxCallback, MODSERIAL::RxIrq);
rkk 17:32b83c5787fc 58 // bt.attach(&txCallback, MODSERIAL::TxIrq);
baraki 0:ce4f790399d9 59
baraki 7:660e8ddb231e 60 //set up IMU
baraki 7:660e8ddb231e 61 imu.reset();
baraki 7:660e8ddb231e 62 imu.setmode(OPERATION_MODE_NDOF);
baraki 7:660e8ddb231e 63 setCal();
baraki 7:660e8ddb231e 64 imu.get_calib();
baraki 7:660e8ddb231e 65 while (imu.calib == 0)
baraki 7:660e8ddb231e 66 {
baraki 7:660e8ddb231e 67 imu.get_calib();
baraki 7:660e8ddb231e 68 }
baraki 7:660e8ddb231e 69
baraki 0:ce4f790399d9 70 char sendData[1] = {0x00};
baraki 0:ce4f790399d9 71
rkk 17:32b83c5787fc 72 // char btData[12] = {'a','b','c','d','e','f','g','\n','\0'};
baraki 15:d6edd100d7fe 73
rkk 17:32b83c5787fc 74 while (1) {
rkk 17:32b83c5787fc 75 imu.get_angles();
rkk 17:32b83c5787fc 76 float pitch = imu.euler.pitch;
rkk 17:32b83c5787fc 77 pc.printf("%f\n",pitch);
rkk 17:32b83c5787fc 78 // pc.printf("about to send data\n");
rkk 17:32b83c5787fc 79 // for(int j=0;j<9;j++){
rkk 17:32b83c5787fc 80 // btData[j] = '\0';
rkk 17:32b83c5787fc 81 // if(bt.writeable())
rkk 17:32b83c5787fc 82 // bt.putc(btData[j]);
rkk 17:32b83c5787fc 83 // //wait(0.001);
rkk 17:32b83c5787fc 84 // }
rkk 17:32b83c5787fc 85 wait(0.5);
baraki 1:5b1d88d69aa2 86 //pc.printf("finished sending data\n");
baraki 0:ce4f790399d9 87 }
baraki 0:ce4f790399d9 88 }