Troubles with Mobile Robot Programming

Hello all,

I have started in the programming stage of my project , a mobile robot that navigates in unknown environment and should avoid obstacles and reach target depending on the Artificial Potential Field algorithm .

actually , I parted the software of the project to several parts : odometry using encoders to determine position and orientation , controlling of motors by Fuzzy logic control , Artificial Potential Field algorithm and sensors readings , after that I tested each part of the code separately on their own and all parts worked successfully. then with my a little bit knowledge I merged all these parts in one final program . But after merging and upload code on the Arduino board , it does not work normally , just left motor spin with choppy speed and right motor does not spin even the controller send commands to it so could any one help , I need for some suggestions and corrections if there were .

Picture below show the diagram of the project ,

Do you have the code of the parts?

luisilva: Do you have the code of the parts?

thanks

all parts in the attachment code with comments showed that .

(...) after that I tested each part of the code separately on their own and all parts worked successfully

I was talking about the code of each part in a separated file when you did the test.

One suggestion can be add to a part of the program, first one one other part, and test the final result. After that add the 3rd part.

It looks like you are using pins 0 and 1 for motor control, which will conflict with Serial.print etc.

luisilva:

(...) after that I tested each part of the code separately on their own and all parts worked successfully

I was talking about the code of each part in a separated file when you did the test.

One suggestion can be add to a part of the program, first one one other part, and test the final result. After that add the 3rd part.

jremington: It looks like you are using pins 0 and 1 for motor control, which will conflict with Serial.print etc.

thanks jremington

lately , I noticed that and I change the Pins but that don't solve the problem .

It could not possibly have worked, with pins 0 and 1 connected to the motors and the Serial I/O. So what problem are you having now? Post your revised code.

Maybe is a silly question, but did you try APF with different values than:

zzz=APFtt(1,1,1,1,1);

?

I see also that your fuzzy logic “module”:

void loop()
{
    // Read Input: F
    g_fisInput[0] = analogRead(0);
    // Read Input: L
    g_fisInput[1] = analogRead(1);
    // Read Input: R
    g_fisInput[2] = analogRead(2);
    // Read Input: Th
    g_fisInput[3] = analogRead(3);

    g_fisOutput[0] = 0;
    g_fisOutput[1] = 0;

    fis_evaluate();

    // Set output vlaue: wr
    analogWrite(4 , g_fisOutput[0]);
    // Set output vlaue: wl
    analogWrite(5 , g_fisOutput[1]);
}

don’t have the motor speed part:

(...)
// ---------------------------- Motor speed part -----------------------------------------

  int rightPWM, leftPWM;
  if (Wr > 0) {
    //forward
    digitalWrite(IN1, LOW);
    digitalWrite(IN2, HIGH);

  }  else if (Wr < 0) {
    //reverse
    digitalWrite(IN1, HIGH);
    digitalWrite(IN2, LOW);
  }

  if (Wr == 0) {
    rightPWM = 0;
    analogWrite(ENA, rightPWM);
  } else {
    rightPWM = map(abs(Wr), 1, 100, 1, 255);
    analogWrite(ENA, rightPWM);
  }


  //--------------------------||-----------------------------\\

  if (Wl > 0) {
    //forward
    digitalWrite(IN3, LOW);
    digitalWrite(IN4, HIGH);
  }  else if (Wl < 0) {
    //reverse
    digitalWrite(IN3, HIGH);
    digitalWrite(IN4, LOW);
  }

  if (Wl == 0) {
    leftPWM = 0;
    analogWrite(ENB, leftPWM);
  } else {
    leftPWM = map(abs(Wl), 1, 100, 1, 255);
    analogWrite(ENB, leftPWM);
  }

  // ---------------------------- Motor speed Part end -----------------------------------------

Do you test this part, or is a new part?

Finally, do you now the values that you are trying to write “to the motors”? That is, what are the values of:

- rightPWM;
- leftPWM;

?
Did this values make sense?