Let's Make Robots!

4WD arduino romeo programming (how to do several action in the same time)

Good morning!

i have make a robot with :

-platform arduino

-ROMEO 328mo

-three sensor infrared

-apc 220 wireless

-1 battery nimh 12V for motors

-1 battery nimh 9V for ROMEO

i made a sketch for controled the robot with my keyboard and processing "it is good!!

i made a sketch for have a autonomous robot "it is good!!

but when i put the sketch "controled" with the "autonomous" in the same sketch there is problem!

when i pressed 'j' on my keyboard for the autonmous sketch it not work, i must hold the key 'j' pressed for start working ok

and for mode default "controled" when i pushed on a key for controled my robot it not work immediately "not in real time"

i don't understand if you have a idea i will very happy, sorry for my english i'm french.

i shawn you my sketch:

     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 setup(void)
     {
     int i;
     for(i=4;i<=7;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()
    {
   valD = digitalRead(8);
   valC = digitalRead(9);
   valG = digitalRead(10);
  
     char choose = Serial.read();
  
     switch(choose){
     case 'j':
     automatique();//mode autonomous!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     break;
                  
    default:
    manuel();//mode manual or controled!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   }
   }
            
void automatique(void) //autonomous!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   {  
  if((valD==LOW&&!valG==LOW&&!valC==LOW)||(valD==LOW&&!valG==LOW&&valC==LOW))
  turn_L (100,100);

  else if ((valC==LOW&&!valG==LOW&&!valD==LOW)||(valC==LOW&&valG==LOW&&valD==LOW)||(!valC==LOW&&valG==LOW&&valD==LOW))
  back_R (100,60);
 
  else if ((valG==LOW&&!valC==LOW&&!valD==LOW)||(valC==LOW&&valG==LOW&&!valD==LOW))
  turn_R (100,100);

  else 
  advance (80,80);
     }

 void manuel(void) //Controled!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     {
     char val = Serial.read();
     switch (val) 
     {
     case 'z'://advance
     advance (50,50);
     break;
     case 'w'://back off
     back_off (50,50);
     break;
     case 'q'://virage left
     advance (70,50);
     break;
     case 's'://virage right
     advance (50,70);
     break;
     case 'a'://turn left
     turn_L (50,50);
     break;
     case 'x'://turn right
     turn_R (50,50);
     break;
     case 'c':// stop
     advance (0,0);
     break;
     }
     }
    
   void stop(void) //Stop
     {
     digitalWrite(E1,LOW);
     digitalWrite(E2,LOW);
     }
     void advance(char a,char B) //advance
     {
     analogWrite (E1,a);
     digitalWrite(M1,LOW);
     analogWrite (E2, B) ;
     digitalWrite(M2,LOW);
     }
     void back_R (char a,char B)//back off right
     {
     analogWrite (E1,a);
     digitalWrite(M1,HIGH);
     analogWrite (E2, B) ;
     digitalWrite(M2,HIGH);
     }
     void back_off (char a,char B) //back off
     {
     analogWrite (E1,a);
     digitalWrite(M1,HIGH);
     analogWrite (E2, B) ;
     digitalWrite(M2,HIGH);
     }
     void turn_L (char a,char B) //turn left
     {
     analogWrite (E1,a);
     digitalWrite(M1,HIGH);
     analogWrite (E2, B) ;
     digitalWrite(M2,LOW);
     }
     void turn_R (char a,char B) //turn right
     {
     analogWrite (E1,a);
     digitalWrite(M1,LOW);
     analogWrite (E2, B) ;
     digitalWrite(M2,HIGH);
     }

a other example :

if i want to controlled my robot and turn on or off a led ,when i pushed on a key for controled my robot it work but not immediately "not in real time" and it's very difficult to drive the robot

void loop()
  {
  while (Serial.available()){
  char choose = Serial.read();

if(choose=='k')
{
digitalWrite(ledPin, HIGH); //
}
if(choose=='m')
{
digitalWrite(ledPin, LOW); //
}
}
manuel();//mode controled!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

}

not say me that the romeo arduino can't run many actions in the same time else i cry!!!!

thank you!!!!

AttachmentSize
DSC08765.JPG1.36 MB

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Hey again, I've been out of the country for the past week and a half, great to hear your robot is working so much better now!

You should definitely start a new post regarding your issue with downloading a sketch via the APC220, so that others with the same problem can also go there for help.

How is the keyboard connected to the Arduino? Perhaps the delay is on that side of things.

thank you djhesit8 for your answer now i 'm crying!!!!!!!

it's very shame when you see all the input and output on the romeo and you can't do two actions in the same time.

telefox the keyboard is connected to the arduino with a apc 220 module wireless.maybe there is a problem with the delay but i don't know how to solve it.