g

Dependencies:   mbed

Fork of Roboter by Seb Pol

Committer:
spolak
Date:
Wed Jan 11 09:43:00 2017 +0000
Revision:
0:d453d7554981
Klassen zum Blinken und Umwandeln vom Text

Who changed what in which revision?

UserRevisionLine numberNew contents of line
spolak 0:d453d7554981 1 #include "mbed.h"
spolak 0:d453d7554981 2 #include "m3pi_ng.h"
spolak 0:d453d7554981 3
spolak 0:d453d7554981 4 m3pi pi;
spolak 0:d453d7554981 5
spolak 0:d453d7554981 6 int main() {
spolak 0:d453d7554981 7
spolak 0:d453d7554981 8 // Parameters that affect the performance
spolak 0:d453d7554981 9 float speed = 0.7; //geschw.
spolak 0:d453d7554981 10 float correction = 0.5; //korrektur links, rechts
spolak 0:d453d7554981 11 float threshold = 0.5; //schwelle, korrektur
spolak 0:d453d7554981 12
spolak 0:d453d7554981 13 pi.locate(0,1); //vorgefertigte position, ausrichten
spolak 0:d453d7554981 14 pi.printf("Runde: ");
spolak 0:d453d7554981 15
spolak 0:d453d7554981 16 wait(2.0);
spolak 0:d453d7554981 17
spolak 0:d453d7554981 18 pi.sensor_auto_calibrate();
spolak 0:d453d7554981 19
spolak 0:d453d7554981 20 while (1) {
spolak 0:d453d7554981 21
spolak 0:d453d7554981 22 // -1.0 is far left, 1.0 is far right, 0.0 in the middle
spolak 0:d453d7554981 23 float position_of_line = pi.line_position();
spolak 0:d453d7554981 24
spolak 0:d453d7554981 25 // Line is more than the threshold to the right, slow the left motor
spolak 0:d453d7554981 26 if (position_of_line > threshold) {
spolak 0:d453d7554981 27 pi.leftt_motor(speed);
spolak 0:d453d7554981 28 pi.right_motor(speed-correction);
spolak 0:d453d7554981 29 }
spolak 0:d453d7554981 30
spolak 0:d453d7554981 31 // Line is more than 50% to the left, slow the right motor
spolak 0:d453d7554981 32 else if (position_of_line < -threshold) {
spolak 0:d453d7554981 33 pi.right_motor(speed);
spolak 0:d453d7554981 34 pi.left_motor(speed-correction);
spolak 0:d453d7554981 35 }
spolak 0:d453d7554981 36
spolak 0:d453d7554981 37 // Line is in the middle
spolak 0:d453d7554981 38 else {
spolak 0:d453d7554981 39 pi.forward(speed);
spolak 0:d453d7554981 40 }
spolak 0:d453d7554981 41 }
spolak 0:d453d7554981 42 }