Bot Doesn't Seem to Want to Run on Auto Pilot vs PS3 Controlled

Checked the code, I have no errors when compiling. So why doesn’t the bot want to run via the Ultrasonic?

#include <PS3BT.h>

int pinI1=8;//define I1 interface, Motor Pin
int pinI2=11;//define I2 interface, Motor Pin 
int speedpinA=9;//enable Motor A
int pinI3=12;//define I3 interface 
int pinI4=13;//define I4 interface 
int speedpinB=10;//enable ignition
int speed =1000;//define the spead of motor
const int pingPin=7;//UltraSonic Sensor Pin. let it be noted that const means constant
int servopin = 4;//Servo 1's Pin
int servopin2 = 5;
int servopin3 = 6;
int pulse = 1500;//Servo
USB Usb;
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
/* You can create the instance of the class in two ways */
PS3BT PS3(&Btd); // This will just create the instance
//PS3BT PS3(&Btd,0x00,0x15,0x83,0x3D,0x0A,0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch

boolean printTemperature;
boolean printAngle;

void setup() 
{
  Serial.begin(9600); //initializes serial communication
  pinMode(pinI1,OUTPUT);
  pinMode(pinI2,OUTPUT);
  pinMode(speedpinA,OUTPUT);
  pinMode(servopin, OUTPUT);
  pinMode(servopin2, OUTPUT);
  pinMode(servopin3, OUTPUT);
  Serial.begin(115200);
  if (Usb.Init() == -1) 
  {
    Serial.print(F("\r\nOSC did not start"));
    while(1); //halt
  }
  Serial.print(F("\r\nPS3 Bluetooth Library Started"));
}

void Forward()
{
  analogWrite(speedpinA,speed);//input a simulation value to set the speed
  digitalWrite(pinI2,LOW);
  digitalWrite(pinI1,HIGH);
}

void Backward()//
{
  analogWrite(speedpinA,speed);//input a simulation value to set the speed
  digitalWrite(pinI2,HIGH);
  digitalWrite(pinI1,LOW);
}

void Stop()
{
  digitalWrite(speedpinA, LOW);
  delay(1000);
}

void Servo_Motor_Turn()
{  
  digitalWrite(servopin, HIGH);
  delayMicroseconds(pulse);
}

void Servo_Motor_UnTurn()
{
  digitalWrite(servopin, LOW);
  delayMicroseconds(pulse);
}

void Servo_Lift()
{
  digitalWrite(servopin2, HIGH);
  delayMicroseconds(pulse);
}

void Servo_UnLift()
{
  digitalWrite(servopin2, LOW);
  delayMicroseconds(pulse);
}

void Servo_Swivel()
{
  digitalWrite(servopin3, HIGH);
  delayMicroseconds(pulse);
}

void Servo_UnSwivel()
{
  digitalWrite(servopin3, LOW);
  delayMicroseconds(pulse);
}

long Sensor_loop()//this funtion is going to need to be played with
{
  long microseconds, inches;//establishes variables: duration(microseconds) and distance(inches)

  //the next little bit is to initiate Pulse(HIGH) for 2 or more microseconds. Sends LOW pulse beforehand to ensure a clean HIGH pulse
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);
  pinMode(pingPin, INPUT);
  microseconds=pulseIn(pingPin, HIGH);

  //code to convert time to distance
  inches= long (microseconds/74/2);
  //code to print distance values
  Serial.print(inches);
  Serial.print("in, ");
  return inches;

  delay(100);
}

void Ignition()
{
  analogWrite(speedpinA,speed);//input a simulation value to set the speed
  digitalWrite(pinI2,LOW);
  digitalWrite(pinI1,HIGH);
}

void loop() 
{
  Usb.Task();

  if(PS3.PS3Connected || PS3.PS3NavigationConnected) 
  {
    if(PS3.getAnalogHat(LeftHatX) > 137 || PS3.getAnalogHat(LeftHatX) < 117 || PS3.getAnalogHat(LeftHatY) > 137 || PS3.getAnalogHat(LeftHatY) < 117 || PS3.getAnalogHat(RightHatX) > 137 || PS3.getAnalogHat(RightHatX) < 117 || PS3.getAnalogHat(RightHatY) > 137 || PS3.getAnalogHat(RightHatY) < 117 || PS3.getAnalogButton(R2) > 0)
    {
      if(Serial.print(PS3.getAnalogHat(LeftHatX)) > 0)
      {
        Servo_Motor_UnTurn();
      }
      if (Serial.print(PS3.getAnalogHat(LeftHatX)) < 0)
      {
        Servo_Motor_Turn();
      }
      if (Serial.print(PS3.getAnalogHat(LeftHatY)) > 0)
      {
        Forward();
      }
      if (Serial.print(PS3.getAnalogHat(LeftHatY)) < 0)
      { 
        Backward();
      }
      if (Serial.print(PS3.getAnalogHat(LeftHatY)) == 0)
      {
        Stop();
      }
      if(Serial.print(PS3.getAnalogHat(RightHatX)) > 0)
      {
        Servo_Swivel();
      }
      if (Serial.print(PS3.getAnalogHat(RightHatX)) < 0)
      {
        Servo_UnSwivel();
      }
      if (Serial.print(PS3.getAnalogHat(RightHatY)) > 0)
      {
        Servo_Lift();
      }
      if (Serial.print(PS3.getAnalogHat(RightHatY)) < 0)
      { 
        Servo_UnLift();
      }
      if (Serial.print(PS3.getAnalogButton(R2)) > 0)
      {
        Ignition();
      }
    }
  }
  else
  {
    long inches = Sensor_loop();
    {
      if (inches>6)
      {
        Forward();
        delay(2000);
      }

      else if (inches<=6)
      {
        Stop();
        Servo_Motor_Turn();
        Backward();
        delay(2000);
        Stop();
        Servo_Motor_UnTurn();
        delay(2000);
        Stop();
      }
    }
  }
}

What is. Ultrasonic.

What do you mean by bot.

It's a four wheeled bot that travels within 6in of an object then backs up and turn, IF the PS3 remote isn't connected. Unfortunately it only wants to take commands from JUST the remote, which isn't connected at the moment.

And the ultrasonic is a sensor that uses ultrasonic sound as a range finder

https://fbcdn-sphotos-d-a.akamaihd.net/hphotos-ak-xfp1/t1.0-9/10599574_10154479738660643_244676574313200716_n.jpg