Making Bluetooth robot but servos move on their own, many other problems

So far I'm putting together a robot that I can control with my android phone. Thus far I've been able to somehow manage to write a code and I can control the robot wirelessly.
I am coming to you all to work out some kinks in the programming to make the operation very fluid.
In the code below I am only controlling the arduino's ability to stop, move forward or turn right at the push of a button or at the absence of a command.

#include <Servo.h>        // Servo library used

Servo servoLeft;          // Define left servo
Servo servoRight;         // Define right servo


 
int val = 0;     // variable to store the servo position

 


 
#include <SoftwareSerial.h>   //Software Serial Port

#define RxD 6
#define TxD 7
 
#define DEBUG_ENABLED  1
 
SoftwareSerial blueToothSerial(RxD,TxD);
 
void setup() 
{ 
  Serial.begin(9600);
  pinMode(RxD, INPUT);
  pinMode(TxD, OUTPUT);
  
  servoLeft.attach(9);  // Set left servo to digital pin 9
  servoRight.attach(10);  // Set right servo to digital pin 10
  setupBlueToothConnection();
  
 
} 
 
void loop() 
{ 
  char recvChar;
  while(1){
    if(blueToothSerial.available()){//check if there's any data sent from the remote bluetooth shield
      recvChar = blueToothSerial.read();
      Serial.print(recvChar);
      recvChar  = Serial.read();
         {val = Serial.read();}{ // read value coming in from phone
        if( val == 'Forward');   // If Forward button is pressed
        forward();}              // follow command sequence to move forward
    } else 
  {stopRobot();                  // do not move if no buttons are pressed
  }
}
{
  char recvChar;
  while(24){
    if(blueToothSerial.available()){//check if there's any data sent from the remote bluetooth shield
      recvChar = blueToothSerial.read();
      Serial.print(recvChar);
      recvChar  = Serial.read();
         {val = Serial.read();}{  // read value coming in from phone
        if( val == 'Right');  // If right button is pressed
        {
  turnRight();                  // follow command sequence to turn right
}
}         
    } else 
  {stopRobot();                 // do not move if no buttons are pressed
  }
}
               
}}
     
    


 
void setupBlueToothConnection()
{
  blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
  blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
  blueToothSerial.print("\r\n+STNA=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave"
  blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
  blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
  delay(2000); // This delay is required.
  blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable 
  Serial.println("The slave bluetooth is inquirable!");
  delay(2000); // This delay is required.
  blueToothSerial.flush();
}
  // Motion routines for forward, reverse, turns, and stop
void forward() {
    servoLeft.write(0);
  servoRight.write(180);
}

void reverse() {
  servoLeft.write(180);
  servoRight.write(0);
}

void turnRight() {
  servoLeft.write(180);
  servoRight.write(180);
}
void turnLeft() {
  servoLeft.write(0);
  servoRight.write(0);
}

void stopRobot() {
  servoLeft.write(90);
  servoRight.write(90);
}

Here is what I WANT it to do.

  • Move forward at the push of the onscreen "Forward" button on my phone
  • Turn right at the push of the onscreen "Right" button on my phone
  • Turn left at the push of the onscreen "Left" button on my phone
  • Move Reverse at the push of the onscreen "Reverse button on my phone
  • Stop at the push of the onscreen "Stop" button on my phone
  • Do nothing until a command is received from phone

Here is what it is doing right now

  • Turns in place infinitely at a slow speed until command is received
  • Moves forward for about 2 seconds then begins turning in place again (when command is received)
  • Robot only moves forward no matter what command is received

Things I've tried so far

+Using different PWM pins 3,5,6, and 11
+adding delays in random locations

  • Use direct coding instead of void referencing
  • Changing the values of the servos in the parenthesis

Hardware

Arduino Duemilanove AtMega 328
Bluetooth shield from trossen robotics http://www.seeedstudio.com/wiki/index.php?title=Bluetooth_Shield
Servos from parallax kit (they just say "continuous rotation" but the specs are somewhere on their site)
Android Phone (T-mobile g2)
Application on phone: Bluetooth SPP <- Great app by the way!

  pinMode(RxD, INPUT);
  pinMode(TxD, OUTPUT);

You told the SoftwareSerial instance that these were it's pins. Why are you diddling with them?

Putting each { and } on it's own line, and using Tools + Auto Format is really going to be necessary to make that code readable. Deleting unnecessary curly braces would help to, as would reducing the number of blank lines.

It isn't clear why you have an infinite loop inside loop().

I pasted your code into the 1.0 IDE, and use Tools + Auto Format, and deleted a lot of useless braces, and I see this:

    if(blueToothSerial.available())
    {//check if there's any data sent from the remote bluetooth shield
      recvChar = blueToothSerial.read();
      Serial.print(recvChar);
      recvChar  = Serial.read();
      val = Serial.read();
      if( val == 'Forward');   // If Forward button is pressed
        forward();
    }

If there is at least one character to be read, read two, and see if the second character equals "Forward". Since val contains a single character, and is the address of a variable, that address will never equal the string "Forward". Even if you change to use the correct function to perform the comparison, one character is never going to equal a string.

Back to the drawing board...

the pinMode part was included in the example for bluetooth communication in the link I posted. I thought it was vital and decided not to mess with it.

thanks for the suggestion

also I noticed the servos move on their own as soon as I put something along the lines of
myservo.attach(9);

I've tried it using a blank code and it still moves. Is this correctable?

I've tried it using a blank code and it still moves. Is this correctable?

Yes. You can write to the servo before attaching it. When you attach it, it will move the the last written position, and stop. If you have real servos, that is.

I don't suspect that you do.