![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
added main and defined M_PI
main.cpp@5:eefbf579d5cc, 2019-07-30 (annotated)
- Committer:
- JesiMiranda
- Date:
- Tue Jul 30 16:44:23 2019 +0000
- Revision:
- 5:eefbf579d5cc
- Parent:
- 4:ecd3871549e8
- Child:
- 7:b548a684290d
Jamie changed the cpp
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 | 5:eefbf579d5cc | 6 | Serial pc(USBTX, USBRX, 192000); |
JesiMiranda | 5:eefbf579d5cc | 7 | |
JesiMiranda | 3:24e65bfcea6d | 8 | |
JesiMiranda | 1:4a5b43b9502c | 9 | // Create IMU, passing in output stream, pins, I2C address, and I2C frequency |
JesiMiranda | 1:4a5b43b9502c | 10 | // These pin assignments are specific to my dev setup -- you'll need to change them |
JesiMiranda | 5:eefbf579d5cc | 11 | BNO080 imu(&pc, D4, D5, D12, D10, 0x4b, 100000); |
JesiMiranda | 3:24e65bfcea6d | 12 | |
JesiMiranda | 2:1fd1549d3fbd | 13 | imu.begin(); |
JesiMiranda | 4:ecd3871549e8 | 14 | |
JesiMiranda | 1:4a5b43b9502c | 15 | // Tell the IMU to report rotation every 100ms and acceleration every 200ms |
JesiMiranda | 5:eefbf579d5cc | 16 | |
JesiMiranda | 5:eefbf579d5cc | 17 | imu.enableReport(BNO080::TOTAL_ACCELERATION, 100); |
JesiMiranda | 5:eefbf579d5cc | 18 | //imu.enableReport(BNO080::GRAVITY_ACCELERATION, 100); |
JesiMiranda | 1:4a5b43b9502c | 19 | imu.enableReport(BNO080::ROTATION, 100); |
JesiMiranda | 3:24e65bfcea6d | 20 | |
JesiMiranda | 3:24e65bfcea6d | 21 | while (true) { |
JesiMiranda | 1:4a5b43b9502c | 22 | wait(.001f); |
JesiMiranda | 4:ecd3871549e8 | 23 | |
JesiMiranda | 1:4a5b43b9502c | 24 | // poll the IMU for new data -- this returns true if any packets were received |
JesiMiranda | 5:eefbf579d5cc | 25 | |
JesiMiranda | 3:24e65bfcea6d | 26 | if(imu.updateData()) { |
JesiMiranda | 1:4a5b43b9502c | 27 | // now check for the specific type of data that was received (can be multiple at once) |
JesiMiranda | 5:eefbf579d5cc | 28 | if (imu.hasNewData(BNO080::TOTAL_ACCELERATION) || imu.hasNewData(BNO080::ROTATION)) { |
JesiMiranda | 5:eefbf579d5cc | 29 | pc.printf("Total Accel: "); |
JesiMiranda | 5:eefbf579d5cc | 30 | imu.totalAcceleration.print(pc, true); |
JesiMiranda | 5:eefbf579d5cc | 31 | |
JesiMiranda | 5:eefbf579d5cc | 32 | pc.printf(", Rotation:"); |
JesiMiranda | 1:4a5b43b9502c | 33 | TVector3 eulerRadians = imu.rotationVector.euler(); |
JesiMiranda | 1:4a5b43b9502c | 34 | TVector3 eulerDegrees = eulerRadians * (180.0 / M_PI); |
JesiMiranda | 1:4a5b43b9502c | 35 | eulerDegrees.print(pc, true); |
JesiMiranda | 1:4a5b43b9502c | 36 | pc.printf("\n"); |
JesiMiranda | 1:4a5b43b9502c | 37 | } |
JesiMiranda | 5:eefbf579d5cc | 38 | |
JesiMiranda | 1:4a5b43b9502c | 39 | } |
JesiMiranda | 0:0f12b8c4d5f1 | 40 | } |
JesiMiranda | 3:24e65bfcea6d | 41 | |
JesiMiranda | 0:0f12b8c4d5f1 | 42 | } |
JesiMiranda | 3:24e65bfcea6d | 43 |