Library for using the xbee-compatible Bluetooth Bee Module on an m3pi.
Dependencies: SensoryTest
Fork of btbee by
main.cpp@8:fd8a30a6923d, 2014-05-20 (annotated)
- Committer:
- mmpeter
- Date:
- Tue May 20 13:36:31 2014 +0000
- Revision:
- 8:fd8a30a6923d
- Child:
- 9:6ae4359b73df
SensoryTests
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 | 8:fd8a30a6923d | 10 | float threshold = 0.01; |
mmpeter | 8:fd8a30a6923d | 11 | |
mmpeter | 8:fd8a30a6923d | 12 | wait(2.0); |
mmpeter | 8:fd8a30a6923d | 13 | |
mmpeter | 8:fd8a30a6923d | 14 | thinggy.sensor_auto_calibrate(); |
mmpeter | 8:fd8a30a6923d | 15 | while(1) { |
mmpeter | 8:fd8a30a6923d | 16 | // -1.0 is far left, 1.0 is far right, 0.0 in the middle |
mmpeter | 8:fd8a30a6923d | 17 | float position= thinggy.line_position(); |
mmpeter | 8:fd8a30a6923d | 18 | |
mmpeter | 8:fd8a30a6923d | 19 | // Line is more than the threshold to the right, slow the left motor |
mmpeter | 8:fd8a30a6923d | 20 | if (position > threshold) { |
mmpeter | 8:fd8a30a6923d | 21 | thinggy.right(speed); |
mmpeter | 8:fd8a30a6923d | 22 | |
mmpeter | 8:fd8a30a6923d | 23 | } |
mmpeter | 8:fd8a30a6923d | 24 | |
mmpeter | 8:fd8a30a6923d | 25 | // Line is more than 50% to the left, slow the right motor |
mmpeter | 8:fd8a30a6923d | 26 | else if (position < -threshold) { |
mmpeter | 8:fd8a30a6923d | 27 | thinggy.left(speed); |
mmpeter | 8:fd8a30a6923d | 28 | |
mmpeter | 8:fd8a30a6923d | 29 | } |
mmpeter | 8:fd8a30a6923d | 30 | |
mmpeter | 8:fd8a30a6923d | 31 | // Line is in the middle |
mmpeter | 8:fd8a30a6923d | 32 | else { |
mmpeter | 8:fd8a30a6923d | 33 | thinggy.forward(speed); |
mmpeter | 8:fd8a30a6923d | 34 | } |
mmpeter | 8:fd8a30a6923d | 35 | } |
mmpeter | 8:fd8a30a6923d | 36 | } |
mmpeter | 8:fd8a30a6923d | 37 |