Servo control using xbee


hello guys...

from several days, trying control movement of 3 servos , esc aircraft using thumb joysticks , xbee series 2 modules..

i tested using direct wire control , fine..

now, using xbee wireless transmission..

i established serial communication between 2 arduinos (diecimila) , verified joystick values on terminal of xctu.



now problem how can decode values of joysticks on receiver end..

my transmitter end sketch is
code: [select]
/*
****transmitter****
just extended version of analoginserial example code

sketch: joystick control of rc servos using xbee modules
*/


void setup() {
 serial.begin(9600);
}

void loop() {

/******* vertical left joystick *******/

  int analogvalue0 = analogread(0);
  //analogvalue0=map(analogvalue0,0,1023,0,180);
 
  // print result:
  serial.print('a',byte);      // sync char
  serial.println(analogvalue0,byte);
 
  // wait 10 milliseconds analog-to-digital converter
  // settle after last reading:
  delay(10);
 
/******* vertical right joystick *******/

  int analogvalue1 = analogread(1);
  //analogvalue1=map(analogvalue1,0,1023,0,180);
 
  serial.print('b',byte);      // sync char
  serial.println(analogvalue1,byte);
 
  delay(10);
 
/******* horizontal right joystick *******/
 
  int analogvalue2 = analogread(2);
  //analogvalue2=map(analogvalue2,0,1023,0,180);
 
  serial.print('c',byte);  // sync char
  serial.println(analogvalue2,byte);      
 
  delay(10);

/******* electronic speed control *******/

  int analogvalue3 = analogread(3);
  //analogvalue3=map(analogvalue3,0,1023,0,180);

  serial.print('d',byte);   // sync char
  serial.println(analogvalue3,byte);  

  delay(10);

}


i tried making changes in receiver sketch http://lab.guilhermemartins.net/2008/12/24/serial-comunication-with-xbee-arduino/ did'nt worked me..

so problem how parse sync characters (a,b,c,d) incoming bytes, can map values servos ?
or can suggest me other logic this.

well, remote control !!!



any appreciated..
aadeesh

below test code i've made tinkering servos might of interest. can send 1000 , position servo. looks "," delimiter in buffer data, can search/parce readstring, , convert string number use in servo control.    

code: [select]

//zoomkat 8-12-10 roborealm serial servo parce test
//type servo position 0 180 in serial monitor
//for writemicroseconds, use value 1500
// http://www.arduino.cc/en/tutorial/textstring wstring.h

#include <wstring.h> //provides easy string handling
string readstring = string(100);
string parce1 = string(10);
string parce2 = string(10);
int pos = 0;
int ind1 = 0;
int ind2 = 0;


#include <servo.h>
servo myservo;  // create servo object control servo

void setup() {
     serial.begin(9600);
       myservo.attach(9);
       }

void loop() {

       //expect string wer,qwe rty,123 456,hyre kjhg,
      while (serial.available())
{
  delay(10);
  if (serial.available() > 0)
  {
    char c = serial.read();  //gets 1 byte serial buffer
    if (c == ',')
       break;
    readstring.append(c); //makes string readstring
   }
}
     
     
     parce:  
     if (readstring.length() >0) {
     serial.println(readstring);
     pos = readstring.length(); //capture string length
     ind1 = readstring.indexof(' '); //position of space
     parce1 = readstring.substring(0, ind1); //first part of string
     parce2 = readstring.substring(ind1+1, pos); //second part of string
     serial.println(parce1);
     serial.println(parce2);
     serial.println();
     
     int n;
    n = atoi(readstring); //convert string number
    myservo.writemicroseconds(n);
    myservo.write(n);
     readstring="";
     }
  }


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Servo control using xbee


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums