Library for using the xbee-compatible Bluetooth Bee Module on an m3pi.
Dependencies: SensoryTest
Fork of btbee by
main.cpp@11:45172e28ecb2, 2014-05-21 (annotated)
- Committer:
- mmpeter
- Date:
- Wed May 21 11:47:58 2014 +0000
- Revision:
- 11:45172e28ecb2
- Parent:
- 10:7ef481d28dcd
- Child:
- 12:6b5dd9e5469c
Testing K=-0.5
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 | 11:45172e28ecb2 | 9 | float speed = 0.5; |
mmpeter | 11:45172e28ecb2 | 10 | float correction; |
mmpeter | 10:7ef481d28dcd | 11 | float threshold = 0.5; |
mmpeter | 11:45172e28ecb2 | 12 | float k = -0.5; |
mmpeter | 9:6ae4359b73df | 13 | |
mmpeter | 9:6ae4359b73df | 14 | thinggy.locate(0,1); |
mmpeter | 9:6ae4359b73df | 15 | thinggy.printf("Line Flw"); |
mmpeter | 8:fd8a30a6923d | 16 | |
mmpeter | 10:7ef481d28dcd | 17 | wait(1.0); |
mmpeter | 8:fd8a30a6923d | 18 | |
mmpeter | 8:fd8a30a6923d | 19 | thinggy.sensor_auto_calibrate(); |
mmpeter | 8:fd8a30a6923d | 20 | while(1) { |
mmpeter | 11:45172e28ecb2 | 21 | |
mmpeter | 11:45172e28ecb2 | 22 | |
mmpeter | 8:fd8a30a6923d | 23 | // -1.0 is far left, 1.0 is far right, 0.0 in the middle |
mmpeter | 11:45172e28ecb2 | 24 | float position = thinggy.line_position(); |
mmpeter | 11:45172e28ecb2 | 25 | correction = k*(position); |
mmpeter | 11:45172e28ecb2 | 26 | |
mmpeter | 11:45172e28ecb2 | 27 | //speed limiting for right motor |
mmpeter | 11:45172e28ecb2 | 28 | if(speed + correction > 1){ |
mmpeter | 11:45172e28ecb2 | 29 | thinggy.right_motor(1); |
mmpeter | 11:45172e28ecb2 | 30 | } |
mmpeter | 11:45172e28ecb2 | 31 | else{ |
mmpeter | 11:45172e28ecb2 | 32 | thinggy.right_motor(speed+correction); |
mmpeter | 11:45172e28ecb2 | 33 | } |
mmpeter | 11:45172e28ecb2 | 34 | |
mmpeter | 11:45172e28ecb2 | 35 | //speed limiting for left motor |
mmpeter | 11:45172e28ecb2 | 36 | if(speed - correction > 1){ |
mmpeter | 11:45172e28ecb2 | 37 | thinggy.left_motor(1); |
mmpeter | 11:45172e28ecb2 | 38 | } |
mmpeter | 11:45172e28ecb2 | 39 | else{ |
mmpeter | 10:7ef481d28dcd | 40 | thinggy.left_motor(speed-correction); |
mmpeter | 11:45172e28ecb2 | 41 | } |
mmpeter | 9:6ae4359b73df | 42 | |
mmpeter | 11:45172e28ecb2 | 43 | |
mmpeter | 8:fd8a30a6923d | 44 | |
mmpeter | 11:45172e28ecb2 | 45 | } |
mmpeter | 11:45172e28ecb2 | 46 | } |