Putting robotics at your service™

Free shipping on orders over $75

Remote control of servos using XBee?

Print view Share :
Previous topicNext topic

Page 1 of 1 [ 6 posts ]

Rookie ( offline )
Posts: 28
Posted: 2013-01-01 15:49 
I have two Arduino Uno boards, two Parallax 2-Axis joysticks, two Xbee modules on Xbee SIP Adapters, regular servos, and continuous/modified servos. How do I create remote control system? If I use Parallax 5-position switch, the servos work properly. If I try to use joysticks, the servos keep on running instead of stopping when the joystick is in center position. How can I fix the problem?


User avatar
Guru ( offline )
Posts: 3329
Posted: 2013-01-02 04:26 
I take it we are talking about two different systems here?
Regular servos & cr servos?

My guess is that you have the regular servos connected to the position switch and the cr servo to the joystick.
If so then the regular servos sound to be working as you mention, but your cr are not?

Cr servos center "around" the value of 1500. Sometimes this number can be slightly off. 1490/5 - 1505/1590.
It's always worth seeing if you can adjust the center deadzone for the joystick, or adjust the sent (offset) value directly with in your code

_________________
Jonny Poole,
Animatronic props.
http://www.innerbreed.co.uk
Create, Innovate, Inspire.


Rookie ( offline )
Posts: 28
Posted: 2013-01-02 07:58 
I connected the joystick, 5-position switch, and two servos to one Arduino board. The servos stop when both the 5-position switch and the joystick are in the center position. I think that something is wrong with the XBee communication.


User avatar
Admin ( offline )
Posts: 6964
Posted: 2013-01-02 09:59 
Can you include a drawing / images of your setup so we clearly see how everything is connected?
It sounds like a code issue.

_________________
Coleman Benson

RobotShop inc.
Putting Robotics at your service!™
www.robotshop.com

Lynxmotion
Imagine it. Build it. Control it.™
http://www.Lynxmotion.com


User avatar
Guru ( offline )
Posts: 4942
Posted: 2013-01-02 11:43 
As others have mentioned, there is not enough information here, to give a complete answer.

Things like, how are the Servos connected and running? My assumption is you are using the Servo library.

Also as mentioned, not all servos are exact at 1500us as the stop position, so may need to adjust. Also some joysticks are not good at having a consistent center-point. Again not sure how you are controlling. I am assuming using analogRead? Assuming you don't scale it, that implies that center will be near 512. On some of these you may find that the actual center one time is 520 and on some when you move it and release it, it may come back to 515 or maybe 508... So we often have what we call a deadzone or deadband where we say that anything in the range of 500-524 is considered to be logical 0... The worse the joystick the bigger this range needs to be...

As for XBees, how are they connected? Shield? Sparkfun Regulated explorer? Using Hardware Serial Port or Software Serial? The reason I ask, is they may all react with each other. For example if you are using the Servo library, it uses specific interrupts and timings to generate the pulses for the servos. However these will get off of something else is handling or disabling interrupts. With Hardware serial, the interrupt processing is minimal, but with Softwareserial, interrupts are disabled during the complete output or input of a character, which can really screw up a servo signal.

Then there is the obvious things to check like how are sending the data between the two XBees. In Serial Replacement mode or in Packet Mode. I will assume that in simple text mode. Do you have code to handle knowing when a packet of information arrives? Do you process it quick enough to not lose data... There are some real simple XBee based remote controls out there like the Arbotix Commander(http://www.trossenrobotics.com/p/arboti ... ad-v2.aspx), which uses a real simple protocol. There is more complex systems, like the DIY XBee remote controls which there are lots of posting talking about that on this forum (but no real kits for building them). My current code uses the XBees in packet mode and I have my own protocol set up for them....

Hope that helps.
Kurt


Rookie ( offline )
Posts: 28
Posted: 2013-01-02 17:04 
I'm using the Servo library. The XBee modules are on Xbee SIP Adapters that are plugged into breadboards. I'm using Software Serial. I will try Hardware Serial. On one Arduino UNO board, The joystick is connected to A0 and A1 pins. The 5-position switch is connected to D4, D5, D6, D7, and D8 pins. The XBee SIP Adapter is connected to D2 and D3 pins. On other Arduino UNO board, The XBee SIP Adapter is connected to D2 and D3 pins. Servos are connected to D5 and D6 pins. GND and 5V pins supply power to breadboards. The servos have separate power source. There is common ground. I'm using modified code from:
http://www.instructables.com/id/DFRobot ... ver-wXbee/

Code:
//#include <SoftwareSerial.h>
#include <Servo.h>
Servo servoLeft;
Servo servoRight;
int sensorPin1 = 0;
int sensorPin2 = 1;
int sensorValue1 = 0;
int sensorValue2 = 0;
int motorValue1 = 0;
int motorValue2 = 0;
//const int xb_rx = 2;
//const int xb_tx = 3;
//SoftwareSerial Xbee(xb_rx,xb_tx);
void setup()
{
  servoLeft.attach(9);
  servoRight.attach(10);
  servoLeft.writeMicroseconds(1500);
  servoRight.writeMicroseconds(1500);
//  Serial.begin(9600);
//  Xbee.begin(9600);
}
void loop()
{
  if(digitalRead(4) == LOW)
  {
    servoLeft.writeMicroseconds(1000);
    servoRight.writeMicroseconds(1000);
  }
  if(digitalRead(5)== LOW)
  {
    servoLeft.writeMicroseconds(2000);
    servoRight.writeMicroseconds(1000);
  }
  if(digitalRead(6) == LOW)
  {
    servoLeft.writeMicroseconds(2000);
    servoRight.writeMicroseconds(2000);
  }
  if(digitalRead(7) == LOW)
  {
    servoLeft.writeMicroseconds(1000);
    servoRight.writeMicroseconds(2000);
  }
  if(digitalRead(8) == LOW)
  {
    servoLeft.writeMicroseconds(1500);
    servoRight.writeMicroseconds(1500);
  }
  sensorValue1 = analogRead(sensorPin1);
  sensorValue2 = analogRead(sensorPin2);
  Serial.print(sensorValue1);
  Serial.print(",");
  Serial.println(sensorValue2);
  motorValue1 = map(sensorValue1,0,1024,1000,2000);
  motorValue2 = map(sensorValue2,0,1024,1000,2000);
  servoLeft.writeMicroseconds(motorValue1);
  servoRight.writeMicroseconds(motorValue2);
}


Code:
#include <SoftwareSerial.h>
#include <Servo.h>
Servo servoLeft;
Servo servoRight;
const int xb_rx = 2;
const int xb_tx = 3;
SoftwareSerial Xbee(xb_rx, xb_tx);
void setup(void)
{
  servoLeft.attach(5);
  servoRight.attach(6);
  Serial.begin(9600);
  Xbee.begin(9600);
  servoLeft.writeMicroseconds(1500);
  servoRight.writeMicroseconds(1500);
 
}
void loop(void)
{
  while (Xbee.available()>0)
  {
    char val01 = Xbee.read();
    switch(val01)
    {
      case '5':
      servoLeft.writeMicroseconds(1500);
      servoRight.writeMicroseconds(1500);
      Serial.println("5");
      break;
      case '8':
      servoLeft.writeMicroseconds(1000);
      servoRight.writeMicroseconds(2000);
      Serial.println("8");
      break;
      case '2':
      servoLeft.writeMicroseconds(2000);
      servoRight.writeMicroseconds(1000);
      Serial.println("2");
      break;
      case '4':
      servoLeft.writeMicroseconds(1000);
      servoRight.writeMicroseconds(1000);
      Serial.println("4");
      break;
      case '6':
      servoLeft.writeMicroseconds(2000);
      servoRight.writeMicroseconds(2000);
      Serial.println("6");
      break;
      case '1':
      Serial.println("1");
      break;
      case '3':
      Serial.println("3");
      break;
      case '7':
      Serial.println("7");
      break;
      case '9':
      Serial.println("9");
      break;
    } 
  }
}


 

All times are UTC - 5 hours [ DST ]. It is currently 2018-05-22 04:23