Code confusion

Hello,

I am new to these things but having fun.

http://www.instructables.com/id/How-to-Make-a-Web-Connected-Robot-for-about-500/

That's what I've been building and it seems fine mechanically, electrically and communicates over the network and web.

However, there is something fundamentally wrong with the code I will post below.

When I turn the thing on the wheels start to turn but go in opposite directions . Left goes backwards and right goes forwards.

I contacted these people but they did not reply.

http://www.oomlout.com/a/products/serb/

Does anyone have any idea whats wrong as I can't understand a lot .

Thanks

Stuart

P.S. I did change these settings to zero instead of 50 and 100 but it made no difference .

int leftSpeed = 50; //holds the speed of the robots leftServo
//a percentage between 0 and 100

int rightSpeed = 100; //holds the speed of the robots rightServo
//a percentage between 0 and 100

And here's the code attached.

Arduio Controlled Web Robot.txt (6.82 KB)

void loop() {
  serbPollSerialPort();		 //continuously looks to the serial port
						//if there is data it processes it
}

Calling just ONE function in loop() wastes time and resources. Why are you doing it?

    if ( dta = checkByte1){		 //Checks for first check byte

It does not. It assigns the first byte to dta, and tests whether dta is non-zero. Hardly what you want to be doing. Hint: == is not equal to =.

If you are using continuous rotation servos for driving, you should be using Servo::writeMicroseconds(), instead of Servo::write() to control them.

I'd check the power wiring for the servos. Check to make sure that they are both wired the same way. I suspect that they are not.

Yes that's correct, if you have wired both your motors the same way and send them the same data (direction and speed) then one will go clockwise and on will go anticlockwise.

Simple solution reverse the motor power connections for one of the motors.

Mark

and send them the same data (direction and speed)

Did you read the code? OP is NOT sending them the same data.

Thank you all for your replies.

I don't know why the code is like it is, I simply copied it . That's how I learn a little at a time. Copy then fiddle and observe the results.

The wiring is exactly as it says it should be. Positive to positive, negative to negative and the signal to 9 and 10 on the Arduino.

No other combination of this wiring is possible.

I thought this part is the part that makes the servos turn in opposite directions so the thing move forward.

leftServo.write(90 + leftSpeed);
rightServo.write(90 - rightSpeed);

I am at a loss .

Thank you

I thought this part is the part that makes the servos turn in opposite directions so the thing move forward.

leftServo.write(90 + leftSpeed);
rightServo.write(90 - rightSpeed);

It is. What you should do is Serial.print() the values of 90 + leftSpeed and 90 - rightSpeed, to see that they match your expectations.

Re-reading reply #1 wouldn't be a bad idea, either.