Obstacle avoiding Rickshaw question

Hey yaw, im new to arduino but ive been trying to program my rickshaw to avoid obstacles and just keep walking forever. I have four HC-SR04 sensors attached to the front,back,left,right of the rickshaw to detect any object. I also have two servo motors one for moving forwards and backwards and the other for moving left and right.

I've tried building this code but i am getting a compiling error, If anyone can help me out and see where im going wrong with this that would be greatly appreciated

Here's the code so far

Current error(expected initializer before 'servoDrive'

//In this project, we will be using 4 ultrasonic ranging
//sensors to control the direction of the motor and drive of the motor.

#include <Servo.h>
#include <NewPing.h> // don't forget to include the NewPing library.

#define SONAR_NUM   4

Servo servoDrive;          // Define left servo
Servo servoDirection;         // Define right servo

NewPing SonarFront(13, 12, 400);// In the project, this was the sensor that
//was used on the right side of the breadboard
NewPing SonarLeft(7, 6, 400);// In the project, this was the sensor that
//was used on the left side of the breadboard
NewPing SonarRight(23, 22, 400);// In the project, this was the sensor that
//was used on the right side of the breadboard
NewPing SonarBack(43, 42, 400);// In the project, this was the sensor that
//was used on the left side of the breadboard
 
void setup() { 
  servoDrive.attach(18);  // Set left servo to digital pin 10
  servoDirection.attach(14);  // Set right servo to digital pin 9

}
void loop() 

{
  unsigned int uS1 = SonarFront.ping(); // activates the first sensor
  delay(50); // wait 50ms
   unsigned int uS2 = SonarBack.ping(); // activate the fourth sensor
  delay(50); // wait 50ms
  unsigned int uS4 = SonarLeft.ping(); // activate the second sensor
  delay(50); // wait 50ms
  unsigned int uS3 = SonarRight.ping(); // activates the third sensor
  delay(50); // wait 50ms
  

 
  // We will declare "if" statements to control the relay module, 
  // which controls the motor. 

  if (uS1 / US_ROUNDTRIP_CM < 20) { //if an object is less than 20 cm away
    //from the front sensor, 
   void reverse() 
   servoDrive.write(0);
   servoDirection.write(180);
    //the motor will rotate forward.
  }
  if (uS1 / US_ROUNDTRIP_CM > 20) { //if an object is greater than 20 cm away
    //from the back sensor, 
   void forward() 
  servoDrive.write(180);
  servoDirection.write(0);
    //the motor will rotate backwards.
  

  }

 if (uS2 / US_ROUNDTRIP_CM < 20) { //if an object is less than 20 cm away
    //from the back sensor, 
   void forward() 
  servoDrive.write(180);
  servoDirection.write(0);
    //the motor will rotate backwards.
  
 }

 if (uS3 / US_ROUNDTRIP_CM < 20) { //if an object is less than 20 cm away
    //from the back sensor, 
  void turnLeft() 
  servoDrive.write(0);
  servoDirection.write(0);
    //the motor will rotate left
 
 }

 if (uS4 / US_ROUNDTRIP_CM < 20) { //if an object is less than 20 cm away
    //from the back sensor, 
  void turnRight() 
  servoLeft.write(180);
  servoRight.write(180);
    //the motor will rotate right
  

 }

}

Rickshawcode.ino (2.51 KB)

Here is a picture of the rickshaw for a better visualization of the project

Rickshaw

Im also using an Arduino Mega Sensor Shield v2

Sensor shield

void reverse() 
   servoDrive.write(0);

oops

'

AWOL:

void reverse() 

servoDrive.write(0);


oops

Im getting an error saying

expected initializer before 'servoDrive'

I know. That's why I highlighted the error for you.
Here it is again

  if (uS1 / US_ROUNDTRIP_CM < 20) { //if an object is less than 20 cm away
    //from the front sensor, 
   void reverse() 
   servoDrive.write(0);
   servoDirection.write(180);

(Please don't PM me - read the signature)

What do you think that:

    void reverse()

is doing?

//In this project, we will be using 4 ultrasonic ranging
//sensors to control the direction of the motor and drive of the motor.

#include <Servo.h>
#include <NewPing.h> // don't forget to include the NewPing library.

#define SONAR_NUM   4

Servo servoDrive;          // Define left servo
Servo servoDirection;         // Define right servo

NewPing SonarFront(13, 12, 400);// In the project, this was the sensor that
//was used on the right side of the breadboard
NewPing SonarLeft(7, 6, 400);// In the project, this was the sensor that
//was used on the left side of the breadboard
NewPing SonarRight(23, 22, 400);// In the project, this was the sensor that
//was used on the right side of the breadboard
NewPing SonarBack(43, 42, 400);// In the project, this was the sensor that
//was used on the left side of the breadboard
 
void setup() { 
  servoDrive.attach(18);  // Set left servo to digital pin 10
  servoDirection.attach(14);  // Set right servo to digital pin 9

}
void loop() 

{
  unsigned int uS1 = SonarFront.ping(); // activates the first sensor
  delay(50); // wait 50ms
   unsigned int uS2 = SonarBack.ping(); // activate the fourth sensor
  delay(50); // wait 50ms
  unsigned int uS3 = SonarRight.ping(); // activates the third sensor
  delay(50); // wait 50ms
   unsigned int uS4 = SonarLeft.ping(); // activate the second sensor
  delay(50); // wait 50ms

 
  // We will declare "if" statements to control the relay module, 
  // which controls the motor. 

  if (uS1 / US_ROUNDTRIP_CM < 20) { //if an object is less than 20 cm away
    //from the front sensor, 
   servoDrive.write(0);
   servoDirection.write(180);
   
    //the motor will rotate forward.
  }
  if (uS1 / US_ROUNDTRIP_CM > 20) { //if an object is greater than 20 cm away
    //from the Front sensor, 
  servoDrive.write(180);
  servoDirection.write(0);
    //the motor will rotate backwards.
  

  }

 if (uS2 / US_ROUNDTRIP_CM < 20) { //if an object is less than 20 cm away
    //from the back sensor, 
 
  servoDrive.write(180);
  servoDirection.write(0);
    //the motor will rotate backwards.
  
 }

 if (uS3 / US_ROUNDTRIP_CM < 20) { //if an object is less than 20 cm away
    //from the right sensor, 
  servoDrive.write(0);
  servoDirection.write(0);
    //the motor will rotate left
 
 }

 if (uS4 / US_ROUNDTRIP_CM < 20) { //if an object is less than 20 cm away
    //from the left sensor, 
  servoLeft.write(180);
  servoRight.write(180);
    //the motor will rotate right
  

 }

}

I took away the voids but im still getting errors

I took away the voids but im still getting errors

But not sharing them.

What Servo instances have you defined? Which instances are you trying to control?

You can't just make sh*t up as you go and expect it to work.