var VAvant = 100 #Variable vitesse avant var VArriere = -100 #Variable vitesse arrière var Vvirage = 10 #Variable vitesse de virage var direction=0 #Variable avant (1) ou arrière (2) var Vplus_moins=0 #Variable de vitesse plus ou moins call sound.system(-1) #couper les sons #call leds.top(0,0,0) #gestion des diodes (éteindre toutes les diodes) #call leds.bottom.left(0,0,0) #call leds.bottom.right(0,0,0) #call leds.circle(0,0,0,0,0,0,0,0) #call leds.prox.h(0,0,0,0,0,0,0,0) #call leds.prox.v(0,0) #call leds.rc(0) call leds.sound(1) call leds.temperature(0,0) #call leds.top(0,0,0) call leds.rc(0) timer.period[0] = 1 #Timer numéro 1 timer.period[1] = 1 #Timer numéro 2 #_______________________________________________routines pour les déplacements du robot sub Avant direction = 1 #Initialisation de la varaiable direction avant Vplus_moins = 0 #Initialisation de la variable vitesse plus ou moins rc5.command =80 #Touche de télécommande (avant) motor.left.target = VAvant #moteur gauche vitesse selon variable motor.right.target = VAvant #moteur droit vitesse selon variable call leds.circle(32,0,0,0,0,0,0,0) #Allumage de la led avant sub Arrière direction = 2 #Initialisation de la varaiable direction arrière Vplus_moins = 0 #Initialisation de la variable vitesse plus ou moins rc5.command =81 #Touche de télécommande (avant) motor.left.target=VArriere #Moteur gauche motor.right.target=VArriere #Moteur droit call leds.circle(0,0,0,0,32,0,0,0) #Allumage de la led arrière sub Gauche motor.left.target=VArriere #Moteur gauche motor.right.target=VAvant #Moteur droit call leds.circle(0,0,0,0,0,0,32,0) #Allumage de la led gauche sub Droit motor.left.target=VAvant #Moteur gauche motor.right.target=VArriere #Moteur droit call leds.circle(0,0,32,0,0,0,0,0) #Allumage de la led droite sub Stop direction = 0 #Initialisation de la varaiable direction Vplus_moins = 0 #Initialisation de la variable vitesse plus ou moins VArriere = -100 #Initialisation de la varaiable vitesse VAvant = 100 #Initialisation de la varaiable vitesse motor.left.target = 0 #Moteur gauche motor.right.target = 0 #Moteur call leds.circle(0,0,0,0,0,0,0,0) #Eteindre les leds #_______________________________________________boucle pour virage onevent timer1 #Evenement timer numéro 1 #_______________________________________________boucle pour virage gauche avant if rc5.command == 4 and direction ==1 then #Condition pour le virage avant timer.period[1] = timer.period[1]+1 #Temps pour les pulsions motor.left.target = 0 #Vitesse moteur gauche call leds.circle(0,0,0,0,0,0,32,0) #Allumage de la led gauche end if timer.period[1] >=20 then timer.period[1] = 1 callsub Avant end #_______________________________________________boucle pour virage droit avant if rc5.command == 6 and direction ==1 then #Condition pour le virage timer.period[1] = timer.period[1]+1 #Temps pour les pulsions motor.right.target = 0 #Vitesse moteur droit call leds.circle(0,0,32,0,0,0,0,0) #Allumage de la led droite end if timer.period[1] >=20 then timer.period[1] = 1 callsub Avant end #_______________________________________________boucle pour virage gauche arrière if rc5.command == 4 and direction ==2 then #Condition pour le virage timer.period[1] = timer.period[1]+1 #Temps pour les pulsions motor.left.target = 0 #Vitesse moteur gauche call leds.circle(0,0,0,0,0,0,32,0) #Allumage de la led gauche end if timer.period[1] >=20 then timer.period[1] = 1 callsub Arrière end #_______________________________________________boucle pour virage droit arrière if rc5.command == 6 and direction ==2 then #Condition pour le virage timer.period[1] = timer.period[1]+1 #Temps pour les pulsions motor.right.target = 0 #Vitesse moteur gauche call leds.circle(0,0,32,0,0,0,0,0) #Allumage de la led droite end if timer.period[1] >=20 then #Compteur timer.period[1] = 1 callsub Arrière end #_______________________________________________boucle pour la vitesse avant onevent timer0 #Evenement timer numéro 2 if rc5.command == 32 and direction ==1 then #Condition pour augmenter la vitesse avant while Vplus_moins == 1 do VAvant = VAvant + Vvirage callsub Avant end end if rc5.command == 33 and direction == 1 then #Condition pour diminuer la vitesse avant while Vplus_moins == 2 do VAvant = VAvant - Vvirage callsub Avant end end #_______________________________________________boucle pour la vitesse arrière if rc5.command == 32 and direction ==2 then #Condition pour augmenter la vitesse arrière while Vplus_moins == 1 do VArriere = VArriere - Vvirage callsub Arrière end end if rc5.command == 33 and direction == 2 then #Condition pour diminuer la vitesse arrière while Vplus_moins == 2 do VArriere = VArriere + Vvirage callsub Arrière end end #_______________________________________________commande du robot par les touches de la télécommande (même routine) onevent rc5 if rc5.command == 80 then callsub Avant elseif rc5.command == 4 then elseif rc5.command==81 then callsub Arrière elseif rc5.command==8 then elseif rc5.command==85 then callsub Gauche elseif rc5.command==4 then elseif rc5.command==86 then callsub Droit elseif rc5.command==6 then elseif rc5.command==33 then Vplus_moins = 2 elseif rc5.command==32 then Vplus_moins = 1 elseif rc5.command==87 then callsub Stop elseif rc5.command==5 then callsub Stop elseif rc5.command==12 then call _poweroff() elseif rc5.command==15 then call sound.system(1) else end #______________________________________________Gestion du sons pour le dépassement de vitesse moteur (500) if motor.right.target >499 or motor.left.target >499 then call sound.system(1) end if motor.right.target < -499 or motor.left.target < -499 then call sound.system(1) end