2

Hi there I just need to ask you how I can send command from master robot to slave to follow using XBee. I have configured both the XBee in AT mode, but I totally don't have the clue how the program.

I am using the following kit components (from DF ROBOT) to build this project,

  1. Romeo V2-All in one Controller (Arduino based controller).

  2. Differential drive chasis with caster ball.

  3. Wheel Encoders.

  4. XBee 2mW PCB Antenna - Series 2 (ZigBee Mesh) Transceiver module for the communication between two robots.

  5. IR sensors.

6.Micro DC Geared Motor w/ Back Shaft (180rpm 6V).

I have done the programming for obstacle detection, positioning of robot, but I have no idea how to do the master slave programming logic.

Please help me on this. Here attached the code I have done till now:

const int InfraredSensorPin1 = 6;//Connect the signal pin to the digital pin 6
int detected2;
int detected1;
const int InfraredSensorPin2 = 9 ; 

int E1 = 5;     //M1 Speed Control
int E2 = 6;     //M2 Speed Control
int M1 = 4;    //M1 Direction Control
int M2 = 7;    //M1 Direction Control

#define LEFT 0
#define RIGHT 1
int value;
long coder[2] = {
  0, 0
};
int lastSpeed[2] = {
  0, 0
};

void stop(void)                    //Stop
{
  digitalWrite(E1, 0);
  digitalWrite(M1, LOW);
  digitalWrite(E2, 0);
  digitalWrite(M2, LOW);
}
void advance(char a, char b)         //Move forward
{
  analogWrite (E1, a);
  digitalWrite(M1, HIGH);
  analogWrite (E2, b);
  digitalWrite(M2, HIGH);
}
void back_off (char a, char b)         //Move backward
{
  analogWrite (E1, a);
  digitalWrite(M1, LOW);
  analogWrite (E2, b);
  digitalWrite(M2, LOW);
}
void turn_L (char a, char b)            //Turn Left
{
  analogWrite (E1, a);
  digitalWrite(M1, LOW);
  analogWrite (E2, b);
  digitalWrite(M2, HIGH);
}
void turn_R (char a, char b)            //Turn Right
{
  analogWrite (E1, a);
  digitalWrite(M1, HIGH);
  analogWrite (E2, b);
  digitalWrite(M2, LOW);
}

void setup(void)
{ Serial.println("Start!");

 pinMode(InfraredSensorPin1, INPUT);
 pinMode(InfraredSensorPin2, INPUT);

advance(200,200);
  Serial.begin(19200);      //Set Baud Rate//
  attachInterrupt(LEFT, LwheelSpeed, CHANGE);    //init the interrupt mode for the digital pin 2
  attachInterrupt(RIGHT, RwheelSpeed, CHANGE);   //init the interrupt mode for the digital pin 3
}
void loop(void)
{
  if((InfraredSensorPin1==LOW&&!InfraredSensorPin2==LOW)||(InfraredSensorPin1==LOW&&InfraredSensorPin2==LOW))
  turn_L (100,100);

  else if ((InfraredSensorPin2==LOW&&!InfraredSensorPin1==LOW)||(InfraredSensorPin2==LOW&&InfraredSensorPin1==LOW))
  turn_R (100,100);

  else  
  advance (80,80);
  static unsigned long timer = 0;                //print manager timer
  if (millis() - timer > 5) {
    Serial.print("Coder value: ");
    Serial.print(coder[LEFT]);
    Serial.print("[Left Wheel] ");
    Serial.print(coder[RIGHT]);
    Serial.println("[Right Wheel]");

    lastSpeed[LEFT] = coder[LEFT];   //record the latest speed value
    lastSpeed[RIGHT] = coder[RIGHT];
    coder[LEFT] = 0;                 //clear the data buffer
    coder[RIGHT] = 0;
    timer = millis();
  }
}
void LwheelSpeed()
{
  coder[LEFT] ++;  //count the left wheel encoder interrupts
}
void RwheelSpeed()
{
  coder[RIGHT] ++; //count the right wheel encoder interrupts
}
1
  • You can format your code with the {} button in the post editor.
    – uint128_t
    Apr 12, 2016 at 1:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.