hi there
i've been working on basics, intermediate applications using XBEE devices, and got good results (turning on leds with remote or controller on pC for example )
now i'm working on controlling an uav, or anykind of robot via the same configuration, that is:
____ PC - Processing ( for the controller or remote) + XBEE on Explorer sending data
____ ARduino - XBEE recieving data
i only use essential XBEE PINS: 1 = Vcc, 10 = Gnd; 2 (data in) = Rx ( i use Main serial on board, ATMEGA 2560 )
i'm thinking of the best method to process the incoming data ( i got good results, but sometimes for example, my actionned motor doesn't stop, or maybe not as quick as i would like to etc.. i also would like to get the more advanced commands, for example turning the robot of the exact angle sent by the sticks etc.. )
this is an example of code i came with:
PC + processing:
// key A is pressed
XBEE.write ('A'); // this works well, acurate and fast
// a stick is used
XBEE.write('Y'); // tells the arduino its gonna be an Y axis
XBEE.write ( ValY ) ; // valY is the value i get using processing code like: ValY = Y.getValue ();
// this works well too
// my processing sketch works well and responds well
arduino + xbee receiving data
void setup(){
Serial.begin (9600); // exact same BD as XBEE receiver
}
void loop (){
processData () ; // i think its better processing data out of the loop, may be wrong or useless
}
processData (){
char c = Serial.read (); // RX0 reads the incoming data from XBEE
// and now what i do is this kind of method:
if ( c == 'A' ){
// action for A
}
if ( c== 'Y') { // an Y axis has been pressed
int i = Serial.read (); // i want to get the data coming right after that, in order to use it for a proportionnal answer:
// action for Y for example:
myMotorRight.write ( i );
myServo.write(i); // etc..
}
} // end processData
So, what do you think of my method?
the main problems i get are:
motors turn on well ( for example i can turn a specific motor only) but sometimes wont stop;
right now, i'm not able to get a motor answering to the integer i= serial.read () right after my char c= serial.read() indicating an Y has been pressed; may be a problem of delays; using only integers might be a solution
i tryed to replace the "if's" by "while's" but once i get a keyPressed or a stick actionned, the answering action is done but does not stop anymore
do you think i should insert some Serial.available or some serial.flush() ?? ( i tried but didnt change anything )
do you think sending only integers ( and not char then integer ) would be more efficient?
i also sometimes get other kind of weird trouble:
for example yesterday afternoon i've been testing my protocols for turning the UAV, landing,lifting ( that is simply actionnate a certain motor and not another, throttle on a certain motor and brake on another etc.. ) and i managed to get some results with problems mentionned above.
and today as i turn everything back on power, cannot manage to recieve a single data via the XBEEs ( i got a lot of them, i often test them, they detect each other, the "sending data" xbee is working, but it seems sometimes the receiving one doesn't...
i need some new ideas coming from efficient brains
_______ double POST PB, delete one please