63Views1Replies

Author Options:

arduino Blimp Answered

Hey guys.
I'm building an RC Blimp right now and i want to add an autonom landing feature which means the blimb has to realise when there is no more serial communication through the xbee. right now the aircraft gets 3 char-type objects. ech of these 3, for example "1=#" represents the speed for one motor. the 3 ASCII symbols get send every 0.1 seconds. any ideas how the arduino can realise that the connection is interrupted? 
heres my code, thanks for helping me out:)


#include <Servo.h>
#include "Wire.h"
#include "SRF02.h"
/*Testprogramm zur Treiberprogrammierung Team Grün*/
SRF02 srf02[2] =
{
  SRF02(0x70, SRF02_CENTIMETERS), //Initialisierung der beiden Ultraschallsensoren
  SRF02(0x71, SRF02_CENTIMETERS),
};
unsigned long nextPrint = 0;

//------------------------------------------+
Servo servoLeft; // create servo object     |
Servo servoRight;//                         |
Servo servoYaxis;//                         |
//------------------------------------------+
int motorSpeed;
int verticalSpeed;
int pinGreen = 8; //rgb colors
int pinRed = 4;
int pinBlue = 7;
int ledPin = 2;

int signal = 0;

void setup()
{
  //--------------------------+
  Serial.begin(9600);//     | Serial
  Wire.begin();//           | Ultraschallsensor
  SRF02::setInterval(100);//| Pulsintervall
  //-------------------------+
  //Servo Liste
  servoLeft.attach(6);
  servoRight.attach(5);
  servoYaxis.attach(9);
  char str[4] = {
    '\0'  };
  char command[3];
  int a;
  pinMode(pinGreen, OUTPUT);
  pinMode(pinRed, OUTPUT);
  pinMode(pinBlue, OUTPUT);
  pinMode(ledPin, OUTPUT);
}

void loop()
{
  char str[4] = {
    '\0'  };
  int a;
  int j = 0;
  int mL, mR, mY;
  if (Serial.available()>=3){
    for (byte i=0; i<3; i++){
      a = Serial.read();
      if (j == 0){
        mL = a;
      }
      if (j == 1){
        mR = a;
      }
      if (j == 2){
        mY = a;
      }
      j++;
    }
    if(mL == 181){
      Serial.println("Recived Command:");
    }

    else{
      Serial.println();
      Serial.println("MotorValues:");
      Serial.println(mL);
      Serial.println(mR);
      Serial.println(mY);
      Serial.println("------------");

      servoLeft.write(mL);
      servoRight.write(mR);
      servoYaxis.write(mY);
      //---------------------------------_-:+*COLOR*+:-_-------------------------------
      if(mL==90&&mR==90&&mY==90){
        //show zeropoint
        digitalWrite(pinBlue, LOW);
        digitalWrite(pinRed, LOW);
        digitalWrite(pinGreen, LOW);
      }
      if(mL<mR){
        digitalWrite(pinBlue, LOW);
        digitalWrite(pinRed, HIGH);
        digitalWrite(pinGreen, HIGH);  
      }
      if(mL>mR){
        digitalWrite(pinGreen, LOW);
        digitalWrite(pinRed, HIGH);
        digitalWrite(pinBlue, HIGH);  
      }
      if(mL==mR&&mL!=90){
        digitalWrite(pinBlue, HIGH);
        digitalWrite(pinRed, LOW);
        digitalWrite(pinGreen, LOW);
      }
      if(mY!=90){
        digitalWrite(pinBlue, LOW);
        digitalWrite(pinRed, LOW);
        digitalWrite(pinGreen, HIGH);
      }            

    }
  }
}

Discussions

0
None
robo10302

4 years ago

you can try and test this out

if(Serial.read( ) )

{

land();

}

void land()

{

// however you want it to land

}

this code is basically saying that if Serial reads nothing then land which is what should happen if connection is lost. But are you sure that the xbee itself doesnt send a serial message saying that the connection was interrupted? if not you can try this. hope it works.