Projekti‎ > ‎Poletna šola robotike‎ > ‎

RC jadralno letalo

objavljeno: 30. jun. 2017 05:36 avtor: Poletna Šola EIR   [ posodobljeno 2. jul. 2017 01:17 ]

Cilj projekta
Namen projekta je izdelati daljinsko vodeno jadralno letalo z Arduinom. 

Izvedba

Za izdelavo letala smo uporabili 2 servota, 2 potenciometra, 2 RF24 radijska modula 2,4 GHz, 1 LCD I2C zaslon, 4 gumbke in depron peno (za trup letala). Potenciometra preko RF24 premikata servote za toliko kot sta premaknjena, z uporabo funkcije map. Gumbki so bolj natančni, a počasni, in servotov položaj spreminjajo le za 1 stopinjo. 

Ugotovitve in predlogi 

Ne meči letala v dežju. Pazi na vezavo, kajti če ne pa boš skuril Arduino ali RF24. 

Zaključek

Smo dosegli želeni rezultat.

Priloge 

Vezje sprejemnika:

Program sprejemnika:
#include <SPI.h>
#include "RF24.h"
#include <Servo.h>

RF24 radio(7, 8);// Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7 & 8
const byte tx_addr[] = "txAdr";
const byte rx_addr[] = "rxAdr";
byte recieved_ch[6];
byte ch[6] = {44, 55, 66, 77, 88, 99};
int battery = 11;
unsigned long timeout = 0;

const bool test = 0; //0 - ne testiramo ; 1 - testiramo
Servo servo_ch0;
Servo servo_ch1;
Servo servo_ch2;
Servo servo_ch3;
Servo servo_ch4;
void setup() {
  Serial.begin(115200);
  Serial.println(F("RESTART============"));
  radio.begin();
  radio.setPALevel(RF24_PA_LOW);
  //radio.openWritingPipe(naslov);  // ("ANDRO") = addresses[1]
  radio.openWritingPipe(rx_addr);
  radio.openReadingPipe(1, tx_addr);

  servo_ch0.attach(3);
  servo_ch1.attach(5);
  servo_ch2.attach(6);
  servo_ch3.attach(9);
  servo_ch4.attach(10);
  //servo_ch5.attach(11); => MISO
}
void transmit() {
  int dummyAdc = analogRead(A0);
  battery = map (dummyAdc, 0, 1023, 0, 1000);
  radio.stopListening(); //transmitting...
  delay(0.1);
  radio.write( &battery, sizeof(battery));
}

void recieve() {
  radio.startListening();
  delay(0.1);
  if (radio.available()) {
    radio.read(&recieved_ch, sizeof(recieved_ch));
//  }else{
//    Serial.println("Radio not conected");
//  }
}
}
void loop() {
  // ODDAJANJE PODATKOV
  if (millis() > timeout) {
    transmit();
    timeout = millis() + 10000; //now+10s
  }



  // SPREJEM PODATKOV
  recieve();
  // NASTAVITVE SERVOTOV
  servo_ch0.write(recieved_ch[0]);
  servo_ch1.write(recieved_ch[1]);
  servo_ch2.write(recieved_ch[2]);
  servo_ch3.write(recieved_ch[3]);
  servo_ch4.write(recieved_ch[4]);
  //IZPIS PODATKOV
  if (test) {
    for (int i = 0; i < 6; i++) {
      Serial.print("\tch"); Serial.print(i); Serial.print(":"); Serial.print(recieved_ch[i]);
    }
    Serial.println();
    Serial.println(battery);
    delay(100);
  }

}

Vezje oddajnika:

Program oddajnika:
#include <SPI.h>
#include "RF24.h"

RF24 radio(9, 10);// Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7 & 8
const byte tx_addr[] = "txAdr";
const byte rx_addr[] = "rxAdr";
byte recieved_ch[6];

// spremenljivke za posamezen kanal
byte ch[5] = {90, 90, 90, 90, 90};
byte ch_min[5] = {45, 45, 45, 45, 45};
byte ch_max[5] = {135, 135, 135, 135, 135};
int gimbalMax[4] = {860, 860, 860, 860};
int gimbalMin[4] = {120, 120, 120, 120};
int trimi[5] = {0, 0, 0, 0, 0};
byte sw_trim_ch_incr[4] = {8, 6, 4, 2};
byte sw_trim_ch_decr[4] = {7, 5, 3, 17};
byte incr_sw_timer[4] = {0, 0, 0, 0};
byte decr_sw_timer[4] = {0, 0, 0, 0};
byte old_incr_sw_val[4] = {1, 1, 1, 1};
byte old_decr_sw_val[4] = {1, 1, 1, 1};

byte pin_pot[4] = {0, 1, 2, 7};

int battery = 11;

const byte test = 0;
// 0 - ne testiramo 
// 1 - testiramo
// 3 - trim test

void odcitaj_komande() {
  for (byte i = 0 ; i < 4; i++) {
    // KANALI
    int dummyCh = analogRead(pin_pot[i]); //ADC = (120..860)
    ch[i] = map(dummyCh, gimbalMin[i], gimbalMax[i], ch_min[i], ch_max[i]);
    
    // TRIM SWITHCHES
    if (digitalRead(sw_trim_ch_incr[i]) == LOW) {
      incr_sw_timer[i]++;
      if ((old_incr_sw_val[i] == HIGH) or (incr_sw_timer[i] > 100)) {
        if (incr_sw_timer[i] > 100) incr_sw_timer[i] = 80;
        ch_max[i]++; ch_min[i]++; old_incr_sw_val[i] = LOW;
      }
    } else {
      incr_sw_timer[i] = 0;
      old_incr_sw_val[i] = HIGH;
    }

    if (digitalRead(sw_trim_ch_decr[i]) == LOW) {
      decr_sw_timer[i]++;
      if ((old_decr_sw_val[i] == HIGH) or (decr_sw_timer[i] > 100)) {
        if (decr_sw_timer[i] > 100) decr_sw_timer[i] = 80;
        ch_max[i]--; ch_min[i]--; old_decr_sw_val[i] = LOW;
      }
    } else {
      decr_sw_timer[i] = 0;
      old_decr_sw_val[i] = HIGH;
    }
  }

}


void setup() {
  Serial.begin(115200);
  radio.begin();
  radio.setPALevel(RF24_PA_LOW);
  radio.openWritingPipe(tx_addr);
  radio.openReadingPipe(1, rx_addr );
  for (int x = 0; x < 4; x++) {
    pinMode(sw_trim_ch_incr[x], INPUT_PULLUP);
    pinMode(sw_trim_ch_decr[x], INPUT_PULLUP);
  }

}
void transmit() {
  radio.stopListening(); //transmitting...
  radio.write( &ch, sizeof(ch));
}

void recieve() {
  radio.startListening();
  delay(0.1);
  if (radio.available()) {
    radio.read(&battery, sizeof(battery));
  }
  radio.stopListening();
}

void loop() {
  // ODDAJANJE PODATKOV
  odcitaj_komande();

  transmit();
  // SPREJEM PODATKOV
  recieve();
  //IZPIS PODATKOV
  if (test == 1) {
    for (int i = 0; i < 6; i++) {
      Serial.print("\tch"); Serial.print(i); Serial.print(":"); Serial.print(ch[i]);

    }
    Serial.println();
    Serial.println(battery);

  }

}

Predstavitev avtorjev

Andrej Matevc, e-mail
Dejan Mežnarc, e-mail
Žiga Tomaž Krajnc, e-mail
Comments