I have been working with Arduino for a while now but just got into the wireless (xbee) type of coding. I am trying to wirelessly control a robot from the computer using the x-ctu terminal but am getting slow responses from the readout. A few facts before continuing:
- The communication between the two xbees is setup (2x XB24-ZB)
- I have 2 servos which are mimicking the drive wheels (left and right)
- When a drive command is prompted in the x-ctu termial window the respective the response is slow and the delay is long (multiple commands print in the window before the robot moves)
- not sure if this is related but when i do a range test in x-ctu i only get “bad” packets back, never “good”, i think this might have something to do with the tx and rf not being connected on the robot side xbee
- The xbees are in “zigbee end device at” for the robot xbee and “zigbee coordinator at” for the computer xbee
- Baud rate is 9600
It almost seems like the xbees are not processing the information fast enough. The code i am using is below, very simple just to get the xbee up and running (see below). Goal of this code is to have the servos run when a command prompt is given from the x-ctu terminal window and for the servo directions to change with no delay if a different command is given. Once this is up and running it will be going into my semi autonomous wheel chair snow plow robot so i can control it from inside if it gets out of hand.
Please let me know if additional information is needed.
"#include
Servo rightServo;
Servo leftServo;
int leftF = 20;
int rightF = 135;
int leftB = 135;
int rightB = 20;
int leftS = 90;
int rightS = 90;
int turnTime = 20;
void setup()
{
Serial.begin(9600);
rightServo.attach(3);
leftServo.attach(5);
}
void loop ()
{
if(Serial.available()>0){
byte info=Serial.read();
Serial.println(info);
//forward
if(info==‘w’){
rightServo.write(rightF);
leftServo.write(leftF);
delay(100);
}
//backward
if(info==‘s’){
rightServo.write(rightB);
leftServo.write(leftB);
delay(100);
}
//left
if(info==‘a’){
rightServo.write(rightF);
leftServo.write(leftB);
delay(100);
}
//right
if(info==‘d’){
rightServo.write(rightB);
leftServo.write(leftF);
delay(100);
}
//stop
{
rightServo.write(rightS);
leftServo.write(leftS);
}
}
}"