use in class project

Dependencies:   mbed BNO055 ros_lib_kinetic

Committer:
chawankorn
Date:
Sat Dec 15 08:49:09 2018 +0000
Revision:
0:7f3dd28ad889
Child:
1:1e40c57efbb1
use in class project

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chawankorn 0:7f3dd28ad889 1 #include "mbed.h"
chawankorn 0:7f3dd28ad889 2 #include "BNO055.h"
chawankorn 0:7f3dd28ad889 3
chawankorn 0:7f3dd28ad889 4 Serial pc(USBTX, USBRX);
chawankorn 0:7f3dd28ad889 5 BNO055 imu(I2C_SDA,I2C_SCL);
chawankorn 0:7f3dd28ad889 6 DigitalOut led(LED1);
chawankorn 0:7f3dd28ad889 7
chawankorn 0:7f3dd28ad889 8 int main() {
chawankorn 0:7f3dd28ad889 9 pc.baud(115200);
chawankorn 0:7f3dd28ad889 10 pc.printf("BNO055 Hello World\r\n\r\n");
chawankorn 0:7f3dd28ad889 11 led = 1;
chawankorn 0:7f3dd28ad889 12 // Reset the BNO055
chawankorn 0:7f3dd28ad889 13 imu.reset();
chawankorn 0:7f3dd28ad889 14 // Check that the BNO055 is connected and flash LED if not
chawankorn 0:7f3dd28ad889 15 if (!imu.check())
chawankorn 0:7f3dd28ad889 16 while (true){
chawankorn 0:7f3dd28ad889 17 led = !led;
chawankorn 0:7f3dd28ad889 18 wait(0.1);
chawankorn 0:7f3dd28ad889 19 }
chawankorn 0:7f3dd28ad889 20 // Display sensor information
chawankorn 0:7f3dd28ad889 21 pc.printf("BNO055 found\r\n\r\n");
chawankorn 0:7f3dd28ad889 22 pc.printf("Chip ID: %u\r\n",imu.ID.id);
chawankorn 0:7f3dd28ad889 23 pc.printf("Accelerometer ID: %u\r\n",imu.ID.accel);
chawankorn 0:7f3dd28ad889 24 pc.printf("Gyroscope ID: %u\r\n",imu.ID.gyro);
chawankorn 0:7f3dd28ad889 25 pc.printf("Magnetometer ID: %u\r\n\r\n",imu.ID.mag);
chawankorn 0:7f3dd28ad889 26 pc.printf("Firmware version v%d.%0d\r\n",imu.ID.sw[0],imu.ID.sw[1]);
chawankorn 0:7f3dd28ad889 27 pc.printf("Bootloader version v%d\r\n\r\n",imu.ID.bootload);
chawankorn 0:7f3dd28ad889 28 // Display chip serial number
chawankorn 0:7f3dd28ad889 29 for (int i = 0; i<4; i++){
chawankorn 0:7f3dd28ad889 30 pc.printf("%u.%u.%u.%u\r\n",imu.ID.serial[i*4],imu.ID.serial[i*4+1],imu.ID.serial[i*4+2],imu.ID.serial[i*4+3]);
chawankorn 0:7f3dd28ad889 31 }
chawankorn 0:7f3dd28ad889 32 pc.printf("\r\n");
chawankorn 0:7f3dd28ad889 33
chawankorn 0:7f3dd28ad889 34 while (true) {
chawankorn 0:7f3dd28ad889 35 imu.setmode(OPERATION_MODE_NDOF);
chawankorn 0:7f3dd28ad889 36 imu.get_calib();
chawankorn 0:7f3dd28ad889 37 imu.get_angles();
chawankorn 0:7f3dd28ad889 38 imu.get_temp();
chawankorn 0:7f3dd28ad889 39 imu.get_quat();
chawankorn 0:7f3dd28ad889 40 pc.printf("Temperature\t%d\n", imu.temperature);
chawankorn 0:7f3dd28ad889 41 pc.printf("Quaternion: w:%f\tx:%f\ty:%f\tz:%f\n", imu.quat.w, imu.quat.x, imu.quat.y, imu.quat.z);
chawankorn 0:7f3dd28ad889 42 //pc.printf("%u\t\t%5.1d\t\t%5.1d\t\t%5.1d\r\n",imu.calib,imu.euler.roll,imu.euler.pitch,imu.euler.yaw);
chawankorn 0:7f3dd28ad889 43 wait(0.5);
chawankorn 0:7f3dd28ad889 44 }
chawankorn 0:7f3dd28ad889 45 }