jetfishteam
/
robfish_test_IMU_and_hallsensor
Tests for BNO055 IMU and hall sensor interrupts
main.cpp@0:c462deb7ee50, 2016-03-20 (annotated)
- Committer:
- alex93
- Date:
- Sun Mar 20 03:01:54 2016 +0000
- Revision:
- 0:c462deb7ee50
Tests for BNO055 IMU and hall sensor interrupts
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
alex93 | 0:c462deb7ee50 | 1 | /********************************************************************************* |
alex93 | 0:c462deb7ee50 | 2 | * This code sets the valve motor to a pwm of 0.8. It also sets interrupts for the |
alex93 | 0:c462deb7ee50 | 3 | * hall sensor input, so on each rising and falling edge, LED1 is flipped, testing |
alex93 | 0:c462deb7ee50 | 4 | * the ability of the mbed to accurately detect the hall sensor reading. Lastly, |
alex93 | 0:c462deb7ee50 | 5 | * this code configures the BNO055 and prints the yaw, pitch, and roll to a PC |
alex93 | 0:c462deb7ee50 | 6 | * terminal. |
alex93 | 0:c462deb7ee50 | 7 | *********************************************************************************/ |
alex93 | 0:c462deb7ee50 | 8 | |
alex93 | 0:c462deb7ee50 | 9 | #include "mbed.h" |
alex93 | 0:c462deb7ee50 | 10 | #include "BNO055.h" |
alex93 | 0:c462deb7ee50 | 11 | using namespace std; |
alex93 | 0:c462deb7ee50 | 12 | |
alex93 | 0:c462deb7ee50 | 13 | Serial pc(USBTX, USBRX); |
alex93 | 0:c462deb7ee50 | 14 | |
alex93 | 0:c462deb7ee50 | 15 | // BNO055 |
alex93 | 0:c462deb7ee50 | 16 | BNO055 bno055(p28, p27); |
alex93 | 0:c462deb7ee50 | 17 | |
alex93 | 0:c462deb7ee50 | 18 | // Hall Sensor |
alex93 | 0:c462deb7ee50 | 19 | InterruptIn hallVoltage1(p8); |
alex93 | 0:c462deb7ee50 | 20 | DigitalOut led1(LED1); |
alex93 | 0:c462deb7ee50 | 21 | |
alex93 | 0:c462deb7ee50 | 22 | // Motor Driver |
alex93 | 0:c462deb7ee50 | 23 | PwmOut valve_pwm(p21); |
alex93 | 0:c462deb7ee50 | 24 | |
alex93 | 0:c462deb7ee50 | 25 | void flipLed1() { |
alex93 | 0:c462deb7ee50 | 26 | led1 = !led1; |
alex93 | 0:c462deb7ee50 | 27 | } |
alex93 | 0:c462deb7ee50 | 28 | |
alex93 | 0:c462deb7ee50 | 29 | int main() { |
alex93 | 0:c462deb7ee50 | 30 | led1 = 0; |
alex93 | 0:c462deb7ee50 | 31 | hallVoltage1.rise(&flipLed1); |
alex93 | 0:c462deb7ee50 | 32 | hallVoltage1.fall(&flipLed1); |
alex93 | 0:c462deb7ee50 | 33 | |
alex93 | 0:c462deb7ee50 | 34 | valve_pwm = 0.8; |
alex93 | 0:c462deb7ee50 | 35 | |
alex93 | 0:c462deb7ee50 | 36 | bno055.reset(); |
alex93 | 0:c462deb7ee50 | 37 | bno055.setmode(OPERATION_MODE_NDOF); |
alex93 | 0:c462deb7ee50 | 38 | bno055.write_calibration_data(); |
alex93 | 0:c462deb7ee50 | 39 | bno055.get_calib(); |
alex93 | 0:c462deb7ee50 | 40 | while (bno055.calib == 0) { |
alex93 | 0:c462deb7ee50 | 41 | bno055.get_calib(); |
alex93 | 0:c462deb7ee50 | 42 | } |
alex93 | 0:c462deb7ee50 | 43 | |
alex93 | 0:c462deb7ee50 | 44 | while(1) { |
alex93 | 0:c462deb7ee50 | 45 | bno055.get_angles(); //query the i2c device |
alex93 | 0:c462deb7ee50 | 46 | pc.printf("yaw:%6.2f pitch:%6.2f roll:%6.2f\n",bno055.euler.yaw, bno055.euler.pitch, bno055.euler.roll); |
alex93 | 0:c462deb7ee50 | 47 | } |
alex93 | 0:c462deb7ee50 | 48 | } |