Lab 4CHEL
/
Bertel_FollowLine
1 Sensor
Fork of BertlTemplate2 by
Bertel_FollowLine.cpp
- Committer:
- TFuchsbichler
- Date:
- 2016-03-07
- Revision:
- 3:d0894bb57690
- Parent:
- 2:bc32145e7819
File content as of revision 3:d0894bb57690:
#include "mbed.h" #include "Serial_HL.h" #include "Bertl14.h" #include "BertlObjects.h" void FollowLine(); void FindLine(); void rightturn(); void leftturn(); void stop(); void lefthard(); void righthard(); int leftright; BusOut boardPow(p30, P1_6,P1_7); AnalogInHL ls1(p18), ls2(p16), ls3(p20), ls4(p19),ls5(p17); int main(void) { boardPow=3; InitBertl(); pex.ClearLeds(); // Damit der Roboter nicht gleich loskoffert leds = 9; pex.WaitUntilFrontButtonPressed(); leds=6; wait(0.8); leds=0; // 2x Button-pressed jetzt gehts los while(1) { wait(1); FollowLine(); } } void FollowLine() { while(1) { if(ls2.Read()>600) { t.reset(); leftturn(); leftright=1; } if(ls2.Read()<600) { rightturn(); leftright=0; } } } void rightturn() { mL.SetPow(0.2); mR.SetPow(0.1); } void leftturn() { mL.SetPow(0.1); mR.SetPow(0.2); } void stop() { mL.SetPow(0); mR.SetPow(0); } void righthard() { mL.SetPow(-0.4); mR.SetPow(0.4); } void lefthard() { mL.SetPow(-0.4); mR.SetPow(0.4); } void FindLine() { while(1) { if(leftright==1) { righthard(); } if(leftright==0) { lefthard(); } if(ls2.Read()>500|ls3.Read()>500) { stop(); break; } } }