Voici notre programme mi-commenté

 

 ' Robot F1 testprog

 

#include           "startrf1.bas"

 

'           byte stepleft, stepright

'           byte code, newcode     ' roue codeuse

 

            byte irobstacle

            int tictac                       ' timer en ms

            int ticks, t10

            byte readir

            byte irl, irr                    ' valeurs des irl, irm

            byte oldirl, oldirr

            int silentir

        byte t2,t,mg,md,ig,id,i,ir

 

            OPTIONS.7 = 1                     ' CAN on

            PACTL.1 = 0              ' vitesse du timer

            PACTL.0 = 0

            TMSK2.6 = 1             ' declencher le timer

            DDRG=$5F

            PORTG=$50              ' -/-

            irobstacle = 10

            print "#0 BASE G6 URZA  "

            delai(2500)

 

             Boucle principale

            do

            mg=0         ‘ initialisation de l’entrée du relais gauche (mise a zéro)       

            md=0         ‘ initialisation de l’entrée du relais droit (mise a zéro)

            ig=0           ‘initialisation de la sortie infra rouge gauche (mise a zéro)

            id=0           ‘initialisation de la sortie infra rouge droit (mise a zéro)

          readirs()       ‘lecture sur les infra rouges

            print "#2 go go go"           ‘l’écran lcd affiche “go go go “

            do while PORTE.1=1 and PORTE.3=1 and irl<15 and irr<15   ‘ si la sortie du capteur gauche et droit sont activées et si la distance entre l’obstacle et les infra rouges sont inférieurs a 15 alors 

        for i= 1 to 10     ‘ alternance le courant de la commande du moteur et le test des 4 capteurs

              gosub avance     ‘le robot avance

            next i

            readirs()

            loop

        if PORTE.1=0 then               

            mg=1

            end if                                                         test de determination du capteur activé

            if PORTE.3=0  then

            md=1

            end if

            if irl>15 then

            ig=1                                                              

            end if                                                            test de determination du capteur activé

            if irr>15 then

            id=1

            end if

            if mg=1 or ig=1 then

            print"#2 A droite .Vite "                ‘l’écran lcd affiche « a droite vite »

            for i=1 to 100

            GOSUB recule                               ‘ le robot recule

            next i

            for i=1 to 80

            gosub droite                                    ‘ le robot tourne a droite

            next i

 

            end if

            if md=1 or id=1 then

            print "#2 A gauche. Vite "             ‘l’écran lcd affiche a gauche vite »

            for i=1 to 100

        GOSUB recule                                  ‘le robot recule

        next i

            for i=1 to 80

            gosub gauche                                 ‘le robot tourne a gauche

            next i

            end if

            loop

 

 

'******************************* SUB ROUTINES DE COMMANDES MOTEUR *************************************

 

recule:

              PORTA.4=1             ' ROUE GAUCHE

              PORTA.5=1             ' ROUE DROITE

          delai2(2)                        ' ROUE GAUCHE (RECULE)

          PORTA.4=0                 ' DESACTIVE LA ROUE GAUCHE

          delai2(10)                      ' CONTINUE AVEC LA ROUE DROITE (AVANCE)

              PORTA.5=0             ' DESACTIVE LA ROUE DROITE

          delai2(80)                      ' WAIT

          return

 

avance:

              PORTA.4=1             ' ROUE GAUCHE

              PORTA.5=1             ' ROUE DROITE

          delai2(2)                        ' ROUE DROITE (AVANCE) [temps plus court]

          PORTA.5=0                 ' DESACTIVE LA ROUE DROITE

          delai2(10)                      ' CONTINUE AVEC LA ROUE GAUCHE (RECULE) [temps plus long]

              PORTA.4=0             ' DESACTIVE LA ROUE GAUCHE

          delai2(80)                      ' WAIT

          return

 

droite:

              PORTA.2=1

              PORTA.4=1             ' ROUE GAUCHE

              PORTA.5=1             ' ROUE DROITE

          delai2(2)                        ' ROUE GAUCHE (AVANCE) ROUE DROITE (RECULE)

          PORTA.4=0                 ' DESACTIVE LA ROUE GAUCHE

              PORTA.5=0             ' DESACTIVE LA ROUE DROITE

          delai2(80)                      ' WAIT

              PORTA.2=0

          return

 

gauche:

              PORTA.1=1

              PORTA.4=1             ' ROUE GAUCHE

              PORTA.5=1             ' ROUE DROITE

          delai2(15)                      ' ROUE GAUCHE (RECULE) ROUE DROITE (AVANCE)

          PORTA.4=0                 ' DESACTIVE LA ROUE GAUCHE

              PORTA.5=0             ' DESACTIVE LA ROUE DROITE

          delai2(80)                      ' WAIT

              PORTA.1=0

          return


 

  © By Gilles