added main and defined M_PI
Dependencies: BNOWrapper
main.cpp@4:ecd3871549e8, 2019-07-29 (annotated)
- Committer:
- JesiMiranda
- Date:
- Mon Jul 29 16:56:33 2019 +0000
- Revision:
- 4:ecd3871549e8
- Parent:
- 3:24e65bfcea6d
- Child:
- 5:eefbf579d5cc
- Child:
- 6:faeba56869a5
connect ps0/1 to gnd for address 4b, address 4a does not work
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 | 3:24e65bfcea6d | 6 | Serial pc(USBTX, USBRX, 115200); |
JesiMiranda | 3:24e65bfcea6d | 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 | 3:24e65bfcea6d | 10 | BNO080 imu(&pc, PB_7, PB_6, D12, PA_11, 0x4b, 400000); |
JesiMiranda | 3:24e65bfcea6d | 11 | |
JesiMiranda | 2:1fd1549d3fbd | 12 | imu.begin(); |
JesiMiranda | 4:ecd3871549e8 | 13 | |
JesiMiranda | 1:4a5b43b9502c | 14 | // Tell the IMU to report rotation every 100ms and acceleration every 200ms |
JesiMiranda | 1:4a5b43b9502c | 15 | imu.enableReport(BNO080::ROTATION, 100); |
JesiMiranda | 1:4a5b43b9502c | 16 | imu.enableReport(BNO080::TOTAL_ACCELERATION, 200); |
JesiMiranda | 3:24e65bfcea6d | 17 | |
JesiMiranda | 3:24e65bfcea6d | 18 | while (true) { |
JesiMiranda | 1:4a5b43b9502c | 19 | wait(.001f); |
JesiMiranda | 4:ecd3871549e8 | 20 | |
JesiMiranda | 1:4a5b43b9502c | 21 | // poll the IMU for new data -- this returns true if any packets were received |
JesiMiranda | 3:24e65bfcea6d | 22 | if(imu.updateData()) { |
JesiMiranda | 1:4a5b43b9502c | 23 | // now check for the specific type of data that was received (can be multiple at once) |
JesiMiranda | 3:24e65bfcea6d | 24 | if (imu.hasNewData(BNO080::ROTATION)) { |
JesiMiranda | 1:4a5b43b9502c | 25 | // convert quaternion to Euler degrees and print |
JesiMiranda | 1:4a5b43b9502c | 26 | pc.printf("IMU Rotation Euler: "); |
JesiMiranda | 1:4a5b43b9502c | 27 | TVector3 eulerRadians = imu.rotationVector.euler(); |
JesiMiranda | 1:4a5b43b9502c | 28 | TVector3 eulerDegrees = eulerRadians * (180.0 / M_PI); |
JesiMiranda | 1:4a5b43b9502c | 29 | eulerDegrees.print(pc, true); |
JesiMiranda | 1:4a5b43b9502c | 30 | pc.printf("\n"); |
JesiMiranda | 1:4a5b43b9502c | 31 | } |
JesiMiranda | 3:24e65bfcea6d | 32 | if (imu.hasNewData(BNO080::TOTAL_ACCELERATION)) { |
JesiMiranda | 1:4a5b43b9502c | 33 | // print the acceleration vector using its builtin print() method |
JesiMiranda | 1:4a5b43b9502c | 34 | pc.printf("IMU Total Acceleration: "); |
JesiMiranda | 1:4a5b43b9502c | 35 | imu.totalAcceleration.print(pc, true); |
JesiMiranda | 1:4a5b43b9502c | 36 | pc.printf("\n"); |
JesiMiranda | 1:4a5b43b9502c | 37 | } |
JesiMiranda | 1:4a5b43b9502c | 38 | } |
JesiMiranda | 0:0f12b8c4d5f1 | 39 | } |
JesiMiranda | 3:24e65bfcea6d | 40 | |
JesiMiranda | 0:0f12b8c4d5f1 | 41 | } |
JesiMiranda | 3:24e65bfcea6d | 42 |