Sunteți pe pagina 1din 36

ROBOTICS Capitolul 2: Servomotoarele Boe-Bot-ului

Acest capitol te va invata sa conectezi, ajustezi si testezi motoarele BoeBotului. Pentru acesta va trebui sa intelegi anumite comenzi ale PBASIC care controleaza directia, viteza si durata miscarii servomotorului. Activitatea 1: Masurarea timpului si repetarea actiunilor: Controlarea vitezei servomotorului se realizeaza cu un program care face ca basic stampul sa trimita acelasi mesaj in repetate randuri. Mesajul trebuie sa se repete de 50 de ori pe secunda pentru ca servomotorul sa mentina viteza si directia. ' Robotics with the Boe-Bot - TimedMessages.bs2 ' Show how the PAUSE command can be used to display messages at human speeds. ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "Start timer..." PAUSE 1000 DEBUG CR, "One second elapsed..." PAUSE 2000 DEBUG CR, "Three seconds elapsed..." DEBUG CR, "Done." END Calificativ FB Studenti: Ilioni Alin, Mardare Adrian, Soruica Sorin, Traila Florin Activitatea 2: Masurarea timpului si repetarea actiunilor folosind un circuit. In aceasta activitate vom construi un circuit care emite o lumina pentru a vedea semnalele folosite pentru a controla servomotoarelor. ' Robotics with the Boe-Bot HighLowLed.bs2 ' Turn the LED connected to P13 on/off once every second. ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "The LED connected to Pin 13 is blinking!" DO

HIGH 13 PAUSE 500 LOW 13 PAUSE 500 LOOP ' Robotics with the Boe-Bot PulseP13Led.bs2 ' Send a 0.13 second pulse to the LED circuit connected to P13 every 2 s. ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "Program Running!" DO PULSOUT 13, 65000 PAUSE 2000 LOOP Calificativ FB Studenti: Ilioni Alin, Mardare Adrian, Soruica Sorin, Traila Florin Activitatea 3: Conectarea servomotoarelor: In acesta activitate vom construi un circuit care conecteaza un servomotor la o sursa de tensiune. Circuitul cu LED construit anterior va fi folosit pentru a monitoriza semnalele din basic stamp trimise la servomotor.

Activitatea 4: Centrarea servomotoarelor: In acesta activitate se va realiza un program care trimite un semnal servomotorului sa stea fix. Deoarece servomotorul nu vine presetat din fabrica va incepe sa se miste dupa ce va primii comanda. Se va folosi o surubelnita pentru a fi ajustat sa stea fix. Dupa ajustare se va testa servomotorul. ' Robotics with the Boe-Bot - CenterServoP12.bs2 ' This program sends 1.5 ms pulses to the servo connected to ' P12 for manual centering. ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "Program Running!" DO PULSOUT 12, 750 PAUSE 20 LOOP

' Robotics with the Boe-Bot - CenterServoP13.bs2 ' This program sends 1.5 ms pulses to the servo connected to ' P13 for manual centering. ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "Program Running!" DO PULSOUT 13, 750 PAUSE 20 LOOP Calificativ FB Studenti: Ilioni Alin, Mardare Adrian, Soruica Sorin, Traila Florin

Activitatea 5: Acesta activitate introduce variabilele care sunt folosite in programele pbasic pentru a memora valori. Programul din boe bot se va baza pe aceste variabile. Cea mai imoprtanta aplicatie folosind memorarea variabilelor este aceea ca boe botul poate numara(contoriza). De vreme ce robotul poate numara acesta poate tine evidenta de fiecare data cand se intampla ceva. VariablesAndSimpleMath.bs2 ' Robotics with the Boe-Bot - VariablesAndSimpleMath.bs2 ' Declare variables and use them to solve a few arithmetic problems. ' {$STAMP BS2} ' {$PBASIC 2.5} value VAR Word ' Declare variables anotherValue VAR Word value = 500 ' Initialize variables anotherValue = 2000 DEBUG ? value ' Display values DEBUG ? anotherValue value = 10 * anotherValue ' Perform operations DEBUG ? value ' Display values again

DEBUG ? anotherValue END Calificativ FB Studenti: Ilioni Alin, Mardare Adrian, Soruica Sorin, Traila Florin

CountToTen.bs2 ' Robotics with the Boe-Bot CountToTen.bs2 ' Use a variable in a FOR...NEXT loop. ' {$STAMP BS2} ' {$PBASIC 2.5} myCounter VAR Word FOR myCounter = 1 TO 10 DEBUG ? myCounter PAUSE 500 NEXT DEBUG CR, "All done!" END Calificativ FB Studenti: Ilioni Alin, Mardare Adrian, Soruica Sorin, Traila Florin

Activitatea 6: testarea servomotoarelor: Inainte de montarea boe botului trebuie testate servomotoarele. Programul acesta va roti servomoaterele intr-o directie si in cealalta pentru a verifica buna functionare a servomotoarelor.

Rotirea servomotorului in sensul acelor de ceasornic: ' Robotics with the Boe-Bot ServoP13Clockwise.bs2 ' Run the servo connected to P13 at full speed clockwise. ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "Program Running!"

DO PULSOUT 13, 650 PAUSE 20 LOOP Rotirea servomotorului in sens trigonometric: ' Robotics with the Boe-Bot ServoP12Counterclockwise.bs2 ' Run the servo connected to P12 at full speed counterclockwise. ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "Program Running!" DO PULSOUT 12, 850 PAUSE 20 LOOP Calificativ FB Studenti: Ilioni Alin, Mardare Adrian, Soruica Sorin, Traila Florin

ControlServoRunTimes.bs2 ' Robotics with the Boe-Bot - ControlServoRunTimes.bs2 ' Run the P13 servo at full speed counterclockwise for 2.3 s, then ' run the P12 servo for twice as long. ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "Program Running!" counter VAR Byte FOR counter = 1 TO 100 PULSOUT 13, 850 PAUSE 20 NEXT FOR counter = 1 TO 200 PULSOUT 12, 850 PAUSE 20 NEXT END Calificativ FB Studenti: Ilioni Alin, Mardare Adrian, Soruica Sorin, Traila Florin

BothServosThreeSeconds.bs2' Robotics with the Boe-Bot BothServosThreeSeconds.bs2 ' Run both servos in opposite directions for three seconds, then reverse ' the direction of both servos and run another three seconds. ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "Program Running!" counter VAR Byte FOR counter = 1 TO 122 PULSOUT 13, 850 PULSOUT 12, 650 PAUSE 20 NEXT FOR counter = 1 TO 122 PULSOUT 13, 650 PULSOUT 12, 850 PAUSE 20 NEXT END Calificativ FB Studenti: Ilioni Alin, Mardare Adrian, Soruica Sorin, Traila Florin

Sumar: Acest capitol te-a ghidat in conectarea, ajustarea si testarea servomotoarelor Parallax. De asemenea au mai fost introduse mai multe comenzi pbasic. Comanda PAUSE face ca programul sa faca o puaza, DO..LOOP repeta un grup de comenzi , HIGH si LOW fac legatura pinilor cu vdd sau vss. Comanda PULSEOUT a fost introdusa ca o metoda mai precisa de a comunica semnla high sau low folosind ca metoda de verificare un led. Servomotoarele au fost reglate cu ajutorul unei surubelnite operatiune numita centrarea servomotorului. Dupa ce servomotoarele au fost centrate variabilele au fost introduse ca o metoda de a salva variabile. Variabilele pot fi folosite pentru operatii matematice sau pentru a numara cevaa. Buclele FOR..NEXT au fost folosite pentru a controla numarul de impulsuri trimise la un servomotor, ceea ce controleaza cat timp servomotorul se roteste. Intrebari: 1. Cum functioneaza servomotoarele parallax fata de servomotoarele obisnuite?

2. Cat dureaza o milisecunda? Cum o abreviem? 3. Ce comanda pbasic se foloseste pentru ca alte comenzi sa se tot execute? 4. Ce comanda face ca basic stamp sa conecteze un pin la VDD? Dar la VSS? 5. Cum se numesc variabilele care pot fi definite intr-un program pbasic? Ce valori pot lua variabilele astfel definite? 6. Care este cheia pentru controlarea vitezei si directiei unui servomotor? Care este legatura cu diagrama de timp? Cum se leaga de comenzile Pbasic? Care este comanda pentru ajustarea vitezei si directiei servomotorului? Raspunsuri: Servomotorul parallax se poate roti in o directie bine stabilita cu o viteza prestabilita. O milisecunda reprezinta o miime de secunda. Abreviere: 1ms Comanda DO...LOOP HIGH conecteaza pinul la VDD si LOW conecteaza pinul laVSS Variabile: Bit=0-1 Nib=0-15 Byte=0-255 Word=0-65535 sau -32768 la +32767 PULSE WIDTH controleaza viteza si directia. Pe diagrama PULSE WIDTH reprezinta timpul maxim. Tactul poate fi generat in pbasic cu comanda PULSEOUT. Argumentul DURATION al comenzii PULSEOUT ajusteaza viteza si directia.

1. 2. 3. 4. 5.

6.

Exercitii: 1. Scrieti o comanda PAUSE astfel ca basic stamp sa nu faca nimic pentru 10 sec. 2. Modificati bucla FOR...NEXT astfel ca ea sa numere de la 6 la 24 din 3 in 3. De asemenea schimbati declararea variabilelor astfel ca programul sa mearga. Rezolvare exercitii: 1. Pause 1000 2. counter VAR Byte FOR counter = 6 TO 24 STEP 3 DEBUG ? counter PAUSE 500 NEXT

Capitolul 4: Conducerea BOE BOT-ului Boe botul poate fi programat sa faca o multime de manevre. Manevrarea si programarea boe botului va fi invatata capitolul acesta. Activitatea 1: manevre de baza cu boebotul:

' Robotics with the Boe-Bot - BoeBotForwardThreeSeconds.bs2 ' Make the Boe-Bot roll forward for three seconds. ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "Program Running!" counter VAR Word FREQOUT 4, 2000, 3000 ' Signal program start/reset. FOR counter = 1 TO 122 ' Run servos for 3 seconds. PULSOUT 13, 850 PULSOUT 12, 650 PAUSE 20 NEXT END Calificativ FB Studenti: Ilioni Alin, Mardare Adrian, Soruica Sorin, Traila Florin

Activitatea 2: complicarea manevrelor de baza: ' Robotics with the Boe-Bot - BoeBotForwardTenSeconds.bs2 ' Make the Boe-Bot roll forward for ten seconds. ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "Program Running!" counter VAR Word FREQOUT 4, 2000, 3000 ' Signal program start/reset. FOR counter = 1 TO 407 ' Number of pulses run time. PULSOUT 13, 850 ' Left servo full speed ccw.

PULSOUT 12, 650 ' Right servo full speed cw. PAUSE 20 NEXT END Calificativ FB Studenti: Ilioni Alin, Mardare Adrian, Soruica Sorin, Traila Florin Activitatea 3: calcularea distantelor:

' Robotics with the Boe-Bot - ForwardOneSecond.bs2 ' Make the Boe-Bot roll forward for one second. ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "Program Running!" counter VAR Word FREQOUT 4, 2000, 3000 ' Signal program start/reset. FOR counter = 1 TO 41 PULSOUT 13, 850 PULSOUT 12, 650 PAUSE 20 NEXT END Activitatea 4: manevre: accelerarea constanta ' -----[ Title ]-------------------------------------------------------------' Robotics with the Boe-Bot - StartAndStopWithRamping.bs2 ' Ramp up, go forward, ramp down. ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "Program Running!" pulseCount VAR Word ' FOR...NEXT loop counter. ' -----[ Initialization ]---------------------------------------------------FREQOUT 4, 2000, 3000 ' Signal program start/reset.

' -----[ Main Routine ]------------------------------------------------------' Ramp up forward. FOR pulseCount = 1 TO 100 ' Loop ramps up for 100 pulses. PULSOUT 13, 750 + pulseCount ' Pulse = 1.5 ms + pulseCount. PULSOUT 12, 750 - pulseCount ' Pulse = 1.5 ms pulseCount. PAUSE 20 ' Pause for 20 ms. NEXT ' Continue forward for 75 pulses. FOR pulseCount = 1 TO 75 ' Loop sends 75 forward pulses. PULSOUT 13, 850 ' 1.7 ms pulse to left servo. PULSOUT 12, 650 ' 1.3 ms pulse to right servo. PAUSE 20 ' Pause for 20 ms. NEXT ' Ramp down from going forward to a full stop. FOR pulseCount = 100 TO 1 ' Loop ramps down for 100 pulses. PULSOUT 13, 750 + pulseCount ' Pulse = 1.5 ms + pulseCount. PULSOUT 12, 750 - pulseCount ' Pulse = 1.5 ms - pulseCount. PAUSE 20 ' Pause for 20 ms. NEXT END ' Stop until reset. Calificativ FB Studenti: Ilioni Alin, Mardare Adrian, Soruica Sorin, Traila Florin

Activitatea 5: conducerea simplificata cu subrutine: Cu o subrutina: ' Robotics with the Boe-Bot - OneSubroutine.bs2 ' This program demonstrates a simple subroutine call. ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "Before subroutine",CR PAUSE 1000 GOSUB My_Subroutine DEBUG "After subroutine", CR END My_Subroutine: DEBUG "Command in subroutine", CR PAUSE 1000 RETURN Cu 2 subrutine:

' Robotics with the Boe-Bot - TwoSubroutines.bs2 ' This program demonstrates that a subroutine is a reusable block of commands. ' {$STAMP BS2} ' {$PBASIC 2.5} DO GOSUB High_Pitch DEBUG "Back in main", CR PAUSE 1000 GOSUB Low_Pitch DEBUG "Back in main again", CR PAUSE 1000 DEBUG "Repeat...",CR,CR LOOP High_Pitch: DEBUG "High pitch", CR FREQOUT 4, 2000, 3500 RETURN Low_Pitch: DEBUG "Low pitch", CR FREQOUT 4, 2000, 2000 RETURN Calificativ FB Studenti: Ilioni Alin, Mardare Adrian, Soruica Sorin, Traila Florin Activitatea 6: creearea de manevre complexe: Harta memoriei:

' Robotics with the Boe-Bot - EepromNavigation.bs2 ' Navigate using characters stored in EEPROM. ' {$STAMP BS2} ' Stamp directive. ' {$PBASIC 2.5} ' PBASIC directive. DEBUG "Program Running!" ' -----[ Variables ]---------------------------------------------------------pulseCount VAR Word ' Stores number of pulses. address VAR Byte ' Stores EEPROM address. instruction VAR Byte ' Stores EEPROM instruction. ' -----[ EEPROM Data ]-------------------------------------------------------' Address: 0123456789 ' These two commented lines show ' |||||||||| ' EEPROM address of each datum. DATA "FLFFRBLBBQ" ' Navigation instructions. ' -----[ Initialization ]-----------------------------------------------------# ' -----[ Subroutine Right_Turn ]-------------------------------------------Right_Turn: ' right turn subroutine. FOR pulseCount = 1 TO 24 ' Send 24 right rotate pulses. PULSOUT 13, 850 ' 1.7 ms pulse to left servo. PULSOUT 12, 850 ' 1.7 ms pulse to right servo. PAUSE 20 ' Pause for 20 ms. NEXT RETURN ' Return to Main Routine section. Calificativ FB Studenti: Ilioni Alin, Mardare Adrian, Soruica Sorin, Traila Florin Sumar: Acest capitol introduce manevre de baza cu boe botul: inainte inapoi, stanga, dreapta. Tipul manevrei este dat de comanda pulseout. Cat de mult merge robotul este dat de cat de mult tine bucla for....loop. Programarea Boe-Bot sa parcurga o distanta pre-definite poate fi realizat prin msurarea distanei de deplasare intr-o secunda, cu ajutorul unei rigle. folosind acest distan, precum i numrul de impulsuri intr-o secunda din timpul de rulare, se poate calcula numrul de impulsuri necesare pentru a acoperi o distanta dorita. Ramping a fost introdus ca o modalitate de a accelera treptat i a scdea. Se recomanda s utilizai propriile rutine ramping n loc de ncepe brusc sau opri servomotorul prezentat n programele exemplu. Ramping se realizeaz prin luarea variabilei ca argument Counter ntr-o bucl ... for next i adugndu-l sau sczandul din 750 n comanda PULSOUT.

Intrebari: 1. pentru ca boebotul sa mearga inainte in ce directie trebuie sa se roteasca rotile? 2. cand robotul merge la stanga ce trebuie sa faca roata din dreapta? Dar cea din stanga? 3. cum corectezi programul unui robot daca acesta merge usor spre stanga si vrei sa mearga inainte? 4. daca robotul are 11mm/s cate impulsuri trebuie sa-i dai ca el sa mearga 36mm? 5. care este legatura dintre COUNTER (bucla for...loop) si duration(comanda pulseout)? 6. ce se foloseste pentru a salva in memoria eeprom? 7. dar pentru a interoga din eeprom? 8. ce block de comenzi se pot folosi pentru a selecta o variabila prestabilita ? 9. care sunt conditiile diferite in care se poate folosi DO...LOOP? raspunsuri: 1. roata din stanga in sens orar si roata din dreapta in sens antiorar 2. roata dreapta se misca in sens orar si cea din stanga nu se misca 3. se va incetinii roata din dreapta 4. Boe-Bot speed = 11 in/s Boe-Bot distance = 36 in/s pulses = (Boe-Bot distance / Boe-Bot speed) * (40.65 pulses / s) = (36 / 11 ) * (40.65) = 133.04= 133 5. FOR pulseCount = 1 to 100 PULSOUT 13, 750 + pulseCount PULSOUT 12, 750 pulseCount PAUSE 20 NEXT 6.directiva DATA 7. comanda read 8. select...case....endselect 9. until and while Exercitii: 1. face robotul sa mearga inapoi 350 impulsuri 2. sa zicem ca pt 180 grade ne trebuie 48 impulsuri. Cate impulsuri ne trebuie pentru 30, 45, 60 de grade 3. scrieti o rutina care face boebotul sa mearga inainte, apoi sa urce si sa se intoarca si apoi sa mearga iarasi inainte rezolvare:

1. FOR counter = 1 to 350 ' Backward PULSOUT 13, 650 PULSOUT 12, 850 PAUSE 20 NEXT 2. FOR counter = 1 to 8 ' Rotate right 30 degrees PULSOUT 13, 850 PULSOUT 12, 850 PAUSE 20 NEXT FOR counter = 1 to 12 ' Rotate right 45 degrees PULSOUT 13, 850 PULSOUT 12, 850 PAUSE 20 NEXT FOR counter = 1 to 16 ' Rotate right 60 degrees PULSOUT 13, 850 PULSOUT 12, 850 PAUSE 20 NEXT 3. FOR counter = 1 to 100 ' Forward PULSOUT 13, 850 PULSOUT 12, 650 PAUSE 20 NEXT FOR counter = 0 TO 30 ' Ramping pivot turn PULSOUT 13, 750 + counter PULSOUT 12, 750 PAUSE 20 NEXT FOR counter = 30 TO 0 PULSOUT 13, 750 + counter PULSOUT 12, 750 PAUSE 20 NEXT FOR counter = 1 to 100 ' Forward PULSOUT 13, 850 PULSOUT 12, 650 PAUSE 20 NEXT Calificativ FB Studenti: Ilioni Alin, Mardare Adrian, Soruica Sorin, Traila Florin

Capitolul 6: Navigarea cu fotorezistente Lumina are multe aplicaii n robotic i aplicatii industriale. Cteva exemple includ detectare marginea de o rola de material n industria textil, de stabilire a luminii pentru a activa luminile stradale n momente diferite ale anului, atunci cnd se face o fotografie, sau atunci cnd trebuie furnizata ap la o cultur de plante. Fotorezistoare:

Activitatea 1: testarea fotorezistoarelor:

' Robotics with the Boe-Bot - TestPhotoresistorDividers.bs2 ' Display what the I/O pins connected to the photoresistor ' voltage dividers sense. ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "PHOTORESISTOR STATES", CR, "Left Right", CR, "------- --------" DO DEBUG CRSRXY, 0, 3, "P6 = ", BIN1 IN6, " P3 = ", BIN1 IN3 PAUSE 100 LOOP Calificativ FB Studenti: Ilioni Alin, Mardare Adrian, Soruica Sorin, Traila Florin

Activitatea 2: evitarea umbrelor: ' -----[ Title ]-------------------------------------------------------------' Robotics with the Boe-Bot - RoamingWithPhotoresistorDividers.bs2 ' Boe-Bot detects shadows photoresistors voltage divider circuit and turns ' away from them. ' {$STAMP BS2} ' Stamp directive. ' {$PBASIC 2.5} ' PBASIC directive. DEBUG "Program Running!" ' -----[ Variables ]---------------------------------------------------------pulseCount VAR Byte ' FOR...NEXT loop counter. ' -----[ Initialization ]----------------------------------------------------FREQOUT 4, 2000, 3000 ' Start/restart signal. ' -----[ Main Routine ]------------------------------------------------------DO IF (IN6 = 0) AND (IN3 = 0) THEN ' Both photoresistors detects GOSUB Back_Up ' shadow, back up & U-turn GOSUB Turn_Left ' (left twice). GOSUB Turn_Left ELSEIF (IN6 = 0) THEN ' Left photoresistor detects GOSUB Back_Up ' shadow, back up & turn right. GOSUB Turn_Right ELSEIF (IN3 = 0) THEN ' Right photoresistor detects GOSUB Back_Up ' shadow, back up & turn left. GOSUB Turn_Left ELSE ' Neither photoresistor detects GOSUB Forward_Pulse ' shadow, apply a forward pulse. ENDIF LOOP ' -----[ Subroutines ]-------------------------------------------------------Forward_Pulse: ' Send a single forward pulse. PULSOUT 12,650 PULSOUT 13,850 PAUSE 20 RETURN Turn_Left: ' Left turn, about 90-degrees. FOR pulseCount = 0 TO 20 PULSOUT 12, 650 PULSOUT 13, 650 PAUSE 20 NEXT

RETURN Turn_Right: FOR pulseCount = 0 TO 20 ' Right turn, about 90-degrees. PULSOUT 12, 850 PULSOUT 13, 850 PAUSE 20 NEXT RETURN Back_Up: ' Back up. FOR pulseCount = 0 TO 40 PULSOUT 12, 850 PULSOUT 13, 650 PAUSE 20 NEXT RETURN Calificativ FB Studenti: Ilioni Alin, Mardare Adrian, Soruica Sorin, Traila Florin

Activitatea 3: navigarea boebotului dupa umbre: ' Robotics with the Boe-Bot - ShadowGuidedBoeBot.bs2 ' Boe-Bot detects shadows cast by your hand and tries to follow them. ' {$STAMP BS2} ' Stamp directive. ' {$PBASIC 2.5} ' PBASIC directive. DEBUG "Program Running!" FREQOUT 4, 2000, 3000 ' Start/restart signal. DO IF (IN6 = 0) AND (IN3 = 0) THEN ' Both detect shadows, forward. PULSOUT 13, 850 PULSOUT 12, 650 ELSEIF (IN6 = 0) THEN ' Left detects shadow, PULSOUT 13, 750 ' pivot left. PULSOUT 12, 650 ELSEIF (IN3 = 0) THEN ' Right detects shadow, PULSOUT 13, 850 ' pivot right. PULSOUT 12, 750 ELSE PULSOUT 13, 750 ' No shadow, sit still PULSOUT 12, 750 ENDIF PAUSE 20 ' Pause between pulses.

LOOP Calificativ FB Studenti: Ilioni Alin, Mardare Adrian, Soruica Sorin, Traila Florin

Activitatea 4: mai multe informatii de la fotorezistoare: ' Robotics with the Boe-Bot - TestP6Photoresistor.bs2 ' Test Boe-Bot photoresistor circuit connected to P6 and display ' the decay time. ' {$STAMP BS2} ' Stamp directive. ' {$PBASIC 2.5} ' PBASIC directive. timeLeft VAR Word DO HIGH 6 PAUSE 2 RCTIME 6,1,timeLeft DEBUG HOME, "timeLeft = ", DEC5 timeLeft PAUSE 100 LOOP Calificativ FB Studenti: Ilioni Alin, Mardare Adrian, Soruica Sorin, Traila Florin

Activitatea 5: urmarirea lanternei de boebot: ' Robotics with the Boe-Bot - TestBothPhotoresistors.bs2 ' Test Boe-Bot RC photoresistor circuits. ' {$STAMP BS2} ' Stamp directive. ' {$PBASIC 2.5} ' PBASIC directive. timeLeft VAR Word ' Variable declarations. timeRight VAR Word DEBUG "PHOTORESISTOR VALUES", CR, ' Initialization. "timeLeft timeRight", CR, "-------- ---------" DO ' Main routine. HIGH 6 ' Left RC time measurement. PAUSE 3 RCTIME 6,1,timeLeft HIGH 3 ' Right RC time measurement. PAUSE 3

RCTIME 3,1,timeRight DEBUG CRSRXY, 0, 3, ' Display measurements. DEC5 timeLeft, " ", DEC5 timeRight PAUSE 100 LOOP Calificativ FB Studenti: Ilioni Alin, Mardare Adrian, Soruica Sorin, Traila Florin

Activitatea 6: navigarea catre lumina: ' -----[ Title ]-------------------------------------------------------------' Robotics with the Boe-Bot - RoamingTowardTheLight.bs2 ' Boe-Bot roams, and turns away from dark areas in favor of brighter areas. ' {$STAMP BS2} ' Stamp directive. ' {$PBASIC 2.5} ' PBASIC directive. DEBUG "Program Running!" ' -----[ Variables ]---------------------------------------------------------' Declare variables for storing measured RC times of the ' left & right photoresistors. timeLeft VAR Word timeRight VAR Word average VAR Word difference VAR Word ' -----[ Initialization ]----------------------------------------------------FREQOUT 4, 2000, 3000 ' -----[ Main Routine ]------------------------------------------------------DO GOSUB Test_Photoresistors ' For mismatched photoresistors, use Appendix F, uncomment and use next line. ' timeLeft = (timeLeft */ 351) + 7 ' Replace 351 and 7 with your own values. GOSUB Average_And_Difference GOSUB Navigate LOOP ' -----[ Subroutine - Test_Photoresistors ]----------------------------------Test_Photoresistors: HIGH 6 ' Left RC time measurement. PAUSE 3 RCTIME 6,1,timeLeft HIGH 3 ' Right RC time measurement.

PAUSE 3 RCTIME 3,1,timeRight RETURN ' -----[ Subroutine - Average_And_Difference ]-------------------------------Average_And_Difference: average = timeRight + timeLeft / 2 difference = average / 6 RETURN ' -----[ Subroutine - Navigate ]---------------------------------------------Navigate: ' Shadow significantly stronger on left detector, turn right. IF (timeLeft > timeRight + difference) THEN PULSOUT 13, 850 PULSOUT 12, 850 ' Shadow significantly stronger on right detector, turn left. ELSEIF (timeRight > timeLeft + difference) THEN PULSOUT 13, 650 PULSOUT 12, 650 ' Shadows in same neighborhood of intensity on both detectors. ELSE PULSOUT 13, 850 PULSOUT 12, 650 ENDIF PAUSE 10 RETURN Calificativ FB Studenti: Ilioni Alin, Mardare Adrian, Soruica Sorin, Traila Florin

Rezumat: Acest capitol ne invata sa facem diferenta dintre diferite intensitati de lumina. O pereche de fotorezistori sau folosit pentru a masura diferente de lumina vizibila. Cand valoarea fotorezistoarelor a scazut sub 1.4V inputul la circuit este 0 si peste 3.8V rezultatul este 1. Cu toate acestea, un mod mult mai versatil de detectare a luminii nivele, cu BASIC Stamp este de a utiliza photoresistor CdS ntr-un circuit RC, pentru a incarca consensatorul si apoi a masura timpul de descarcare. Acest lucru este usor de facut in basic stamp cu comanda RCTIME. De asemenea au fost introduse constante in programele PBASIC.

Intrebari: 1. 2. 3. 4. 5. 6. 7. 8. cum raspunde fotorezistenta la lumina? un pin are vreun efect daca este setat pe input? ce reprezinta pragul de voltaj? referinduva la fig. 6-4 ce face ca Vo sa creasca sau sa scada sub un anumit prag intr-un program pbasic. cum difera ShadowGuidedBoeBot.bs2 de RoamingWithPhotoresistorDividers.bs2? ce reprezinta o declarare a constantelor? Ce face? Cum pot fi folosite? cum sunt evaluate expresiile matematice? cum se calculeaza media in PBASIC? Raspunsuri: rezistenta este mica la lumina mare pinul asculta comanda fara sa faca vreo schimbare pragul reprezinta valoarea peste care este 1 logic si sub care este 0 logic Vo se schimba deoarece se schimba valoarea rezistentei. verifica senzorul intre fiecare puls. declararea constantelor face ca basic stamp sa le foloseasca ca si constante. se evalueaza de la stanga la dreapta exercitii: 1. Calculate Vo for Figure 6-4 on page 197 if R is 10 k. Repeat for R = 30 k. 2. If Vo in Figure 6-4 on page 197 is 1.4 V, whats the value of R? Repeat for Vo = 1 V and Vo = 3 V. 3. Assume you have three variable values: firstValue, secondValue, and thirdValue. Write a command that takes the average of these three values in a variable named myAverage. Write a command that stores 7/8 of the average value in a variable named myScaledAverage. Write the variable declarations needed to make your command able to run in a program, first with myAverage and myScaledAverage as separate variables, then with one of these variable names aliased as the other. E1: a) R = 10 kOhm Vo = 5V * (2000 / (2000 + R)) = 5 * (2000 / (2000 + 10000) = 5 * (2000 / (12000) = 5 * ( 2 / 12 ) =5*(1/6)

1. 2. 3. 4. 5. 6. 7.

= 5 * 0.17 = 0.83 Volts If R = 10 kOhm, Vo = 0.83 V b) R = 30 kOhm Vo = 5V * (2000 / (2000 + R)) = 5 * (2000 / (2000 + 30000) = 5 * (2000 / (32000) = 5 * ( 2 / 32 ) = 5 8 ( 1 / 16 ) = 5 * 0.06 = 0.31 Volts If R = 30 kOhm, Vo = 0.31 V E2: a) Vo = 1.4 V R = (5 * (2000/Vo)) 2000 = (5 * (2000/1.4)) 2000 = (5 * 1428.57) 2000 = 7142.86 2000 = 5142.86 = 5143 Ohm When Vo = 1.4V, R = 5143 b) Vo = 1.0 V R = (5 * (2000/1)) 2000 = (5 * 2000) 2000 = (10000) 2000 = 8000 = 8 kOhm When Vo = 1.4V, R = 8 k E3: myScaledAvereage: myAverage = firstValue + secondValue + thirdValue / 3 myScaledAverage = myAverage * 7 / 8 Declarations as separate variables: myAverage VAR Word myScaledAverage VAR Word Declarations using aliasing: myAverage VAR Word myScaledAverage VAR myAverage

Capitolul 7: Navigarea cu faruri infrarou In acest capitol am studiat navigarea robotilor Boe-Bot cu ajutorul LED-urilor cu infrarosu, montate pe roboti.Cu ajutorul acestor LED-uri robotii vor putea detecta obstacolele, vor lua decizii i vor operea servomotoarele avnd la baz acest senzor de intrare. ACTIVITATEA 1: Construirea si testarea perechii de senzori IR n aceast activitate se va construi i se va testa perechea emitor / detector in infrarou ' Robotics with the Boe-Bot - TestLeftIrPair.bs2 ' Test IR object detection circuits, IR LED connected to P8 and detector ' connected to P9. ' {$STAMP BS2} ' {$PBASIC 2.5} irDetectLeft VAR Bit DO FREQOUT 8, 1, 38500 irDetectLeft = IN9 DEBUG HOME, "irDetectLeft = ", BIN1 irDetectLeft PAUSE 100 LOOP Calificativ FB Studenti: Ilioni Alin, Mardare Adrian, Soruica Sorin, Traila Florin

ACTIVITATEA 2: Testarea pe teren pentru detectarea de obiecte si interferenta infrarosu n aceast activitate, se vor construi i testa LED-uri indicatoare care v vor spune dac un obiect este detectat fr ajutorul terminalului Debug. ' Robotics with the Boe-Bot - TestIrPairsAndIndicators.bs2 ' Test IR object detection circuits. ' {$STAMP BS2} ' Stamp directive. ' {$PBASIC 2.5} ' PBASIC directive. ' -----[ Variables ]---------------------------------------------------------irDetectLeft VAR Bit irDetectRight VAR Bit

' -----[ Initialization ]----------------------------------------------------DEBUG "Testing piezospeaker..." FREQOUT 4, 2000, 3000 DEBUG CLS, "IR DETECTORS", CR, "Left Right", CR, "----- -----" ' -----[ Main Routine ]------------------------------------------------------DO FREQOUT 8, 1, 38500 irDetectLeft = IN9 FREQOUT 2, 1, 38500 irDetectRight = IN0 IF (irDetectLeft = 0) THEN HIGH 10 ELSE LOW 10 ENDIF IF (irDetectRight = 0) THEN HIGH 1 ELSE ENDIF DEBUG CRSRXY, 2, 3, BIN1 irDetectLeft, CRSRXY, 9, 3, BIN1 irDetectRight PAUSE 100 LOOP Robotics with the Boe-Bot IrInterferenceSniffer.bs2 ' Test fluorescent lights, infrared remotes, and other sources ' of 38.5 kHz IR interference. ' {$STAMP BS2} ' Stamp directive. ' {$PBASIC 2.5} ' PBASIC directive. counter VAR Nib DEBUG "IR interference not detected, yet...", CR DO IF (IN0 = 0) OR (IN9 = 0) THEN DEBUG "IR Interference detected!!!", CR FOR counter = 1 TO 5 HIGH 1 HIGH 10 FREQOUT 4, 50, 4000 LOW 1 LOW 10

PAUSE 20 NEXT ENDIF LOOP Calificativ FB Studenti: Ilioni Alin, Mardare Adrian, Soruica Sorin, Traila Florin

ACTIVITATEA 3: Ajustarea razei de detectare in infrarosu Crescand luminozitatea farurilor Boe-Bot-ului, putei crete, de asemenea, gama de detectie. Prin curent electrict mai puin, o rezisten mai mic permite un debit mai crescut de curent prin intermediul unui LED. In aceast activitate, vei examina efectul de valorilor de rezistene diferite, att LED-uri rosu si infrarosu. ' Robotics with the Boe-Bot - P1LedHigh.bs2 ' Set P1 high to test for LED brightness testing with each of ' these resistor values in turn: 220 ohm , 470 ohm, 1 k ohm. ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "Program Running!" HIGH 1 STOP Calificativ FB Studenti: Ilioni Alin, Mardare Adrian, Soruica Sorin, Traila Florin

ACTIVITATEA 4: Detectarea si evitarea obiectelor n aceast activitate, RoamingWithWhiskers.bs2 este modificat astfel nct s funcioneaze cu detectoare IR. Atunci cnd nu este detectat nici un obiect,semnalul de ieire este HIGH, atunci cnd un obiect este detectat, semnalul de ieire este LOW. ' Robotics with the Boe-Bot - RoamingWithIr.bs2 ' Adapt RoamingWithWhiskers.bs2 for use with IR pairs. ' {$STAMP BS2} ' Stamp directive. ' {$PBASIC 2.5} ' PBASIC directive. DEBUG "Program Running!" ' -----[ Variables ]----------------------------------------------------------

irDetectLeft VAR Bit irDetectRight VAR Bit pulseCount VAR Byte ' -----[ Initialization ]----------------------------------------------------FREQOUT 4, 2000, 3000 ' Signal program start/reset. ' -----[ Main Routine ]------------------------------------------------------DO FREQOUT 8, 1, 38500 ' Store IR detection values in irDetectLeft = IN9 ' bit variables. FREQOUT 2, 1, 38500 irDetectRight = IN0 IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN GOSUB Back_Up ' Both IR pairs detect obstacle GOSUB Turn_Left ' Back up & U-turn (left twice) GOSUB Turn_Left ELSEIF (irDetectLeft = 0) THEN ' Left IR pair detects GOSUB Back_Up ' Back up & turn right GOSUB Turn_Right ELSEIF (irDetectRight = 0) THEN ' Right IR pair detects GOSUB Back_Up ' Back up & turn left GOSUB Turn_Left ELSE ' Both IR pairs 1, no detects GOSUB Forward_Pulse ' Apply a forward pulse ENDIF ' and check again LOOP ' -----[ Subroutines ]-------------------------------------------------------Forward_Pulse: ' Send a single forward pulse. PULSOUT 13,850 PULSOUT 12,650 PAUSE 20 RETURN Turn_Left: ' Left turn, about 90-degrees. FOR pulseCount = 0 TO 20 PULSOUT 13, 650 PULSOUT 12, 650 PAUSE 20 NEXT RETURN Turn_Right: FOR pulseCount = 0 TO 20 ' Right turn, about 90-degrees. PULSOUT 13, 850 PULSOUT 12, 850 PAUSE 20

NEXT RETURN Back_Up: ' Back up. FOR pulseCount = 0 TO 40 PULSOUT 13, 650 PULSOUT 12, 850 PAUSE 20 NEXT RETURN Calificativ FB Studenti: Ilioni Alin, Mardare Adrian, Soruica Sorin, Traila Florin

ACTIVITATEA 5: Navigarea IR de inalt nivel Avei posibilitatea s mbunti foarte mult performana Boe-Bot-ului de orientare spatiala prin verificarea de obstacole nainte de livrarea fiecarui set de impulsuri la servomotoare. Programul poate folosi intrarile senzorilor pentru a selecta cele mai bune manevre pentru fiecare moment de navigare. ' Robotics with the Boe-Bot - FastIrRoaming.bs2 ' Higher performance IR object detection assisted navigation ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "Program Running!" irDetectLeft VAR Bit ' Variable Declarations irDetectRight VAR Bit pulseLeft VAR Word pulseRight VAR Word FREQOUT 4, 2000, 3000 ' Signal program start/reset. DO ' Main Routine FREQOUT 8, 1, 38500 ' Check IR Detectors irDetectLeft = IN9 FREQOUT 2, 1, 38500 irDetectRight = IN0 ' Decide how to navigate. IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN pulseLeft = 650

pulseRight = 850 ELSEIF (irDetectLeft = 0) THEN pulseLeft = 850 pulseRight = 850 ELSEIF (irDetectRight = 0) THEN pulseLeft = 650 pulseRight = 650 ELSE pulseLeft = 850 pulseRight = 650 ENDIF PULSOUT 13,pulseLeft ' Apply the pulse. PULSOUT 12,pulseRight PAUSE 15 LOOP ' Repeat main routine Calificativ FB Studenti: Ilioni Alin, Mardare Adrian, Soruica Sorin, Traila Florin

ACTIVITATEA 6: Detectorul DROP-OFF Programul ar trebui s fac robotul sa mearga n continuare nainte, atta timp ct ambele detectoare IR poate "vedea" suprafaa mesei ' Robotics with the Boe-Bot - AvoidTableEdge.bs2 ' IR detects object edge and navigates to avoid drop-off. ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "Program Running!" irDetectLeft VAR Bit ' Variable declarations. irDetectRight VAR Bit pulseLeft VAR Word pulseRight VAR Word loopCount VAR Byte pulseCount VAR Byte FREQOUT 4, 2000, 3000 ' Signal program start/reset. DO ' Main Routine.

FREQOUT 8, 1, 38500 ' Check IR detectors. irDetectLeft = IN9 FREQOUT 2, 1, 38500 irDetectRight = IN0 ' Decide navigation. IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN pulseCount = 1 ' Both detected, pulseLeft = 850 ' one pulse forward. pulseRight = 650 ELSEIF (irDetectRight = 1) THEN ' Right not detected, pulseCount = 10 ' 10 pulses left. pulseLeft = 650 pulseRight = 650 ELSEIF (irDetectLeft = 1) THEN ' Left not detected, pulseCount = 10 ' 10 pulses right. pulseLeft = 850 pulseRight = 850 ELSE ' Neither detected, pulseCount = 15 ' back up and try again. pulseLeft = 650 pulseRight = 850 ENDIF FOR loopCount = 1 TO pulseCount ' Send pulseCount pulses PULSOUT 13,pulseLeft PULSOUT 12,pulseRight PAUSE 20 NEXT LOOP Calificativ FB Studenti: Ilioni Alin, Mardare Adrian, Soruica Sorin, Traila Florin

REZUMAT Un program indicator de detectare n infrarou a fost introdus pentru testarea de la distan LED-urile IR / perechi detectoare. Un alt program de detectare a interferentei infrarou a fost de asemenea, introdus pentru a ajuta la detectarea a interferenelor care pot fi generate de lumina fluorescent. Un program care verific detectoare IR ntre fiecare impuls spre servodirecie a fost introdus pentru a demonstra o performan mai ridicate de orientare, fr ca robotul sa se

ciocnesca cu obiecte. Acest program a fost apoi modificat pentru a evita marginea unei zone delimitate de o band electrica. ntrebri: Care este frecvena de armonici trimise de FREQOUT 2, 1, 38500? Care este valoarea frecvenei fundamentale de comand trimisa? Ct timp sunt aceste semnale trimise? La ce pin I / O trebuie s fie conectat circuitul LED-uri IR n scopul de a difuza acest semnal? Ce comanda trebuie s urmeze imediat comanda FREQOUT, n scopul de a a determina cu exactitate dac un obiect a fost sau nu detectat? Ce nseamn n cazul n care detectorul IR trimite un semnal slab? Ce nseamn aceasta n cazul n care detectorul transmite un semnal inalt? Ce se ntmpl dac se modific valoarea unui rezistor n serie cu un LED rou? Ce se ntmpl dac se modific valoarea unui rezistor n serie cu o conexiune prin LED-uri infrarou? E1: Modific o linie de cod n IrInterferenceSniffer.bs2, astfel nct acesta monitorizeaz numai una dintre perechile deLED-uri IR E2: Explicai funcia de impuls Count n Evitai Edge.bs2 tabelul. Care este legatura cu la rspunsul dumneavoastr la Exerciiul 3? Proiecte P1: Proiectati o aplicatie de Boe-Bot, care se afl n repaus pn cnd miscati manai in fata de robotului,iar apoi ncepe miscarea P2: Proiectati o aplicatie de Boe-Bot, prin care se rotete ncet n loc pn cnd se detecteaz un obiect. De ndat ce detecteaz un obiect, il fixeaza i-l urmarestet. Acesta este un comportament SumoBot clasic. P3: Proiectati o aplicatie de Boe-Bot, care patruleaza, dar n cazul n care detecteaz interferene infrarou, aceasta sun alarma pentru scurt timp, apoi continu n roamingul. Aceast alarm trebuie s fie diferite de alarma bateriei. Raspunsuri

1: 38.5 kHz este frecvena de armonic. frecvena fundamental = 65536 38500 = 27036 Hz. Semnalele sunt trimise pentru o milisecunda, iar LED-ul IR trebuie s fi conectat la I / O Pin 2. 2: Comanda care stocheaz semnalul de ieire al detectorului intr-o variabila. De exemplu, irDetectLeft = IN9. 3: Un semnal slab nseamn IR la 38.5 kHz a fost detectat, astfel, un obiect a fost detectat. Un semnal ridicat nseamn ca IR la 38.5kHz nu a fost detectat, astfel, nici un obiect nu a fost detectat. 4: Electric vorbind, att pentru LED-uri rosii cat si infrarosu, o rezisten mai mica va cauza LED-ul sa straluceasca mai tare. n termeni de rezultate, LED-uri IR mai luminoase fac posibil detectarea obiectelor care sunt mai departe. E1: Schimbam IF...Then: IF (IN0 = 0) THEN Va monitoriza numai senzorul drept E2: Variabila pulseCount permite Boe-Bot-ului s aib distan reglabil de n funcie de situaie.

P1: ' -----[ Title ]------------------------------------------------------' Robotics with the Boe-Bot - MotionActivatedBoeBot.bs2 ' Boe-Bot starts roaming when hand is waved in front of IR detectors. ' {$STAMP BS2} ' {$PBASIC 2.5} ' -----[ Variables ]--------------------------------------------------irDetectLeft VAR Bit ' Variable Declarations irDetectRight VAR Bit pulseLeft VAR Word pulseRight VAR Word ' -----[ Initialization ]----------------------------------------------

DEBUG "Program Running!" FREQOUT 4, 2000, 3000 ' Signal program start/reset. ' -----[ Main Routine ]-----------------------------------------------Main: ' Loop until something is detected DO GOSUB Check_IRs LOOP UNTIL (irDetectLeft = 0) OR (irDetectRight = 0) ' Now start roaming -- this code from FastIrRoaming.bs2 DO IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN pulseLeft = 650 ' Both detect pulseRight = 850 ' Back up ELSEIF (irDetectLeft = 0) THEN ' Left detect pulseLeft = 850 ' Turn right pulseRight = 850 ELSEIF (irDetectRight = 0) THEN ' Right detect pulseLeft = 650 ' Turn left pulseRight = 650 ELSE ' Nothing detected pulseLeft = 850 ' Go forward pulseRight = 650 ENDIF PULSOUT 13, pulseLeft ' Apply the pulse. PULSOUT 12, pulseRight PAUSE 15 GOSUB Check_IRs ' Check IRs again LOOP ' -----[ Subroutines ] -----------------------------------------------Check_IRs: FREQOUT 8, 1, 38500 ' Check IR Detectors irDetectLeft = IN9 FREQOUT 2, 1, 38500 IrDetectRight = IN0 RETURN Calificativ FB Studenti: Ilioni Alin, Mardare Adrian, Soruica Sorin, Traila Florin

P2:

' Robotics with the Boe-Bot - SumoBoeBot.bs2 ' Search for object, lock onto it and push it. ' {$STAMP BS2} ' {$PBASIC 2.5} irDetectLeft VAR Bit ' Left IR reading irDetectRight VAR Bit ' Right IR reading pulseLeft VAR Word ' pulse values for servos pulseRight VAR Word ' -----[ Initialization ]---------------------------------------------DEBUG "Program Running!" FREQOUT 4, 2000, 3000 ' Signal start/reset. ' -----[ Main Routine ]-----------------------------------------------Main: ' Spin around slowly until an object is spotted DO PULSOUT 13, 790 ' Rotate slowly PULSOUT 12, 790 PAUSE 15 ' 5 ms for detectors GOSUB Check_IRs ' While looking for object LOOP UNTIL (irDetectLeft = 0) OR (irDetectRight = 0) ' Now figure out exactly where the object is and go toward it DO ' Object in both detectors -- go forward IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN pulseLeft = 850 ' Forward pulseRight = 650 ' Object on left - go left ELSEIF (irDetectLeft = 0) THEN pulseLeft = 650 ' Left toward object pulseRight = 650 ' Object on right - go right ELSEIF (irDetectRight = 0) THEN pulseLeft = 850 ' Right toward object pulseRight = 850 ' No object -- go forward anyway, because the detectors will ELSE ' momentarily show pulseLeft = 850 ' "no object" as the pulseRight = 650 ' Boe-Bot is adjusting ENDIF ' its position. PULSOUT 13,pulseLeft ' Apply the pulse. PULSOUT 12,pulseRight PAUSE 15 ' 5 ms for detectors ' Check IRs again in case object is moving

GOSUB Check_IRs LOOP ' -----[ Subroutines ] -----------------------------------------------Check_IRs: FREQOUT 8, 1, 38500 ' Check IR Detectors irDetectLeft = IN9 FREQOUT 2, 1, 38500 IrDetectRight = IN0 RETURN P3: ' -----[ Title ]------------------------------------------------------' Robotics with the Boe-Bot - RoamAndSniffBoeBot.bs2 ' Boe-Bot roams around and sounds alarm when IR detected. ' {$STAMP BS2} ' {$PBASIC 2.5} ' -----[ Variables ]--------------------------------------------------irDetectLeft VAR Bit ' Left IR sensor reading irDetectRight VAR Bit ' Right IR sensor reading pulseLeft VAR Word ' Pulses sent to servos pulseRight VAR Word counter VAR Nib ' Loop counter ' -----[ Initialization ]---------------------------------------------DEBUG "Program Running!" FREQOUT 4, 2000, 3000 ' Signal program start/reset. ' -----[ Main Routine ]-----------------------------------------------Main: DO GOSUB Roam GOSUB Sniff LOOP ' -----[ Subroutines ] -----------------------------------------------Sniff: ' From IrInterferenceSniffer.bs2 IF (IN0 = 0) OR (IN9 = 0) THEN FOR counter = 1 TO 5 ' Beep 5 times HIGH 1 ' and flash LEDs HIGH 10 FREQOUT 4, 50, 4000 LOW 1 LOW 10 PAUSE 20

NEXT ENDIF RETURN Roam: ' From FastIrRoaming.bs2 FREQOUT 8, 1, 38500 ' Check IR Detectors irDetectLeft = IN9 FREQOUT 2, 1, 38500 irDetectRight = IN0 ' Decide how to navigate. IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN pulseLeft = 650 pulseRight = 850 ELSEIF (irDetectLeft = 0) THEN pulseLeft = 850 pulseRight = 850 ELSEIF (irDetectRight = 0) THEN pulseLeft = 650 pulseRight = 650 ELSE pulseLeft = 850 pulseRight = 650 ENDIF PULSOUT 13,pulseLeft ' Apply the pulse. PULSOUT 12,pulseRight PAUSE 15 RETURN Calificativ FB Studenti: Ilioni Alin, Mardare Adrian, Soruica Sorin, Traila Florin

S-ar putea să vă placă și