Library for using the xbee-compatible Bluetooth Bee Module on an m3pi.
Dependencies: SensoryTest
Fork of btbee by
main.cpp@10:7ef481d28dcd, 2014-05-20 (annotated)
- Committer:
- mmpeter
- Date:
- Tue May 20 14:33:23 2014 +0000
- Revision:
- 10:7ef481d28dcd
- Parent:
- 9:6ae4359b73df
- Child:
- 11:45172e28ecb2
testing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mmpeter | 8:fd8a30a6923d | 1 | #include "mbed.h" |
mmpeter | 8:fd8a30a6923d | 2 | #include "m3pi_ng.h" |
mmpeter | 8:fd8a30a6923d | 3 | |
mmpeter | 8:fd8a30a6923d | 4 | m3pi thinggy; |
mmpeter | 8:fd8a30a6923d | 5 | |
mmpeter | 8:fd8a30a6923d | 6 | |
mmpeter | 8:fd8a30a6923d | 7 | int main() { |
mmpeter | 8:fd8a30a6923d | 8 | |
mmpeter | 8:fd8a30a6923d | 9 | float speed = 0.1; |
mmpeter | 10:7ef481d28dcd | 10 | float correction = 0.5; |
mmpeter | 10:7ef481d28dcd | 11 | float threshold = 0.5; |
mmpeter | 9:6ae4359b73df | 12 | |
mmpeter | 9:6ae4359b73df | 13 | thinggy.locate(0,1); |
mmpeter | 9:6ae4359b73df | 14 | thinggy.printf("Line Flw"); |
mmpeter | 8:fd8a30a6923d | 15 | |
mmpeter | 10:7ef481d28dcd | 16 | wait(1.0); |
mmpeter | 8:fd8a30a6923d | 17 | |
mmpeter | 8:fd8a30a6923d | 18 | thinggy.sensor_auto_calibrate(); |
mmpeter | 8:fd8a30a6923d | 19 | while(1) { |
mmpeter | 8:fd8a30a6923d | 20 | // -1.0 is far left, 1.0 is far right, 0.0 in the middle |
mmpeter | 8:fd8a30a6923d | 21 | float position= thinggy.line_position(); |
mmpeter | 8:fd8a30a6923d | 22 | |
mmpeter | 10:7ef481d28dcd | 23 | // Too far to the right--slow left motor |
mmpeter | 8:fd8a30a6923d | 24 | if (position > threshold) { |
mmpeter | 10:7ef481d28dcd | 25 | thinggy.right_motor(speed); |
mmpeter | 10:7ef481d28dcd | 26 | thinggy.left_motor(speed-correction); |
mmpeter | 9:6ae4359b73df | 27 | |
mmpeter | 8:fd8a30a6923d | 28 | } |
mmpeter | 8:fd8a30a6923d | 29 | |
mmpeter | 10:7ef481d28dcd | 30 | // Too far to the left--slow right motor |
mmpeter | 8:fd8a30a6923d | 31 | else if (position < -threshold) { |
mmpeter | 9:6ae4359b73df | 32 | thinggy.left_motor(speed); |
mmpeter | 10:7ef481d28dcd | 33 | thinggy.right_motor(speed-correction); |
mmpeter | 8:fd8a30a6923d | 34 | |
mmpeter | 8:fd8a30a6923d | 35 | } |
mmpeter | 8:fd8a30a6923d | 36 | |
mmpeter | 10:7ef481d28dcd | 37 | // Default: Centered |
mmpeter | 8:fd8a30a6923d | 38 | else { |
mmpeter | 8:fd8a30a6923d | 39 | thinggy.forward(speed); |
mmpeter | 8:fd8a30a6923d | 40 | } |
mmpeter | 8:fd8a30a6923d | 41 | } |
mmpeter | 8:fd8a30a6923d | 42 | } |
mmpeter | 8:fd8a30a6923d | 43 |