4wd rover with legs

It looks like the Baud rate on the SSC-32 is physically set to 115.2, whereas your code is trying to communicate with it at 9600.
Refer to section 9 here regarding baud rate: lynxmotion.com/images/html/build136.htm

Next, you need to understand Arduino programming; your code is using serial (associated with pins 0 and 1 on the BotBoarduino), whereas your conections seem to show those two digital pins are empty, and the SSC-32 is connected to digital pins 12 or 13. This means you have it configured for soft serial. More information about software serial can be found on the Arduino site:
arduino.cc/en/Reference/Software … onstructor

Hope this helps,

Also, in your setup, confirm that the Tx pin from the BotBoarduino connects to the Rx pin on the SSC-32 (can’t quite tell from the last image).

Hi everyone,

little update, I was able to connect to the sabertooth from the botboarduino, got RR to run autonomous.

Sorry no video,

So then I moved on working on RR arms

Here I was using visual sequencer to testing concept. Passing object from one arm to the other.

Thing was going smoothly, I installed my PS2 controller kit, download the PS2 library.

I got the example code from GitHub, with little changed to the code ( mostly the Servo Pin #) I got to control one of RR arm. However , now is the problem,

when I try to change the PS2 code (after do study about the code. ) to control RR wheel , however nothing was moving .

So I try to use botboarduino to run RR autonomous by using the code that i had before. But nothing happen now.

please help. here is the current set up and baud 9600

http://i113.photobucket.com/albums/n237/khangtnguyen2012/IMG_1246_zpse55f0aff.jpg

I’m not sure, but didn’t your setup before used to use an SSC-32 board?

Yes sir, and i think it could be one of the possible problem.

Here is the code I use to control SS autonomous

[code] const int RForward = 94;
const int RBackward = 34 ;
const int RightTurnForward = 125;
const int RightTurnBackward = 1;

const int LForward = 212;
const int LBackward = 162;
const int LeftTurnForward = 255;
const int LeftTurnBackward = 128;
const int RNeutral = 64;
const int LNeutral = 192;
const int pingPin = 13 ;
const int dangerThresh = 15; //threshold for obstacles in cm

int leftDistance, rightDistance;

long duration;

void setup()
{
Serial.begin(9600);

}

void loop()
{
int distanceFwd = ping();
if (distanceFwd>dangerThresh) // if path clear
{
Serial.write(LForward);
Serial.write(RForward);
}
else // path is block
{
Serial.write(LNeutral);
Serial.write(RNeutral);
delay (2000);

Serial.write(LeftTurnForward); //turn right
Serial.write(RightTurnBackward);
delay(300);

rightDistance = ping(); // sacanning
delay(500);

Serial.write(RightTurnForward);
Serial.write(LeftTurnBackward);
delay(300);

leftDistance = ping();
delay(500);

Serial.write(LeftTurnForward);
Serial.write(RightTurnBackward);
delay(300);

compareDistance ();
}
}

void compareDistance()
{
if (leftDistance>rightDistance) //if left less obstructed
{
Serial.write(LeftTurnBackward);
Serial.write(RightTurnForward);
delay(300); //turn left
}
else if (rightDistance>leftDistance) // if the right less obstructed
{
Serial.write(LeftTurnForward);
Serial.write(RightTurnBackward);
delay(300); //turn right
}
else // if there are equal obstructed
{
Serial.write(LeftTurnForward);
Serial.write(RightTurnBackward);
delay(350); // turn 180 degree
}
}

long ping()
{
//send out ping singnal pulse

pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);

//get duration it take to receive echo

pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);

//convert duration into distance

return duration / 29 /2;
}[/code]

And here is the code I use to control RR arm.

So I have connect the PS2 bluetooth kit and using this code to control

[code]
#include <SoftwareSerial.h>
#include <PS2X_lib.h>

#define DEBUG

#define DBGSerial Serial
SoftwareSerial SSCSerial(13, 12);

//comment to disable the Force Sensitive Resister on the gripper
//#define FSRG

//FSRG pin Must be analog!!
#define FSRG_pin A1

//uncomment for digital servos in the Shoulder and Elbow
//that use a range of 900ms to 2100ms
//#define DIGITAL_RANGE

//Select which arm by uncommenting the corresponding line
//#define AL5A
//#define AL5B
#define AL5D

#ifdef AL5A
const float A = 3.75;
const float B = 4.25;
#elif defined AL5B
const float A = 4.75;
const float B = 5.00;
#elif defined AL5D
const float A = 5.75; // distance between shoulder axis and elbow axis in inches
const float B = 7.375;// distance between elbow axis and wrist axis in inches
#endif

//PS2 pins connected to BotBoarduino
#define DAT 6
#define CMD 7
#define ATT 8
#define CLK 9

//PS2 analog joystick Deadzone
#define Deadzone 10

//Math constants
const float rtod = 57.295779;
const float atop = 11.111;

//Arm Speed Variables
float Arm_Speed = 1.0;
int Arm_sps = 3;

//Arm Current Pos
float X = 4;
float Y = 4;
int Z = 1500;
int G = 1500;
int WR = 1500; // wrist rotate default position
float WA = 0;

//Arm temp pos
float tmpx = 4;
float tmpy = 4;
int tmpz = 1500;
int tmpg = 1500;
int tmpwr = 1500;
float tmpwa = 0;

PS2X ps2x;

boolean mode = true;

void setup()
{
DBGSerial.begin(57600);
SSCSerial.begin(38400);
pinMode(7, INPUT);
pinMode(5, OUTPUT);
if(!digitalRead(7))
{
tone(5, 1000, 500);
SSCForwarder();
}

// SSC-32 debugging
int error = 0;
error = ps2x.config_gamepad(CLK,CMD,ATT,DAT, true, true); //setup pins and settings: GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error

#ifdef DEBUG
if(error == 0)
DBGSerial.println(“Found Controller, configured successful”);

else if(error == 1)
DBGSerial.println(“No controller found”);

else if(error == 2)
DBGSerial.println(“not accepting commands”);

else if(error == 3)
DBGSerial.println(“refusing Pressures mode”);

byte type = 0;
type = ps2x.readType();
switch(type)
{
case 0:
DBGSerial.println(“Unknown”);
break;
case 1:
DBGSerial.println(“DualShock”);
break;
case 2:
DBGSerial.println(“GuitarHero”);
break;
}
#endif

}

void SSCForwarder()
{
delay(2000);
int sChar;
int sPrevChar;

while(digitalRead(7)) {
if ((sChar = DBGSerial.read()) != -1) {
SSCSerial.write(sChar & 0xff);
if (((sChar == ‘\n’) || (sChar == ‘\r’)) && (sPrevChar == ‘$’))
break; // exit out of the loop
sPrevChar = sChar;
}
if ((sChar = SSCSerial.read()) != -1) {
DBGSerial.write(sChar & 0xff);
}
}
}

int Arm(float x, float y, float z, int g, float wa, int wr) //Here’s all the Inverse Kinematics to control the arm
{
float M = sqrt((yy)+(xx)); // radial length between the base axis and the gripper axis
if(M <= 0) // if the angle is less than 0, do not attempt to move there
return 1;
float A1 = atan(y/x); // The calculation above determines the angle between the horizontal and the angle formed between the shoulder axis and the wrist axis.
if(x <= 0) // if the angle is less than 0, do not attempt to move there
return 1;
float A2 = acos((AA-BB+MM)/((A2)M)); // This is the angle between the line formed between the shoulder axis and the wrist axis and the line formed between the shoulder and elbow
float Elbow = acos((A
A+BB-MM)/((A*2)B)); // This is the angle between the line formed between the elbow axis and the shoulder axis and the line formed between the elbow axis and the wrist axis
float Shoulder = A1 + A2; // This is the angle between the horizontal and the line formed between the shoulder axis and the elbow axis
Elbow = Elbow * rtod;
Shoulder = Shoulder * rtod;
while((int)Elbow <= 0 || (int)Shoulder <= 0) // if the angle is less than 0, do not attempt to move there
return 1;
float Wrist = abs(wa - Elbow - Shoulder) + 7.50; // the wrist is not included in the above calculations and is set at a predetermined angle w.r.t. the horizontal.
#ifdef DIGITAL_RANGE
Elbow = map((180 - Elbow) * atop, 500, 2500, 900, 2100); // convert the angle to pulse for the elbow
Shoulder = map(Shoulder
atop + 500, 500, 2500, 900, 2100); //convert the angle to pulse for the shoulder
#else
Elbow = (180 - Elbow) * atop;
Shoulder = Shoulder * atop + 500;
#endif
Wrist = (180 - Wrist) * atop + 500;
SSCSerial.print(" #26, P");
SSCSerial.println(z);
SSCSerial.print(" #27, P");
SSCSerial.print(Shoulder);
SSCSerial.print(" #28, P");
SSCSerial.print(Elbow);
SSCSerial.print(" #29, P");
SSCSerial.print(Wrist);
#ifndef FSRG // force sensor
SSCSerial.print(" #14 P");
SSCSerial.print(g);
#endif // wrist rotate
SSCSerial.print(" #31 P");
SSCSerial.print(wr);
SSCSerial.println();

Y = tmpy;
X = tmpx;
Z = tmpz;
WA = tmpwa;

#ifndef FSRG
G = tmpg;
#endif
WR = tmpwr;
return 0;
}

//2joy sticks control
void Arm_mode()
{
int LSY = 128 - ps2x.Analog(PSS_LY); // reading analog values from controller
int LSX = ps2x.Analog(PSS_LX) - 128;
int RSX = 128 - ps2x.Analog(PSS_RX);
int RSY = ps2x.Analog(PSS_RY) - 128;

if(RSY > Deadzone || RSY < -Deadzone)
tmpy = max(Y + RSY/1000.0*Arm_Speed, -1);

if(RSX > Deadzone || RSX < -Deadzone)
tmpx = max(X + RSX/1000.0*Arm_Speed, -0.5);

if(LSY > Deadzone || LSY < -Deadzone)
tmpwa = constrain(WA + LSY/100.0*Arm_Speed, 0, 180);

if(LSX > Deadzone || LSX < -Deadzone)
tmpz = constrain(Z + LSX/10.0*Arm_Speed, 500, 2500);

// Right one button
if(ps2x.Button(PSB_R1))
{
#ifdef FSRG // if force sensor is used
int gPos;
int reading;
SSCSerial.println(“QP 31”);
while(SSCSerial.available() == 0)
delay(1);
gPos = SSCSerial.read() * 10;
SSCSerial.println(“VC”);
while(SSCSerial.available() == 0)
delay(1);
reading = SSCSerial.read();
while(reading < 50 && gPos < 2400)
{
gPos += 10;
SSCSerial.print("#31 P");
SSCSerial.println(gPos);
SSCSerial.println(“VC”);
while(SSCSerial.available() == 0)
delay(1);
reading = SSCSerial.read()
}
#else
tmpg = constrain(G + 20*Arm_Speed, 500, 2500);
#endif
}

//Right two button
if(ps2x.Button(PSB_R2))
{
#ifdef FSRG
int gPos;
SSCSerial.println(“QP 18”);
while(SSCSerial.available() == 0)
delay(1);
gPos = SSCSerial.read() * 10;
while(gPos > 1500)
{
SSCSerial.print("#18 P");
SSCSerial.println(gPos);
gPos -= 50;
}
#else
tmpg = constrain(G - 20*Arm_Speed, 1500, 2400);
#endif
}

//Left one button
if(ps2x.Button(PSB_L1))
tmpwr = max(WR + 20Arm_Speed, 500);
else if(ps2x.Button(PSB_L2))
tmpwr = min(WR - 20
Arm_Speed, 2500);

// up button
if(ps2x.ButtonPressed(PSB_PAD_UP))
{
Arm_sps = min(Arm_sps + 1, 5);
tone(5, Arm_sps200, 200);
}
else if(ps2x.ButtonPressed(PSB_PAD_DOWN)) // down button
{
Arm_sps = max(Arm_sps - 1, 1);
tone(5, Arm_sps
200, 200);
}

Arm_Speed = Arm_sps*0.20 + 0.60;

if(Arm(tmpx, tmpy, tmpz, tmpg, tmpwa, tmpwr))
{
#ifdef DEBUG
DBGSerial.print(“NONREAL Answer”);
#endif
}

if(tmpx < 2 && tmpy < 2 && RSX < 0)
{
tmpy = tmpy + 0.05;
Arm(tmpx, tmpy, tmpz, tmpg, tmpwa, tmpwr);
}
else if(tmpx < 1 && tmpy < 2 && RSY < 0)
{
tmpx = tmpx + 0.05;
Arm(tmpx, tmpy, tmpz, tmpg, tmpwa, tmpwr);
}

}

void loop()
{
ps2x.read_gamepad(); //update the ps2 controller
Arm_mode();
delay(30);
}[/code]

Sorry I don’t have much time to go over this, but one thing I am wondering about, is in the Autonomous case, the main loop make a call to ping, which tries to do a pulsein on pin 13, which I don’t think you currently have anything connected to. So the code may simply be hung here…

Kurt

P.S. - Hope you don’t mind, but I put your two programs in code tags to make it easier to read (keeps indents and the like.

Thanks Kurt for putting the Code tags: that helps a lot!

@BipeScoutK: seems like your first code (autonomous) is made to control the Sabertooth directly through simplified serial connection at 9600 to the BotBoarduino’s Serial port. The dips of the Sabertooth are properly configured, but I don’t think the S1 of the Sabertooth is connected to the right place: it should be connected to the TX pin of the BotBoarduino, but it seems like it is connected to pin 2 or 3 instead. Is that possible? (It’s hard to tell from the photo.)

For comparison, your second code (PS2) does use the SSC-32 board, at 34800 baud, connected to pins 12 and 13.

Hi everyone, I haven’t been active due to schooling, however I am back. lol

I still strangling with the Ping sensor.

here is the simple reading distance code

[code]const int pingPin = 7;

void setup() {
// initialize serial communication:
Serial.begin(9600);
}

void loop()
{

// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, inches, cm;

// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short 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);

// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);

// convert the time into a distance
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);

Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print(“cm”);
Serial.println();

delay(100);
}

long microsecondsToInches(long microseconds)
{
// According to Parallax’s datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}
[/code]

but the vaule come back only 0inc 0 cm

And here is the connection

Did I miss a jumper ? and why the red LED turn on ?

HElP :slight_smile::):):slight_smile:

PS: miss every one.
http://i105.photobucket.com/albums/m237/khang_nguyen4/1_zps3b966596.jpg

Welcome back! Are you using pin 7 for the ping sensor? Pin 7 is normally connect to a button and that red LED, so that might be causing problems. Try removing the JA jumper (item 5 in the manual) to see if that helps, and let us know the results.

Hope this helps,

Thank you Jarcand, and everyone. Feel good to be back with the cummunity. Lol
I will definitely try that tonight. :slight_smile: :slight_smile: :slight_smile:

Yeah. The sensor read valid value now.

My next question would be coding.

[code]#include<Servo.h>

////////////////////////////////////////

class Ultrasonic
{
public:
Ultrasonic(int pin);
void DistanceMeasure(void);
long microsecondsToCentimeters(void);
long microsecondsToInches(void);
private:
int _pin;//pin number of Arduino that is connected with SIG pin of Ultrasonic Ranger.
long duration;// the Pulse time received;
};
Ultrasonic::Ultrasonic(int pin)
{
_pin = pin;
}
/Begin the detection and get the pulse back signal/
void Ultrasonic::DistanceMeasure(void)
{
pinMode(_pin, OUTPUT);
digitalWrite(_pin, LOW);
delayMicroseconds(2);
digitalWrite(_pin, HIGH);
delayMicroseconds(5);
digitalWrite(_pin,LOW);
pinMode(_pin,INPUT);
duration = pulseIn(_pin,HIGH);
}
/The measured distance from the range 0 to 400 Centimeters/
long Ultrasonic::microsecondsToCentimeters(void)
{
return duration/29/2;
}
/The measured distance from the range 0 to 157 Inches/
long Ultrasonic::microsecondsToInches(void)
{
return duration/74/2;
}

Ultrasonic ultrasonic(7);

////////////////////////////////////////////////////////////////////////////////////

// f’(LM) > 0 @ D f’(LM)] = [100,150]
// f’(LM) < 0 @ D[f’(LM)] = [100,30]

const int RForward = 30;
const int RBackward = 160;

// f’(RM) > 0 @ D f’(RM) ] = 100, 30]
// f’(RM) < 0 @ D f’(RM0 ] = 100,160]
const int LForward = 157;
const int LBackward = 30;

//simply out of domain
const int LNutral = 10;
const int RNutral = 230;

//
Servo servoleft;
Servo servoright;

int RangeInInches;

long randNumber;

void setup(){

Serial.begin(9600);

servoleft.attach(3);
servoright.attach(4);

}

void loop()

{
long RangeInInches;
long RangeInCentimeters;
ultrasonic.DistanceMeasure();// get the current signal time;
RangeInInches = ultrasonic.microsecondsToInches();//convert the time to inches;
RangeInCentimeters = ultrasonic.microsecondsToCentimeters();//convert the time to centimeters
Serial.println(“The distance to obstacles in front is: “);
Serial.print(RangeInInches);//0~157 inches
Serial.println(” inch”);
Serial.print(RangeInCentimeters);//0~400cm
Serial.println(" cm");
delay(1000);

/////////////////////////////////////////////////////////////////////////////

if (RangeInInches> 90 ) {

servoleft.write(LForward); // move forward
servoright.write(RForward);

}

else {

servoleft.write (RBackward); // backward
servoright.write(LBackward);

}

delay(1000);

}
[/code]

I think I miss int something, but isn’t it " RangeInInches" is my condition for servoleft and servo right to take action ???

:smiley:
:smiley:
:smiley:

Yes, that should be working. Is your robot only moving backwards? What information are you seeing in the Serial Monitor?

The value change as I move my hand in front of the ping sensor, however the direction of rover won’t chang. What I try to say here is , the rover seen didn’t react to the change of RangeInInches.

On the serial monitor , it return " the value ahead in inches is #value".

Thank Jarcand.

Aha! There’s a small/silly error in your code: The values for left and right are mixed up for the backwards direction…

  servoleft.write (RBackward); // backward
  servoright.write(LBackward);

should instead be:

  servoleft.write (LBackward); // backward
  servoright.write(RBackward);

OKi , i am getting to the final week so everything is chaos right now. However i found some free time for my robot.

I do more research and come up with this code. After successfully verifying the code :slight_smile:. i uploaded into my Rover using Botboarduino 328 :smiley:.

The board light flashing as the code got upload into the brain :slight_smile:, i thought because the code a little long so the board jut took a little longer :astonished:.

After it took quite a bit, my most fear come true :open_mouth:, the board stuck in some kind of loop and keep try to comply the code :cry:.

I already try to reset the Botboarduino manually, however the light stop flashing when i press it and back to flashing as soon as i release the reset button:?.

Please help . :unamused: :neutral_face::arrow::mrgreen:

[code]#include<Servo.h>

#define MAX_DISTANCE 200
#define runEvery(t) for (static typeof(t) _lasttime;(typeof(t))((typeof(t))millis() - _lasttime) > (t);_lasttime += (t))

// f’(LM) > 0 @ D f’(LM)] = [100,150]
// f’(LM) < 0 @ D[f’(LM)] = [100,30]

const int RForward = 30;
const int RBackward = 160;

// f’(RM) > 0 @ D f’(RM) ] = 100, 30]
// f’(RM) < 0 @ D f’(RM0 ] = 100,160]
const int LForward = 157;
const int LBackward = 30;

//simply out of domain
const int LNutral = 10;
const int RNutral = 230;

// Value for of Ultrasonic Sensor
int uS1;
int uS2;

//distance in cm of ultrasonic sensor
int distance;

//start position of servo = 90
int pos = 90;

// sweeping left or right
int servoDirection = 0;

// 0 = forward, 1 = backward, 2= left, 3 = right
int robotDirection = 0;

// last direction of the robot
int lastRobotDirection;

int distanceCenter;
int distanceLeft;
int distanceRight;

// with this parameter you can change the speed of the servo
int servoDelay = 20;

long previousMillis = 0;

//interval to switch between the robotDirection, this value will determine how long th robot willturn lef or right
// when the robot detects an obstacle
const int interval = 650;

//
Servo servoleft;
Servo servoright;
Servo servoSensor;

int RangeInInches;

////////////////////////////////////////

class Ultrasonic
{
public:
Ultrasonic(int pin);
void DistanceMeasure(void);
long microsecondsToCentimeters(void);
long microsecondsToInches(void);
private:
int _pin;//pin number of Arduino that is connected with SIG pin of Ultrasonic Ranger.
long duration;// the Pulse time received;
};
Ultrasonic::Ultrasonic(int pin)
{
_pin = pin;
}
/Begin the detection and get the pulse back signal/
void Ultrasonic::DistanceMeasure(void)
{
pinMode(_pin, OUTPUT);
digitalWrite(_pin, LOW);
delayMicroseconds(2);
digitalWrite(_pin, HIGH);
delayMicroseconds(5);
digitalWrite(_pin,LOW);
pinMode(_pin,INPUT);
duration = pulseIn(_pin,HIGH);
}
/The measured distance from the range 0 to 400 Centimeters/
long Ultrasonic::microsecondsToCentimeters(void)
{
return duration/29/2;
}
/The measured distance from the range 0 to 157 Inches/
long Ultrasonic::microsecondsToInches(void)
{
return duration/74/2;
}

Ultrasonic ultrasonic(7);

////////////////////////////////////////////////////////////////////////////////////

void setup(){

Serial.begin(9600);

servoSensor.attach(5);
servoleft.attach(3);
servoright.attach(4);

servoSensor.write(pos);
delay(1500);
}

void loop() {

sweepServo();

getDistance();

if (pos >= 15 && pos <=45)
{
distanceRight = distance; // servo is to the right mesure the distance
}
if (pos >= 135 && pos <=165)
{
distanceLeft = distance; // sero is to the lefts measure the distance
}
if (pos > 70 && pos < 110)
{
distanceCenter = distance; // servo is centered so measure
}
if (distanceCenter >=25)
{
robotDirection = 0;
}
else // obstacle detected , turn left or right
{
if (distanceLeft > distanceRight)
{
robotDirection = 2; // turn left
}
if(distanceLeft < distanceRight)
{
robotDirection = 3; // turn right
}
if ( distanceLeft <= 5 && distanceCenter <= 5 || distanceRight <= 5 && distanceCenter <= 5)
{
robotDirection = 1; // we are stuck
}
}

unsigned long currentMillis = millis(); //set a timer

if(robotDirection == 0 && robotDirection == lastRobotDirection)
{
forward();
lastRobotDirection = robotDirection;
}
if(robotDirection == 0 && robotDirection != lastRobotDirection && currentMillis - previousMillis > interval )
{
forward();
lastRobotDirection = robotDirection;
previousMillis = currentMillis;
}
///////////////

if (robotDirection == 1 && robotDirection == lastRobotDirection)
{
backward();
lastRobotDirection = robotDirection;
}
if(robotDirection == 1 && robotDirection != lastRobotDirection && currentMillis - previousMillis > interval )
{
backward();
lastRobotDirection = robotDirection;
previousMillis = currentMillis;
}
//////////

if (robotDirection == 2 && robotDirection == lastRobotDirection)
{
left();
lastRobotDirection = robotDirection;
}
if(robotDirection == 2 && robotDirection != lastRobotDirection && currentMillis - previousMillis > interval )
{
left();
lastRobotDirection = robotDirection;
previousMillis = currentMillis;
}
/////////

if (robotDirection == 3 && robotDirection == lastRobotDirection)
{
right();
lastRobotDirection = robotDirection;
}
if(robotDirection == 3 && robotDirection != lastRobotDirection && currentMillis - previousMillis > interval )
{
right();
lastRobotDirection = robotDirection;
previousMillis = currentMillis;
}
///////
}

void getDistance()
{
runEvery(40)

{
long RangeInCentimeters;

ultrasonic.DistanceMeasure();// get the current signal time;

uS1 = ultrasonic.microsecondsToCentimeters();//convert the time to centimeters
delay(10);

uS2 = ultrasonic.microsecondsToCentimeters();
delay(10);

distance = (uS1+uS2)/2 ;

Serial.print(“DistanceMeasure: “); // to check distance on the serial monitor
Serial.print(distance);//0~400cm
Serial.println(” cm”);

}

}
/////////////////////////////////////////////////////////////////////////////

void forward()

{
servoleft.write(LForward);
servoright.write(RForward);
}

void backward ()
{
servoleft.write(LBackward);
servoright.write(RBackward);
}

void stop()
{
servoleft.write(LNutral);
servoright.write(RNutral);
}

void left ()
{
servoleft.write(LBackward);
servoright.write(RForward);
}

void right()
{
servoleft.write(LForward);
servoright.write(RBackward);
}

////////////////////////////////////////////////////////////////////////////////////

void sweepServo()
{
runEvery(servoDelay) //this loop determines the servo position
{
if(pos < 165 && servoDirection == 0) // 165 = servo to the left
{
pos = pos + 5; // +1 was to slow
}
if(pos > 15 && servoDirection == 1) // 15 = servo to the right
{
pos = pos - 5;
}
}
if (pos == 165 )
{
servoDirection = 1; //changes the direction
}
if (pos == 15 )
{
servoDirection = 0; //changes the direction
}
servoSensor.write(pos); //move that servo!
}
[/code]

We’ve compiled the code and uploaded it to our test BotBoarduino board with no issues… Do you have anything connected to the RX/TX/Gnd header or pins D0 and D1 of the shield headers? Can upload pictures of your latest robot, including showing the electrical connections?

Yup yup I will definitely do that as soon as I could. Thank you Jar. :slight_smile: :wink:

Here is the electronic connection.
http://
http://<a%20href="%20%20%20%20http:=""%20%20%20%20s105.photobucket.com=""%20%20%20%20user=""%20%20%20%20khang_nguyen4=""%20%20%20%20media=""%20%20%20%20mobile%20uploads=""%20%20%20%20image_zpsca7c53a8.jpg.html"="
And last night when I attempt to uplad the code to Botboarduino, the compling bar stuck at the last bit, and kept
on comply. However the yellow LED was flashing like crazy instead more like a stable rate. Hopefully this help.

P.S : I just made it harder on myself , I never known that we have an upload pictures option. Can you please delet the post with photobucket erro. Thank you.

Update Update Update
After the attempt for the autonomous code, now my Botboarduino wont comply with any other code even a simple once, It stuck at very end of the bar, and the LED flashing crazy again, :frowning::(:(:(:(:(:(:(:(:frowning: