![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
cube
Dependencies: BNO055_fusion_tom FastPWM mbed
main.cpp@8:1011786787a4, 2017-04-09 (annotated)
- Committer:
- wchurch
- Date:
- Sun Apr 09 19:28:56 2017 +0000
- Revision:
- 8:1011786787a4
- Parent:
- 7:1be7e6735fe2
- Child:
- 9:6a83e2777d24
basic loop going
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wchurch | 0:604ceafb7bb3 | 1 | #include "mbed.h" |
wchurch | 0:604ceafb7bb3 | 2 | #include "BNO055.h" |
wchurch | 0:604ceafb7bb3 | 3 | |
wchurch | 0:604ceafb7bb3 | 4 | |
wchurch | 0:604ceafb7bb3 | 5 | //------------------------------------ |
wchurch | 0:604ceafb7bb3 | 6 | // Hyperterminal configuration |
wchurch | 0:604ceafb7bb3 | 7 | // 9600 bauds, 8-bit data, no parity |
wchurch | 0:604ceafb7bb3 | 8 | //------------------------------------ |
wchurch | 0:604ceafb7bb3 | 9 | |
wchurch | 0:604ceafb7bb3 | 10 | Serial pc(SERIAL_TX, SERIAL_RX); |
wchurch | 0:604ceafb7bb3 | 11 | |
wchurch | 5:9247f07a954a | 12 | Ticker pwmint; |
wchurch | 0:604ceafb7bb3 | 13 | DigitalOut myled(LED1); |
wchurch | 6:f2c930a90873 | 14 | InterruptIn button(USER_BUTTON); |
wchurch | 6:f2c930a90873 | 15 | |
wchurch | 1:d81f93d3f819 | 16 | PwmOut P1(PE_9); |
wchurch | 7:1be7e6735fe2 | 17 | //PwmOut P2(PE_11); 1D FOCUS FOR NOW |
wchurch | 7:1be7e6735fe2 | 18 | //PwmOut P3(PE_13); |
wchurch | 0:604ceafb7bb3 | 19 | |
wchurch | 0:604ceafb7bb3 | 20 | I2C i2c(PB_9, PB_8); // SDA, SCL |
wchurch | 0:604ceafb7bb3 | 21 | BNO055 imu(i2c, PA_8); // Reset |
wchurch | 0:604ceafb7bb3 | 22 | |
wchurch | 0:604ceafb7bb3 | 23 | BNO055_ID_INF_TypeDef bno055_id_inf; |
wchurch | 0:604ceafb7bb3 | 24 | BNO055_EULER_TypeDef euler_angles; |
wchurch | 7:1be7e6735fe2 | 25 | |
wchurch | 7:1be7e6735fe2 | 26 | |
wchurch | 8:1011786787a4 | 27 | //BNO055_EULER_TypeDef velocity; IN PROGRESS |
wchurch | 6:f2c930a90873 | 28 | |
wchurch | 8:1011786787a4 | 29 | double Kbt = 0.003; |
wchurch | 8:1011786787a4 | 30 | double Kbv = 0.23; |
wchurch | 8:1011786787a4 | 31 | double Kwv = 0.124; |
wchurch | 8:1011786787a4 | 32 | double r1; |
wchurch | 8:1011786787a4 | 33 | |
wchurch | 6:f2c930a90873 | 34 | int isPressed; |
wchurch | 6:f2c930a90873 | 35 | |
wchurch | 6:f2c930a90873 | 36 | void pwmupdate() { |
wchurch | 6:f2c930a90873 | 37 | |
wchurch | 6:f2c930a90873 | 38 | myled = !myled; |
wchurch | 6:f2c930a90873 | 39 | |
wchurch | 8:1011786787a4 | 40 | r1 = (Kbt*euler_angles.h); |
wchurch | 8:1011786787a4 | 41 | r1 = (r1 + 6.0)/12.0 ; //Normalize for PWM output |
wchurch | 8:1011786787a4 | 42 | P1 = r1; |
wchurch | 7:1be7e6735fe2 | 43 | //P2 = (euler_angles.r/360.0); |
wchurch | 7:1be7e6735fe2 | 44 | //P3 = (euler_angles.p/360.0); |
wchurch | 6:f2c930a90873 | 45 | |
wchurch | 6:f2c930a90873 | 46 | } |
wchurch | 6:f2c930a90873 | 47 | |
wchurch | 6:f2c930a90873 | 48 | void eventFunction() { |
wchurch | 7:1be7e6735fe2 | 49 | |
wchurch | 6:f2c930a90873 | 50 | if(!isPressed) { |
wchurch | 8:1011786787a4 | 51 | pwmint.attach(&pwmupdate, .005); |
wchurch | 6:f2c930a90873 | 52 | isPressed=1; |
wchurch | 7:1be7e6735fe2 | 53 | |
wchurch | 6:f2c930a90873 | 54 | } else { |
wchurch | 6:f2c930a90873 | 55 | pwmint.detach(); |
wchurch | 7:1be7e6735fe2 | 56 | P1 = 0; |
wchurch | 8:1011786787a4 | 57 | myled = 0; |
wchurch | 7:1be7e6735fe2 | 58 | //P2 = 0; |
wchurch | 7:1be7e6735fe2 | 59 | //P3 = 0; |
wchurch | 6:f2c930a90873 | 60 | isPressed=0; |
wchurch | 6:f2c930a90873 | 61 | } |
wchurch | 6:f2c930a90873 | 62 | } |
wchurch | 6:f2c930a90873 | 63 | |
wchurch | 6:f2c930a90873 | 64 | int main() |
wchurch | 6:f2c930a90873 | 65 | { |
wchurch | 0:604ceafb7bb3 | 66 | |
wchurch | 0:604ceafb7bb3 | 67 | pc.printf("Bosch Sensortec BNO055 test program on " __DATE__ "/" __TIME__ "\r\n"); |
wchurch | 0:604ceafb7bb3 | 68 | if (imu.chip_ready() == 0){ |
wchurch | 4:ae9e664301dd | 69 | pc.printf("Bosch BNO055 is NOT available!!\r\n"); |
wchurch | 0:604ceafb7bb3 | 70 | } |
wchurch | 6:f2c930a90873 | 71 | |
wchurch | 0:604ceafb7bb3 | 72 | imu.read_id_inf(&bno055_id_inf); |
wchurch | 6:f2c930a90873 | 73 | |
wchurch | 7:1be7e6735fe2 | 74 | //pc.printf("CHIP:0x%02x, ACC:0x%02x, MAG:0x%02x, GYR:0x%02x, , SW:0x%04x, , BL:0x%02x\r\n", |
wchurch | 7:1be7e6735fe2 | 75 | // bno055_id_inf.chip_id, bno055_id_inf.acc_id, bno055_id_inf.mag_id, |
wchurch | 7:1be7e6735fe2 | 76 | // bno055_id_inf.gyr_id, bno055_id_inf.sw_rev_id, bno055_id_inf.bootldr_rev_id); |
wchurch | 6:f2c930a90873 | 77 | |
wchurch | 7:1be7e6735fe2 | 78 | P1.period(0.0002); |
wchurch | 7:1be7e6735fe2 | 79 | |
wchurch | 6:f2c930a90873 | 80 | isPressed=0; |
wchurch | 6:f2c930a90873 | 81 | button.rise(&eventFunction); |
wchurch | 6:f2c930a90873 | 82 | |
wchurch | 6:f2c930a90873 | 83 | |
wchurch | 0:604ceafb7bb3 | 84 | |
wchurch | 0:604ceafb7bb3 | 85 | while(1) { |
wchurch | 6:f2c930a90873 | 86 | |
wchurch | 6:f2c930a90873 | 87 | |
wchurch | 0:604ceafb7bb3 | 88 | pc.printf("Heading:%+6.4f [deg], Roll:%+6.4f [deg], Pitch:%+6.4f [deg]\r\n", |
wchurch | 0:604ceafb7bb3 | 89 | euler_angles.h, euler_angles.r, euler_angles.p); |
wchurch | 7:1be7e6735fe2 | 90 | |
wchurch | 6:f2c930a90873 | 91 | imu.get_Euler_Angles(&euler_angles); |
wchurch | 6:f2c930a90873 | 92 | |
wchurch | 0:604ceafb7bb3 | 93 | |
wchurch | 8:1011786787a4 | 94 | //wait(0.2); |
wchurch | 0:604ceafb7bb3 | 95 | } |
wchurch | 0:604ceafb7bb3 | 96 | } |