loading
 
Obstacle avoidance (help)
Anonymous
13 year
Hello Mr. Steven
I have prepared a new robo file so that i can use it to do obstacle avoidance for my mini robot. At the moment i am using serial module to communicate to arduino mega. I have adopted few codes from this forum.

But i have noticed that the behavior of the robot is not as desired. At times it does obstacle avoidance and at times it bumps into it. I have attached the robo file, the arduino sketch and the picture of the scene which i will be using in real time and the path which i wish to attain with my web cam. Could you please have a look and fine tune so that i can get a better performance.

Anonymous 13 year
Sorry here are the files

  

obstacle_test.robo
program.robo
Anonymous 13 year

int E1 = 4;    //Enable Right motor controller
int E2 = 8;    //Enable Left motor controller
int M1 = 10;   //Right Motor  Forward PWM
int M2 = 5;    //Left Motor  Reverse PWM***********differential drive configuration

int highest_middle_x = 0; // The distance of the object from the center of the screen
int midx=0;
int left_threshold=0;
int right_threshold=0;
int i=0;// counter
int x = 0;
int StrArray[4] = {0, 0, 0, 0};//A buffer to store the ASCII value read in from the serial port

void setup()
{
  pinMode(E1, OUTPUT);
  pinMode(E2, OUTPUT);
  pinMode(M1, OUTPUT);
  pinMode(M2, OUTPUT);
  
  Serial.begin(115200); // Open the serial port with a 9600 baud rate
  Serial.println("Arduino Mega is ready"); // Print on screen
}

void loop()
{
  // Wait for data to become available at the serial port
while(!Serial.available()){}

while(Serial.available())
{
  StrArray[i] = Serial.read() - '0';

  delay(1);
   i++;
}

  if(i==4)
    x = StrArray[0]*1000 + StrArray[1]*100 + StrArray[2]*10 + StrArray[3];
  if(i==3)
    x = StrArray[0]*100 + StrArray[1]*10 + StrArray[2];
  if(i==2)
    x = StrArray[0]*10 + StrArray[1];
  if(i==1)
    x = StrArray[0];  
    
     i=0;
    
   highest_middle_x = x;
   delay(10);
   Serial.println(highest_middle_x);
       midx=320;
      
      left_threshold= midx-50;
      right_threshold= midx+50;
      
  if (highest_middle_x <=left_threshold)
     {
      digitalWrite(E1,HIGH);
      analogWrite (M1,200);
      digitalWrite(E2,LOW);
      analogWrite (M2,50);
      delay(100);
    }
    else if (highest_middle_x >= right_threshold)
    {
      digitalWrite(E1,LOW);
      analogWrite (M1,50);
      digitalWrite(E2,HIGH);
      analogWrite (M2,200);
      delay(100);
    }
    else
    {
      digitalWrite(E1,HIGH);
      analogWrite (M1,200);
      digitalWrite(E2,HIGH);
      analogWrite (M2,200);
      delay(100);
    }
  }

Anonymous 13 year
Can anyone help me on the above issue.

Thanks in advance.
Anonymous 13 year
First off, what image size are you using? The posted image is WAY too large. You should scale that down to a maximum of 640 .. things will work a lot faster when you do.

Second, have a look at the two attached robofiles. One refines what you did (need to select the color option in the blob size otherwise you are just thresholding the image) and the other uses the floor finder which was recently upgraded (download RR again to get that to work correctly). That should help a bit with the detection.

Third, your script is not quite right on the Arduino. If the PC sends a lot of data (which it can easily do) the

while(Serial.available())

can loop endlessly and cause a fault in the application. You'd be better off using the code below that in the MCU_Communicator module that provides a stable way of PC to Arduino communication and allows you to extend that communication program with your own custom code. It should allow the transferal of any variable in RR to the Arduino in a standard way that will not cause communication mixups.

http://www.roborealm.com/help/MCU_Communicator.php

STeven.
program.robo
Anonymous 13 year
Thanks Steven.

Will try it out and hope that it will perform a better job this time. Thanks.

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index