Library for using the xbee-compatible Bluetooth Bee Module on an m3pi.

Dependencies:   SensoryTest

Fork of btbee by Nikolas Goldin

Committer:
mmpeter
Date:
Wed May 21 12:20:43 2014 +0000
Revision:
15:cc5b8a858c6e
Parent:
14:7ddbd9f475ad
Child:
16:2b437630e29e
k=-0.7, speed=0.5, correction for jumpy turns

Who changed what in which revision?

UserRevisionLine numberNew 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 15:cc5b8a858c6e 9 float speed = 0.5;
mmpeter 11:45172e28ecb2 10 float correction;
mmpeter 15:cc5b8a858c6e 11 float k = -0.7;
mmpeter 13:4016c362b0d5 12
mmpeter 9:6ae4359b73df 13
mmpeter 9:6ae4359b73df 14 thinggy.locate(0,1);
mmpeter 15:cc5b8a858c6e 15 thinggy.printf("HellzYa");
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 15:cc5b8a858c6e 29 thinggy.right_motor(0.6);
mmpeter 15:cc5b8a858c6e 30 }
mmpeter 15:cc5b8a858c6e 31 else if(speed + correction <= 0){
mmpeter 15:cc5b8a858c6e 32 thinggy.right_motor(0.1);
mmpeter 11:45172e28ecb2 33 }
mmpeter 11:45172e28ecb2 34 else{
mmpeter 11:45172e28ecb2 35 thinggy.right_motor(speed+correction);
mmpeter 11:45172e28ecb2 36 }
mmpeter 11:45172e28ecb2 37
mmpeter 11:45172e28ecb2 38 //speed limiting for left motor
mmpeter 11:45172e28ecb2 39 if(speed - correction > 1){
mmpeter 15:cc5b8a858c6e 40 thinggy.left_motor(0.6);
mmpeter 15:cc5b8a858c6e 41 }
mmpeter 15:cc5b8a858c6e 42 else if(speed - correction <= 0){
mmpeter 15:cc5b8a858c6e 43 thinggy.left_motor(0.1);
mmpeter 11:45172e28ecb2 44 }
mmpeter 11:45172e28ecb2 45 else{
mmpeter 10:7ef481d28dcd 46 thinggy.left_motor(speed-correction);
mmpeter 11:45172e28ecb2 47 }
mmpeter 9:6ae4359b73df 48
mmpeter 11:45172e28ecb2 49
mmpeter 13:4016c362b0d5 50
mmpeter 13:4016c362b0d5 51
mmpeter 11:45172e28ecb2 52 }
mmpeter 11:45172e28ecb2 53 }