Library for using the xbee-compatible Bluetooth Bee Module on an m3pi.
Dependencies: SensoryTest
Fork of btbee by
main.cpp@14:7ddbd9f475ad, 2014-05-21 (annotated)
- Committer:
- mmpeter
- Date:
- Wed May 21 12:06:54 2014 +0000
- Revision:
- 14:7ddbd9f475ad
- Parent:
- 13:4016c362b0d5
- Child:
- 15:cc5b8a858c6e
speed = 0.25, k =-0.3
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 | 14:7ddbd9f475ad | 9 | float speed = 0.25; |
mmpeter | 11:45172e28ecb2 | 10 | float correction; |
mmpeter | 14:7ddbd9f475ad | 11 | float k = -0.3; |
mmpeter | 13:4016c362b0d5 | 12 | |
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 | 14:7ddbd9f475ad | 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 | 13:4016c362b0d5 | 44 | |
mmpeter | 13:4016c362b0d5 | 45 | |
mmpeter | 11:45172e28ecb2 | 46 | } |
mmpeter | 11:45172e28ecb2 | 47 | } |