Call to 'AF_DCMotor::AF_DCMotor(uint8_t, uint8_t)' uses the default argument for parameter 2, which is not yet defined (Obstracle avioding BOw)

I am getting a new error I am trying to work on obstracle avioding bot but when I upload my program this error is showing

Arduino: 1.8.19 (Windows 10), Board: "WeMos D1 R1, 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS:2MB OTA:~1019KB), v2 Lower Memory, Disabled, None, Only Sketch, 115200"

In file included from C:\Users\rames\Downloads\Compressed\ObstacleAvoidingRobot\ObstacleAvoidingRobot.ino:6:0:

C:\Users\rames\OneDrive\Documents\Arduino\libraries\Adafruit_Motor_Shield_library/AFMotor.h:156:47: error: 'DC_MOTOR_PWM_RATE' was not declared in this scope

   AF_DCMotor(uint8_t motornum, uint8_t freq = DC_MOTOR_PWM_RATE);

                                               ^

ObstacleAvoidingRobot:9:23: error: call to 'AF_DCMotor::AF_DCMotor(uint8_t, uint8_t)' uses the default argument for parameter 2, which is not yet defined

 AF_DCMotor rightBack(1);                          //Create an object to control each motor

                       ^

ObstacleAvoidingRobot:10:24: error: call to 'AF_DCMotor::AF_DCMotor(uint8_t, uint8_t)' uses the default argument for parameter 2, which is not yet defined

 AF_DCMotor rightFront(2);

                        ^

ObstacleAvoidingRobot:11:23: error: call to 'AF_DCMotor::AF_DCMotor(uint8_t, uint8_t)' uses the default argument for parameter 2, which is not yet defined

 AF_DCMotor leftFront(3);

                       ^

ObstacleAvoidingRobot:12:22: error: call to 'AF_DCMotor::AF_DCMotor(uint8_t, uint8_t)' uses the default argument for parameter 2, which is not yet defined

 AF_DCMotor leftBack(4);

                      ^

Multiple libraries were found for "Servo.h"

 Used: C:\Users\rames\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.1\libraries\Servo

 Not used: C:\Program Files (x86)\Arduino\libraries\Servo

exit status 1

call to 'AF_DCMotor::AF_DCMotor(uint8_t, uint8_t)' uses the default argument for parameter 2, which is not yet defined



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Is this a simple error or is it hard to remove pls help me

//The DIY Life
//Michael Klements
//29 June 2020
//Obstacle Avoiding Robot

#include <AFMotor.h>                              //Import library to control motor shield
#include <Servo.h>                                //Import library to control the servo

AF_DCMotor rightBack(1);                          //Create an object to control each motor
AF_DCMotor rightFront(2);
AF_DCMotor leftFront(3);
AF_DCMotor leftBack(4);
Servo servoLook;                                  //Create an object to control the servo

byte trig = A0;                                    //Assign the ultrasonic sensor pins
byte echo = D2;
byte maxDist = 150;                               //Maximum sensing distance (Objects further than this distance are ignored)
byte stopDist = 50;                               //Minimum distance from an object to stop in cm
float timeOut = 2*(maxDist+10)/100/340*1000000;   //Maximum time to wait for a return signal

byte motorSpeed = 55;                             //The maximum motor speed
int motorOffset = 10;                             //Factor to account for one side being more powerful
int turnSpeed = 50;                               //Amount to add to motor speed when turning


void setup() 
{
  rightBack.setSpeed(motorSpeed);                 //Set the motors to the motor speed
  rightFront.setSpeed(motorSpeed);
  leftFront.setSpeed(motorSpeed+motorOffset);
  leftBack.setSpeed(motorSpeed+motorOffset);
  rightBack.run(RELEASE);                         //Ensure all motors are stopped
  rightFront.run(RELEASE);
  leftFront.run(RELEASE);
  leftBack.run(RELEASE);
  servoLook.attach(10);                           //Assign the servo pin
  pinMode(trig,OUTPUT);                           //Assign ultrasonic sensor pin modes
  pinMode(echo,INPUT);
}

void loop() 
{
  servoLook.write(90);                            //Set the servo to look straight ahead
  delay(750);
  int distance = getDistance();                   //Check that there are no objects ahead
  if(distance >= stopDist)                        //If there are no objects within the stopping distance, move forward
  {
    moveForward();
  }
  while(distance >= stopDist)                     //Keep checking the object distance until it is within the minimum stopping distance
  {
    distance = getDistance();
    delay(250);
  }
  stopMove();                                     //Stop the motors
  int turnDir = checkDirection();                 //Check the left and right object distances and get the turning instruction
  Serial.print(turnDir);
  switch (turnDir)                                //Turn left, turn around or turn right depending on the instruction
  {
    case 0:                                       //Turn left
      turnLeft (400);
      break;
    case 1:                                       //Turn around
      turnLeft (700);
      break;
    case 2:                                       //Turn right
      turnRight (400);
      break;
  }
}

void accelerate()                                 //Function to accelerate the motors from 0 to full speed
{
  for (int i=0; i<motorSpeed; i++)                //Loop from 0 to full speed
  {
    rightBack.setSpeed(i);                        //Set the motors to the current loop speed
    rightFront.setSpeed(i);
    leftFront.setSpeed(i+motorOffset);
    leftBack.setSpeed(i+motorOffset);
    delay(10);
  }
}

void decelerate()                                 //Function to decelerate the motors from full speed to zero
{
  for (int i=motorSpeed; i!=0; i--)               //Loop from full speed to 0
  {
    rightBack.setSpeed(i);                        //Set the motors to the current loop speed
    rightFront.setSpeed(i);
    leftFront.setSpeed(i+motorOffset);
    leftBack.setSpeed(i+motorOffset); 
    delay(10);
  }
}

void moveForward()                                //Set all motors to run forward
{
  rightBack.run(FORWARD);
  rightFront.run(FORWARD);
  leftFront.run(FORWARD);
  leftBack.run(FORWARD);
}

void stopMove()                                   //Set all motors to stop
{
  rightBack.run(RELEASE);
  rightFront.run(RELEASE);
  leftFront.run(RELEASE);
  leftBack.run(RELEASE);
}

void turnLeft(int duration)                                 //Set motors to turn left for the specified duration then stop
{
  rightBack.setSpeed(motorSpeed+turnSpeed);                 //Set the motors to the motor speed
  rightFront.setSpeed(motorSpeed+turnSpeed);
  leftFront.setSpeed(motorSpeed+motorOffset+turnSpeed);
  leftBack.setSpeed(motorSpeed+motorOffset+turnSpeed);
  rightBack.run(FORWARD);
  rightFront.run(FORWARD);
  leftFront.run(BACKWARD);
  leftBack.run(BACKWARD);
  delay(duration);
  rightBack.setSpeed(motorSpeed);                           //Set the motors to the motor speed
  rightFront.setSpeed(motorSpeed);
  leftFront.setSpeed(motorSpeed+motorOffset);
  leftBack.setSpeed(motorSpeed+motorOffset);
  rightBack.run(RELEASE);
  rightFront.run(RELEASE);
  leftFront.run(RELEASE);
  leftBack.run(RELEASE);
  
}

void turnRight(int duration)                                //Set motors to turn right for the specified duration then stop
{
  rightBack.setSpeed(motorSpeed+turnSpeed);                 //Set the motors to the motor speed
  rightFront.setSpeed(motorSpeed+turnSpeed);
  leftFront.setSpeed(motorSpeed+motorOffset+turnSpeed);
  leftBack.setSpeed(motorSpeed+motorOffset+turnSpeed);
  rightBack.run(BACKWARD);
  rightFront.run(BACKWARD);
  leftFront.run(FORWARD);
  leftBack.run(FORWARD);
  delay(duration);
  rightBack.setSpeed(motorSpeed);                           //Set the motors to the motor speed
  rightFront.setSpeed(motorSpeed);
  leftFront.setSpeed(motorSpeed+motorOffset);
  leftBack.setSpeed(motorSpeed+motorOffset);
  rightBack.run(RELEASE);
  rightFront.run(RELEASE);
  leftFront.run(RELEASE);
  leftBack.run(RELEASE);
}

int getDistance()                                   //Measure the distance to an object
{
  unsigned long pulseTime;                          //Create a variable to store the pulse travel time
  int distance;                                     //Create a variable to store the calculated distance
  digitalWrite(trig, HIGH);                         //Generate a 10 microsecond pulse
  delayMicroseconds(10);
  digitalWrite(trig, LOW);
  pulseTime = pulseIn(echo, HIGH, timeOut);         //Measure the time for the pulse to return
  distance = (float)pulseTime * 340 / 2 / 10000;    //Calculate the object distance based on the pulse time
  return distance;
}

int checkDirection()                                            //Check the left and right directions and decide which way to turn
{
  int distances [2] = {0,0};                                    //Left and right distances
  int turnDir = 1;                                              //Direction to turn, 0 left, 1 reverse, 2 right
  servoLook.write(180);                                         //Turn servo to look left
  delay(500);
  distances [0] = getDistance();                                //Get the left object distance
  servoLook.write(0);                                           //Turn servo to look right
  delay(1000);
  distances [1] = getDistance();                                //Get the right object distance
  if (distances[0]>=200 && distances[1]>=200)                   //If both directions are clear, turn left
    turnDir = 0;
  else if (distances[0]<=stopDist && distances[1]<=stopDist)    //If both directions are blocked, turn around
    turnDir = 1;
  else if (distances[0]>=distances[1])                          //If left has more space, turn left
    turnDir = 0;
  else if (distances[0]<distances[1])                           //If right has more space, turn right
    turnDir = 2;
  return turnDir;
}

This is the full code

Is this the library you're using?

Did you see this note:

Before you go on, you need to fix this. You are using integer math so, "2*(maxDist+10)/100/340" == (320/100)/340 == 3/340 == 0.

Hi,
I assume this is the start of your thread;

Tom... :smiley: :+1: :coffee: :australia:

Dude the code is different

so what will this do and why should the *1000000 being removed??

Yes this is the LIbrary I am using. This is my other account from mobile since my pc is at home and I am in school now for testing there. And which library should I need to use for the motor driver l293d???

What @anon57585045 is showing is that as you work through the equation in integer mode, before you get to multiply by 1000000, the subtotal is zero, so the answer will be zero after you multiply by 1000000.

Tom... :smiley: :+1: :coffee: :australia:

So what should I have to do now PLS HELP I AM IN URGENT need

So it is a school/college/university project?

As you have changed your code, did you write code to just SIMPLY control the motor control board first, so as to prove you have control?

Also with the Ultrasonic sensor, have you got new code to prove it is functioning?

Tom.... :smiley: :+1: :coffee: :australia:

Okay, your request has been escalated to level alpha zulu. :slight_smile:

No I am making this project without controller, by making the servo attached to the sensor to turn and see which has more distance and move that side

Second account suspended.
We do not allow secondary accounts.

You have to make each component work correctly individually, prove they all work, then put it all together...

I know you are but;
As you have changed your code, did you write code to just SIMPLY control the motor control board first, so as to prove you have control?

Also with the Ultrasonic sensor, have you got new code to prove it is functioning?

A major code rewrite needs to go back to the beginning and check ALL basic I/O functions that you will use in your code.

Tom... :smiley: :+1: :coffee: :australia:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.