![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
added main and defined M_PI
Dependencies: BNOWrapper
main.cpp@2:1fd1549d3fbd, 2019-07-22 (annotated)
- Committer:
- JesiMiranda
- Date:
- Mon Jul 22 18:54:39 2019 +0000
- Revision:
- 2:1fd1549d3fbd
- Parent:
- 1:4a5b43b9502c
- Child:
- 3:24e65bfcea6d
fixed some syntax
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JesiMiranda | 1:4a5b43b9502c | 1 | #include <mbed.h> |
JesiMiranda | 1:4a5b43b9502c | 2 | #include <BNO080.h> |
JesiMiranda | 2:1fd1549d3fbd | 3 | |
JesiMiranda | 0:0f12b8c4d5f1 | 4 | int main() |
JesiMiranda | 0:0f12b8c4d5f1 | 5 | { |
JesiMiranda | 2:1fd1549d3fbd | 6 | Serial pc(USBTX, USBRX, 9600); |
JesiMiranda | 1:4a5b43b9502c | 7 | |
JesiMiranda | 1:4a5b43b9502c | 8 | // Create IMU, passing in output stream, pins, I2C address, and I2C frequency |
JesiMiranda | 1:4a5b43b9502c | 9 | // These pin assignments are specific to my dev setup -- you'll need to change them |
JesiMiranda | 2:1fd1549d3fbd | 10 | BNO080 imu(&pc, PB_7 , PB_6, PB_0, D10, 0x4b, 400000); |
JesiMiranda | 1:4a5b43b9502c | 11 | |
JesiMiranda | 1:4a5b43b9502c | 12 | pc.printf("============================================================\n"); |
JesiMiranda | 2:1fd1549d3fbd | 13 | imu.begin(); |
JesiMiranda | 2:1fd1549d3fbd | 14 | pc.printf("======================================ENABLING REPORT FOR IMU==========================================================\r\n"); |
JesiMiranda | 1:4a5b43b9502c | 15 | // Tell the IMU to report rotation every 100ms and acceleration every 200ms |
JesiMiranda | 1:4a5b43b9502c | 16 | imu.enableReport(BNO080::ROTATION, 100); |
JesiMiranda | 1:4a5b43b9502c | 17 | imu.enableReport(BNO080::TOTAL_ACCELERATION, 200); |
JesiMiranda | 2:1fd1549d3fbd | 18 | pc.printf("======================================DONE ENABLING REPORT FOR IMU ===================================================\r\n"); |
JesiMiranda | 2:1fd1549d3fbd | 19 | pc.printf("========================= STUCK INSIDE THE WHILE LOOP ===============================\r\n"); |
JesiMiranda | 1:4a5b43b9502c | 20 | while (true) |
JesiMiranda | 2:1fd1549d3fbd | 21 | { |
JesiMiranda | 1:4a5b43b9502c | 22 | wait(.001f); |
JesiMiranda | 1:4a5b43b9502c | 23 | // poll the IMU for new data -- this returns true if any packets were received |
JesiMiranda | 1:4a5b43b9502c | 24 | if(imu.updateData()) |
JesiMiranda | 1:4a5b43b9502c | 25 | { |
JesiMiranda | 2:1fd1549d3fbd | 26 | pc.printf("======================================= INSIDE IMU.UPDATEDATA() =================================\r\n"); |
JesiMiranda | 1:4a5b43b9502c | 27 | // now check for the specific type of data that was received (can be multiple at once) |
JesiMiranda | 1:4a5b43b9502c | 28 | if (imu.hasNewData(BNO080::ROTATION)) |
JesiMiranda | 1:4a5b43b9502c | 29 | { |
JesiMiranda | 1:4a5b43b9502c | 30 | // convert quaternion to Euler degrees and print |
JesiMiranda | 1:4a5b43b9502c | 31 | pc.printf("IMU Rotation Euler: "); |
JesiMiranda | 1:4a5b43b9502c | 32 | TVector3 eulerRadians = imu.rotationVector.euler(); |
JesiMiranda | 1:4a5b43b9502c | 33 | TVector3 eulerDegrees = eulerRadians * (180.0 / M_PI); |
JesiMiranda | 1:4a5b43b9502c | 34 | eulerDegrees.print(pc, true); |
JesiMiranda | 1:4a5b43b9502c | 35 | pc.printf("\n"); |
JesiMiranda | 1:4a5b43b9502c | 36 | } |
JesiMiranda | 1:4a5b43b9502c | 37 | if (imu.hasNewData(BNO080::TOTAL_ACCELERATION)) |
JesiMiranda | 1:4a5b43b9502c | 38 | { |
JesiMiranda | 1:4a5b43b9502c | 39 | // print the acceleration vector using its builtin print() method |
JesiMiranda | 1:4a5b43b9502c | 40 | pc.printf("IMU Total Acceleration: "); |
JesiMiranda | 1:4a5b43b9502c | 41 | imu.totalAcceleration.print(pc, true); |
JesiMiranda | 1:4a5b43b9502c | 42 | pc.printf("\n"); |
JesiMiranda | 1:4a5b43b9502c | 43 | } |
JesiMiranda | 1:4a5b43b9502c | 44 | } |
JesiMiranda | 0:0f12b8c4d5f1 | 45 | } |
JesiMiranda | 1:4a5b43b9502c | 46 | |
JesiMiranda | 0:0f12b8c4d5f1 | 47 | } |
JesiMiranda | 1:4a5b43b9502c | 48 | |
JesiMiranda | 1:4a5b43b9502c | 49 |