Aller au contenu


Photo
- - - - -

votre avis sur le chassis et le controleur


61 réponses à ce sujet

#21 galactus

galactus

    Habitué

  • Membres
  • PipPip
  • 157 messages

Posté 23 février 2010 - 06:55

essaye ça,mais je ne te promet rien,je suis une patate en dev :ph34r:

if (valG==HIGH){
                if (valC==HIGH){
                                if(valD==HIGH){advance(50,50);}else{advance(0,0);/*vald==LOW dans ce cas*/}
                               }else{turn_R(0,0);/*valC==LOW dans ce cas*/}
                 }else(advance(0,0)/*valG==LOW dans ce cas*/;


#22 TIMAL

TIMAL

    Membre

  • Membres
  • 53 messages
  • Gender:Male

Posté 23 février 2010 - 09:11

Merci galactus, mais c'est toujours pareil.
quand j'appuie sur A les moteurs tournent sans prendre en compte la valeur des capteurs :wacko:

void loop(){
while (Serial.available()) {
switch (Serial.read())
{
case 'Z'://stop
advance (0,0);
break;

case 'A':
{
valG = digitalRead(inputPinG);
valC = digitalRead(inputPinC);
valD = digitalRead(inputPinD);
if (valG==HIGH){
if (valC==HIGH){
if (valD==HIGH){advance(50,50);}
else{advance(0,0);}
}else{turn_R(0,0);}
}else{advance(0,0);}
}
}
}
}

comprend pô!
Image IPB

#23 galactus

galactus

    Habitué

  • Membres
  • PipPip
  • 157 messages

Posté 23 février 2010 - 10:47

tu as essayé juste avec un test
genre
case 'A'
advance(50,50);
break;

sinon,a la fin de ton code ,place un
default:
advance(0,0);

comme ca il s'arrete a n'importe quelle touche ^^

#24 TIMAL

TIMAL

    Membre

  • Membres
  • 53 messages
  • Gender:Male

Posté 24 février 2010 - 12:04

disons que mon programme autonome fonctionne bien, mon programme controle à distance fonctionne aussi.
Mon problème est que je n'arrive pas à faire les deux programmes cohabiter ensemble.
Je souhaiterai que lorsque j'appuie sur "A" mon robot soit autonome et que si j'appuie sur z qu'il soit en mode manuel.
mais en utilisant la fonction switch pour mettre 'A et Z' la partie autonome se lance mais ne prend pas en compte la valeur du capteur, de ce fait le robot ne fait qu'avancer.
si j'appuie sur z il s'arrête,
mon seul souci est que mon programme autonome utilisé seul sans switch fonctionne, mais avec le switch kedallll
Image IPB

#25 TIMAL

TIMAL

    Membre

  • Membres
  • 53 messages
  • Gender:Male

Posté 24 février 2010 - 12:39

je ne sais pas si ça peut t'aider de te donner mon vrai code car 'A et Z' était un exemple
voila l'ensemble:


int inputPinG = 8;
int inputPinC = 9;
int inputPinD = 10;
int valG = 0;
int valC = 0;
int valD = 0;

int E1 = 5; //M1 vitesse
int E2 = 6; //M2 vitesse
int M1 = 4; //M1 Direction
int M2 = 7; //M1 Direction

void advance(char a,char B) //avancer
{
analogWrite (E1,a);
digitalWrite(M1,LOW);
analogWrite (E2,B);
digitalWrite(M2,LOW);
}
void back_off (char a,char B) //reculer
{
analogWrite (E1,a);
digitalWrite(M1,HIGH);
analogWrite (E2,B);
digitalWrite(M2,HIGH);
}
void turn_L (char a,char B) //tourner à gauche
{
analogWrite (E1,a);
digitalWrite(M1,HIGH);
analogWrite (E2,B);
digitalWrite(M2,LOW);
}
void turn_R (char a,char B) //tourner à droite
{
analogWrite (E1,a);
digitalWrite(M1,LOW);
analogWrite (E2,B);
digitalWrite(M2,HIGH);
}
void setup(void)
{
int i;
for(i=5;i<=8;i++)
pinMode(i, OUTPUT);
pinMode(inputPinG, INPUT); // declare Infrared sensor as input
pinMode(inputPinC, INPUT); // declare Infrared sensor as input
pinMode(inputPinD, INPUT); // declare Infrared sensor as input

Serial.begin(19200); //Set Baud Rate
}
void loop ()
{
while (Serial.available()) {
switch (Serial.read())
{
case 'j'://mode automatique
valG = digitalRead(inputPinG);
valC = digitalRead(inputPinC);
valD = digitalRead(inputPinD);
if (valG&&valC&&valD==HIGH){advance(50,50);}
else if (valG==LOW){advance(150,80);}
else if (valC==LOW){turn_R(100,100);}
else if (valC==LOW){advance(80,150);}
break;

//mode manuel
case 'z'://avancer
advance (100,100); //réglage vitesse
break;
case 'q'://virage gauche
advance (150,80); //réglage vitesse
break;
case 's'://virage droite
advance (80,150); //réglage vitesse
break;
case 'x'://tourner sur place à droite
turn_R (100,100);
break;

case 'c'://stop
advance (0,0);
break;
}
}
}


merki!!!!! ^_^
Image IPB

#26 galactus

galactus

    Habitué

  • Membres
  • PipPip
  • 157 messages

Posté 24 février 2010 - 12:42

tu peux editer et passer ton code avec la balise code
je suis pas fan des smileys :lol:

merci d'avance :)

#27 TIMAL

TIMAL

    Membre

  • Membres
  • 53 messages
  • Gender:Male

Posté 24 février 2010 - 11:18

désolé pour les smiley, j'ai po fais gaffe!!

        int inputPinG = 8; 
        int inputPinC = 9; 
        int inputPinD = 10;
        int valG = 0;    
        int valC = 0; 
        int valD = 0; 
        
        int E1 = 5; //M1 vitesse
        int E2 = 6; //M2 vitesse
        int M1 = 4; //M1 Direction 
        int M2 = 7; //M1 Direction 
        
        void advance(char a,char <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> //avancer
        {
        analogWrite (E1,a); 
        digitalWrite(M1,LOW);
        analogWrite (E2, <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> ;
        digitalWrite(M2,LOW);
        }
        void back_off (char a,char <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> //reculer
        {
        analogWrite (E1,a);
        digitalWrite(M1,HIGH);
        analogWrite (E2, <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> ;
        digitalWrite(M2,HIGH);
        }
        void turn_L (char a,char <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> //tourner à gauche
        {
        analogWrite (E1,a);
        digitalWrite(M1,HIGH);
        analogWrite (E2, <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> ;
        digitalWrite(M2,LOW);
        }
        void turn_R (char a,char <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> //tourner à droite
        {
        analogWrite (E1,a);
        digitalWrite(M1,LOW);
        analogWrite (E2, <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> ;
        digitalWrite(M2,HIGH);
        }
        void setup(void)
        {
        int i;
        for(i=5;i<=8;i++)
        pinMode(i, OUTPUT);
        pinMode(inputPinG, INPUT);  // declare Infrared sensor as input
        pinMode(inputPinC, INPUT);  // declare Infrared sensor as input
        pinMode(inputPinD, INPUT);  // declare Infrared sensor as input
        
        Serial.begin(19200); //Set Baud Rate
        }
        void loop ()
        {
          while (Serial.available()) {  
        switch (Serial.read())  
        {  
        case 'j':
           valG = digitalRead(inputPinG);
           valC = digitalRead(inputPinC);
           valD = digitalRead(inputPinD); 
         if (valG&&valC&&valD==HIGH){advance(50,50);}
         else if (valG==LOW){advance(150,80);}
         else if (valC==LOW){turn_R(100,100);}
         else if (valC==LOW){advance(80,150);}
         break;
  
        case 'z'://avancer
        advance (100,100); //réglage vitesse
        break;
        case 'w'://reculer
        back_off (100,100);
        break;
        case 'q'://virage gauche
        advance (150,80); //réglage vitesse
        break;
        case 's'://virage droite
        advance (80,150); //réglage vitesse
        break;
        case 'a'://tourner sur place à gauche
        turn_L (100,100);
        break;
        case 'x'://tourner sur place à droite
        turn_R (100,100);
        break;
        }
        }
        }

je ne sais pas comment faire mais j'ai l'impression qu'il faudrait mettre une sorte de fonction loop dans la partie autonome 'case j' , ce qui n'est pas permis .
Snif!!!
Image IPB

#28 Electron

Electron

    Pilier du forum

  • Membres
  • PipPipPipPip
  • 906 messages
  • Gender:Male
  • Location:LABEGE

Posté 24 février 2010 - 01:09

Ta partie "manuel" est comprise dans la partie automatique, alors que tu devrais séparer les deux parties, faire une boucle séparée pour chacune.

Il sera en automatique grace à une variable mise à une valeur par défaut au début du programme, il restera ainsi dans la boucle "automatique", et dés que tu presse "Z" il sort de la boucle "automatique" et continue vers la boucle "manuel" dans laquelle il restera tant que tu n'auras pas pressé la touche "A", ce qui le renvoie au début du programme où se trouve la boucle "automatique".

"Plus on partage, plus on possède, voilà le miracle". LEONARD NIMOY
"Celui qui se bat peut perdre, celui qui ne se bat pas a déjà tout perdu". BERTOLT BRECHT (1898-1956)
Comment se lancer dans la robotique !
Mince encore un post pour augmenter mon compteur ;)


#29 TIMAL

TIMAL

    Membre

  • Membres
  • 53 messages
  • Gender:Male

Posté 25 février 2010 - 05:21

Merci électron j'ai compris ce que tu m'a dit, mais j'ai du mal à l'appliquer!!!!

En suivant tes conseils j'ai fait deux boucles distincts dans void loop.,
J'ai utilisé les fonctions if else if switch et do...while 'j'ai passé des heures et des heures pour trouver une solution avec les fonctions while et for mais en vain, mon niveau est encore trop juste)

Toutes les touches répondent bien aux actions, mais une fois dans le mode auto je ne peux plus retourner au mode manuel.
il manque pas grand chose!!!!!!
Quelqu'un aurait - il une piste :unsure: je bloooooooque!!!!!

    int inputPinG = 8; 
   int inputPinC = 9; 
   int inputPinD = 10;
   int valG = 0;    
   int valC = 0; 
   int valD = 0; 
   
   int E1 = 5; //M1 vitesse
   int E2 = 6; //M2 vitesse
   int M1 = 4; //M1 Direction 
   int M2 = 7; //M1 Direction 
   
   void advance(char a,char <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> //avancer
   {
   analogWrite (E1,a); 
   digitalWrite(M1,LOW);
   analogWrite (E2, <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> ;
   digitalWrite(M2,LOW);
   }
   void back_off (char a,char <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> //reculer
   {
   analogWrite (E1,a);
   digitalWrite(M1,HIGH);
   analogWrite (E2, <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> ;
   digitalWrite(M2,HIGH);
   }
   void turn_L (char a,char <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> //tourner à gauche
   {
   analogWrite (E1,a);
   digitalWrite(M1,HIGH);
   analogWrite (E2, <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> ;
   digitalWrite(M2,LOW);
   }
   void turn_R (char a,char <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> //tourner à droite
   {
   analogWrite (E1,a);
   digitalWrite(M1,LOW);
   analogWrite (E2, <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> ;
   digitalWrite(M2,HIGH);
   }
   void setup(void)
   {
   int i;
   for(i=5;i<=8;i++)
   pinMode(i, OUTPUT);
   pinMode(inputPinG, INPUT);  // declare Infrared sensor as input
   pinMode(inputPinC, INPUT);  // declare Infrared sensor as input
   pinMode(inputPinD, INPUT);  // declare Infrared sensor as input
   
   Serial.begin(19200); //Set Baud Rate
   }
   
   void loop(void)
   {
   char val = Serial.read();
   if(val!='j')//mode manuel
   {
   switch (val) 
   { 
   case 'z'://avancer
   advance (50,50); //réglage vitesse
   break;
   case 'w'://reculer
   back_off (50,50);
   break;
   case 'q'://virage gauche
   advance (70,50); //réglage vitesse
   break;
   case 's'://virage droite
   advance (50,70); //réglage vitesse
   break;
   case 'a'://tourner sur place à gauche
   turn_L (50,50);
   break;
   case 'x'://tourner sur place à droite
   turn_R (50,50);
   break;
   case 'c':// stop
   advance (0,0);
   break;
   }
   }
   else if(val=='j')//mode auto
   {
   [color="#00ff00"]do{[/color]
     valG = digitalRead(inputPinG);
     valC = digitalRead(inputPinC);
     valD = digitalRead(inputPinD); 
             
    if(valG&&valC&&valD==HIGH)
    advance(50,50);
    
    else if (!valG&&valC&&valD==HIGH)
    advance(70,50);
    else if (valG&&valC&&!valD==HIGH)
    advance(50,70);
    
    else turn_R(50,50);
   }
   while (val=='j');
   }
   }
   

Image IPB

#30 Electron

Electron

    Pilier du forum

  • Membres
  • PipPipPipPip
  • 906 messages
  • Gender:Male
  • Location:LABEGE

Posté 25 février 2010 - 11:24

if(val!='j')//mode manuel

Traduction de ça : "Si val est différent de "j" alors passer en mode manuel"

Donc apparemment tu passe en mode manuel en pressant une touche différente de "j" c'est ce qui est écrit dans le test.
Hors toi tu voudrais passer en mode manuel AVEC "j" ;)
regarde si l'erreur ne vient pas de là.

Je continue de lire pour voir si je trouve pas un truc.

En gros moi je ferais :
- début de la boucle "manuel"
- test si touche pressée="a" si oui sortir de la boucle et aller à la boucle "automatique", sinon test des touches de directions.
- Fin de la boucle "manuel".


- début de la boucle "automatique"
- test si touche pressée="m" si oui sortir de la boucle et aller à la boucle "manuel".
- traitements de l'automatique.
- fin de la boucle "automatique".

"Plus on partage, plus on possède, voilà le miracle". LEONARD NIMOY
"Celui qui se bat peut perdre, celui qui ne se bat pas a déjà tout perdu". BERTOLT BRECHT (1898-1956)
Comment se lancer dans la robotique !
Mince encore un post pour augmenter mon compteur ;)


#31 TIMAL

TIMAL

    Membre

  • Membres
  • 53 messages
  • Gender:Male

Posté 27 février 2010 - 12:34

bonjour électron, j'ai suivi à la lettre tes instructions, mais j'ai un problème de syntaxe donc impossible de compiler
j'ai ce message d'erreur :

In function 'void loop()':
error: a function-definition is not allowed here before '{' token
l'erreur est situé sur: void manuel()


  void loop(void)
  {
 
 
  void manuel()
  {
  char val = Serial.read();
  
  if (val=='h') automatique()
  else
    {
    switch (val)  
      { 
      case 'z'://avancer
         advance (50,50); //réglage vitesse
         break;
      case 'w'://reculer
         back_off (50,50);
         break;
      case 'q'://virage gauche
         advance (70,50); //réglage vitesse
         break;
      case 's'://virage droite
         advance (50,70); //réglage vitesse
         break;
      case 'a'://tourner sur place à gauche
         turn_L (50,50);
         break;
      case 'x'://tourner sur place à droite
         turn_R (50,50);
         break;
      case 'c':// stop
         advance (0,0);
         break;
      }
    } //fin du test de val
  } //fin de manuel
  
  void automatique()
    {
    char val = Serial.read();
  
    if (val=='j') manuel();

    valG = digitalRead(inputPinG);
    valC = digitalRead(inputPinC);
    valD = digitalRead(inputPinD); 

    if(valG&&valC&&valD==HIGH) advance(50,50)
    else if (!valG&&valC&&valD==HIGH) advance(70,50)
    else if (valG&&valC&&!valD==HIGH) advance(50,70)
    else turn_R(50,50);

    } // fin de automatique
  } // fin du loop

Il manque un else après ça :
if (val=='j') manuel();
Ne met pas de point virgule avant un else.

Ce que j'ai fait :
Suppression du point virgule avant les elses
Indentation du code pour y voir plus clair.
Supression des accolades autour de l'appel à automatique() dans la fonction void manuel().



Essaie avec ça et on verra par la suite.
La traduction de l'erreur, c'est qu'il manque la définition d'une fonction avant l'accolade de la fonction et l'erreur se situe dans la fonction loop.
Image IPB

#32 Electron

Electron

    Pilier du forum

  • Membres
  • PipPipPipPip
  • 906 messages
  • Gender:Male
  • Location:LABEGE

Posté 27 février 2010 - 03:10

J'ai regardé un peu ton code, j'ai écris dessus ce que j'y ai fait.
Le compilo ne te donne pas un numéro de ligne où se situe l'erreur ?

"Plus on partage, plus on possède, voilà le miracle". LEONARD NIMOY
"Celui qui se bat peut perdre, celui qui ne se bat pas a déjà tout perdu". BERTOLT BRECHT (1898-1956)
Comment se lancer dans la robotique !
Mince encore un post pour augmenter mon compteur ;)


#33 TIMAL

TIMAL

    Membre

  • Membres
  • 53 messages
  • Gender:Male

Posté 01 mars 2010 - 10:04

Voila j'ai fait toutes les modifs, quand je compile il me met erreur:

"In function 'void loop()': error: a function-definition is not allowed here before '{' token"

et c'est la ligne 57
apparement il y a un problème avec void manuel :( , help electron!
  int inputPinG = 8; 
  int inputPinC = 9; 
  int inputPinD = 10;
  
  int valG = 0;    
  int valC = 0; 
  int valD = 0; 
  
  int E1 = 5; //M1 vitesse
  int E2 = 6; //M2 vitesse
  int M1 = 4; //M1 Direction 
  int M2 = 7; //M1 Direction 
  
  void advance(char a,char <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> //avancer
  {
  analogWrite (E1,a); 
  digitalWrite(M1,LOW);
  analogWrite (E2, <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> ;
  digitalWrite(M2,LOW);
  }
  void back_off (char a,char <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> //reculer
  {
  analogWrite (E1,a);
  digitalWrite(M1,HIGH);
  analogWrite (E2, <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> ;
  digitalWrite(M2,HIGH);
  }
  void turn_L (char a,char <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> //tourner à gauche
  {
  analogWrite (E1,a);
  digitalWrite(M1,HIGH);
  analogWrite (E2, <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> ;
  digitalWrite(M2,LOW);
  }
  void turn_R (char a,char <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> //tourner à droite
  {
  analogWrite (E1,a);
  digitalWrite(M1,LOW);
  analogWrite (E2, <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> ;
  digitalWrite(M2,HIGH);
  }
  void setup(void)
  {
  int i;
  for(i=5;i<=8;i++)
  pinMode(i, OUTPUT);
  pinMode(inputPinG, INPUT);  // declare Infrared sensor as input
  pinMode(inputPinC, INPUT);  // declare Infrared sensor as input
  pinMode(inputPinD, INPUT);  // declare Infrared sensor as input
  
  Serial.begin(19200); //Set Baud Rate
  }
  
  void loop(void)
  {
  void manuel()
  {
  char val = Serial.read();
  if (val=='h')
  automatique()
      
  else
    {
  switch (val)  
  { 
  case 'z'://avancer
  advance (50,50); //réglage vitesse
  break;
  case 'w'://reculer
  back_off (50,50);
  break;
  case 'q'://virage gauche
  advance (70,50); //réglage vitesse
  break;
  case 's'://virage droite
  advance (50,70); //réglage vitesse
  break;
  case 'a'://tourner sur place à gauche
  turn_L (50,50);
  break;
  case 'x'://tourner sur place à droite
  turn_R (50,50);
  break;
  case 'c':// stop
  advance (0,0);
  break;
  }
  } //fin du test de val
  } //fin de manuel
  
  
  void automatique()
    {
  char val = Serial.read();
  
  if (val=='j') 
  
  manuel();
  
    valG = digitalRead(inputPinG);
    valC = digitalRead(inputPinC);
    valD = digitalRead(inputPinD); 
            
   if(valG&&valC&&valD==HIGH)
   advance(50,50);
   else if (!valG&&valC&&valD==HIGH)
   advance(70,50);
   else if (valG&&valC&&!valD==HIGH)
   advance(50,70);
   else turn_R(50,50);
  }// fin de automatique
  }// fin du loop

Image IPB

#34 Electron

Electron

    Pilier du forum

  • Membres
  • PipPipPipPip
  • 906 messages
  • Gender:Male
  • Location:LABEGE

Posté 02 mars 2010 - 03:41

Heu...j'aurais préféré que tu m'indique la ligne en question que tu repère d'abord par le numéro que te donne le compilo, car là sur le forum, compter les lignes c'est pas pratique (même sans le forum^^).

"Plus on partage, plus on possède, voilà le miracle". LEONARD NIMOY
"Celui qui se bat peut perdre, celui qui ne se bat pas a déjà tout perdu". BERTOLT BRECHT (1898-1956)
Comment se lancer dans la robotique !
Mince encore un post pour augmenter mon compteur ;)


#35 TIMAL

TIMAL

    Membre

  • Membres
  • 53 messages
  • Gender:Male

Posté 02 mars 2010 - 03:46

J'ai mis ce symbole <<<<< pour cibler la ligne 57.

  int inputPinG = 8; 
  int inputPinC = 9; 
  int inputPinD = 10;
  
  int valG = 0;    
  int valC = 0; 
  int valD = 0; 
  
  int E1 = 5; //M1 vitesse
  int E2 = 6; //M2 vitesse
  int M1 = 4; //M1 Direction 
  int M2 = 7; //M1 Direction 
  
  void advance(char a,char <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> //avancer
  {
  analogWrite (E1,a); 
  digitalWrite(M1,LOW);
  analogWrite (E2, <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> ;
  digitalWrite(M2,LOW);
  }
  void back_off (char a,char <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> //reculer
  {
  analogWrite (E1,a);
  digitalWrite(M1,HIGH);
  analogWrite (E2, <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> ;
  digitalWrite(M2,HIGH);
  }
  void turn_L (char a,char <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> //tourner à gauche
  {
  analogWrite (E1,a);
  digitalWrite(M1,HIGH);
  analogWrite (E2, <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> ;
  digitalWrite(M2,LOW);
  }
  void turn_R (char a,char <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> //tourner à droite
  {
  analogWrite (E1,a);
  digitalWrite(M1,LOW);
  analogWrite (E2, <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> ;
  digitalWrite(M2,HIGH);
  }
  void setup(void)
  {
  int i;
  for(i=5;i<=8;i++)
  pinMode(i, OUTPUT);
  pinMode(inputPinG, INPUT);  // declare Infrared sensor as input
  pinMode(inputPinC, INPUT);  // declare Infrared sensor as input
  pinMode(inputPinD, INPUT);  // declare Infrared sensor as input
  
  Serial.begin(19200); //Set Baud Rate
  }
  
  void loop(void)
  {                    
  void manuel()
  {             <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<c'est ici.
  char val = Serial.read();
  if (val=='h')
  automatique()
      
  else
    {
  switch (val)  
  { 
  case 'z'://avancer
  advance (50,50); //réglage vitesse
  break;
  case 'w'://reculer
  back_off (50,50);
  break;
  case 'q'://virage gauche
  advance (70,50); //réglage vitesse
  break;
  case 's'://virage droite
  advance (50,70); //réglage vitesse
  break;
  case 'a'://tourner sur place à gauche
  turn_L (50,50);
  break;
  case 'x'://tourner sur place à droite
  turn_R (50,50);
  break;
  case 'c':// stop
  advance (0,0);
  break;
  }
  } //fin du test de val
  } //fin de manuel
  
  
  void automatique()
    {
  char val = Serial.read();
  
  if (val=='j') 
  
  manuel();
  
    valG = digitalRead(inputPinG);
    valC = digitalRead(inputPinC);
    valD = digitalRead(inputPinD); 
            
   if(valG&&valC&&valD==HIGH)
   advance(50,50);
   else if (!valG&&valC&&valD==HIGH)
   advance(70,50);
   else if (valG&&valC&&!valD==HIGH)
   advance(50,70);
   else turn_R(50,50);
  }// fin de automatique
  }// fin du loop
  

Image IPB

#36 Electron

Electron

    Pilier du forum

  • Membres
  • PipPipPipPip
  • 906 messages
  • Gender:Male
  • Location:LABEGE

Posté 02 mars 2010 - 03:51

A priori, je vois pas, essai de l'écrire comme ça : void manuel(void)
Ta pas corrigé non plus le else comme je te l'ai indiqué précédemment^^

"Plus on partage, plus on possède, voilà le miracle". LEONARD NIMOY
"Celui qui se bat peut perdre, celui qui ne se bat pas a déjà tout perdu". BERTOLT BRECHT (1898-1956)
Comment se lancer dans la robotique !
Mince encore un post pour augmenter mon compteur ;)


#37 TIMAL

TIMAL

    Membre

  • Membres
  • 53 messages
  • Gender:Male

Posté 02 mars 2010 - 09:59

rien à faire ,après tous les changements ça ne compile pô!

il y a un phénomène que j'aimerai comprendre.
le code ci dessous fonctionne très bien:le robot avance , recule, tourne etc en fonction des valeurs des capteurs

          int inputPinG = 8; 
          int inputPinC = 9; 
          int inputPinD = 10;
          
          int valG = 0;    
          int valC = 0; 
          int valD = 0; 
          
          void automatique(void) 
        {   
            valG = digitalRead(inputPinG);
            valC = digitalRead(inputPinC);
            valD = digitalRead(inputPinD); 
            
           if(valG&&valC&&valD==HIGH)
           advance(50,50);
           else if (!valG&&valC&&valD==HIGH)
           advance(70,50);
           else if (valG&&valC&&!valD==HIGH)
           advance(50,70);
           else turn_R(50,50);
          }
          
          
          int E1 = 5; //M1 vitesse
          int E2 = 6; //M2 vitesse
          int M1 = 4; //M1 Direction 
          int M2 = 7; //M1 Direction 
          
          void advance(char a,char <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> //avancer
          {
          analogWrite (E1,a); 
          digitalWrite(M1,LOW);
          analogWrite (E2, <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> ;
          digitalWrite(M2,LOW);
          }
          void back_off (char a,char <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> //reculer
          {
          analogWrite (E1,a);
          digitalWrite(M1,HIGH);
          analogWrite (E2, <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> ;
          digitalWrite(M2,HIGH);
          }
          void turn_L (char a,char <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> //tourner à gauche
          {
          analogWrite (E1,a);
          digitalWrite(M1,HIGH);
          analogWrite (E2, <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> ;
          digitalWrite(M2,LOW);
          }
          void turn_R (char a,char <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> //tourner à droite
          {
          analogWrite (E1,a);
          digitalWrite(M1,LOW);
          analogWrite (E2, <img src='http://www.robot-maker.com/forum/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> ;
          digitalWrite(M2,HIGH);
          
          }
          void setup(void)
          {
          int i;
          for(i=5;i<=8;i++)
          pinMode(i, OUTPUT);
          pinMode(inputPinG, INPUT);  // declare Infrared sensor as input
          pinMode(inputPinC, INPUT);  // declare Infrared sensor as input
          pinMode(inputPinD, INPUT);  // declare Infrared sensor as input
          
          Serial.begin(19200); //Set Baud Rate
          }
          
          void loop(void)
            {
        automatique(); <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<mode automatique<<<<<<<<<<<<<<<<<<<<<<<<fonctionne
            }


mais dès que je met un if dans void loop, le robot ne fait qu'avancer sans prendre en compte la valeur des capteurs
voici le code
               
          void loop(void)
          {
          char val = Serial.read();
          if (val=='j')
            {
        automatique();          <<<<<<<<<<<<<<<<<<<je veux que lorsque l'on appuie sur j le mode automatique se déroule<<<<<<<<<<<<problème
            }
          }

comprend pô, si vous avez des idées n'hésitez pas !!
Image IPB

#38 Electron

Electron

    Pilier du forum

  • Membres
  • PipPipPipPip
  • 906 messages
  • Gender:Male
  • Location:LABEGE

Posté 03 mars 2010 - 04:15

Logiquement, soit il voit que val différend de "j", soit il voit que val==j mais ne sait pas sortir de la boucle, maintenant il faut voir ça en détail, je pars au boulot, je regarde ça après.

Heu, mais au fait, s'il est déjà en mode automatique dés le départ, et tu lui dis que s'il voit val=j il aille en automatique, donc rien ne change il reste en automatique.

Met-le en mode manuel dés le départ (juste avant le loop) et voit si le test de val==j le met en auto.

"Plus on partage, plus on possède, voilà le miracle". LEONARD NIMOY
"Celui qui se bat peut perdre, celui qui ne se bat pas a déjà tout perdu". BERTOLT BRECHT (1898-1956)
Comment se lancer dans la robotique !
Mince encore un post pour augmenter mon compteur ;)


#39 galactus

galactus

    Habitué

  • Membres
  • PipPip
  • 157 messages

Posté 03 mars 2010 - 08:36

void loop()
          {
          char val = Serial.read();

          switch(val){
                     case 'j':
                     automatique();
                     break;
                
                     default:
                     manuel();

          }

         

ps: je comprends pas ton
void loop(void)


#40 Electron

Electron

    Pilier du forum

  • Membres
  • PipPipPipPip
  • 906 messages
  • Gender:Male
  • Location:LABEGE

Posté 03 mars 2010 - 01:07

Oui je trouve ton code sympa galactus^^

Ce code est dans quel langage là sinon Timal ?

"Plus on partage, plus on possède, voilà le miracle". LEONARD NIMOY
"Celui qui se bat peut perdre, celui qui ne se bat pas a déjà tout perdu". BERTOLT BRECHT (1898-1956)
Comment se lancer dans la robotique !
Mince encore un post pour augmenter mon compteur ;)




Répondre à ce sujet



  


0 utilisateur(s) li(sen)t ce sujet

0 members, 0 guests, 0 anonymous users