LAMPIRAN A
Sintaks Program Sistem Autotracking pada Stasiun Pengirim
#include <TinyGPS++.h> #include <SoftwareSerial.h> #include <RF24Network.h> #include <RF24.h> #include <SPI.h> #include "printf.h" #include <Wire.h> #include <Adafruit_BMP085.h> Adafruit_BMP085 bmp;
static const int RXPin = 3, TXPin = 4; // GPS connections (RX pin connects to TX on module and other wise) static const uint32_t GPSBaud = 9600; // GPS Baud Rate
SoftwareSerial ss(RXPin, TXPin); // The serial connection to the GPS device TinyGPSPlus gps; // The TinyGPS++ object
// BMP Altitude[0]
double myAlt[1]; //current BMP height // GPS Latitude[0]/Longitude[1]
RF24 radio(7,8); // nRF24L01 radio attached (CE, CSN) RF24Network network(radio); // Network uses that radio const uint16_t channel = 60; // Channel of our node const uint16_t this_node = 1; // Address of our node const uint16_t other_node = 0; // Address of the base
unsigned long packets_sent; // How many packets have we sent already
// Structure of our payload, limited to 32 bytes struct payload_t // 32 bytes max
{
unsigned long counter; // 4 bytes double lat; // 4 bytes double lng; // 4 bytes double Altitude; // 4 bytes };
void setup() {
Serial.begin(9600); Wire.begin();
ss.begin(GPSBaud); // start Software Serial bmp.begin();
SPI.begin(); radio.begin(); network.begin(channel, this_node); } void loop() { while (ss.available() > 0) { if (gps.encode(ss.read())) {
getGPS(); //Baca data latitude, longitude dan altitude sendPayload(); //kirim data yang telah terbaca
smartDelay(2000);
if (millis() > 5000 && gps.charsProcessed() < 10) {
Serial.println(F("No GPS detected: check wiring.")); while(true);
} } } }
void getGPS() //Baca data latitude, longitude dan altitude {
if (gps.location.isValid()) { myLL[0] = gps.location.lat(); myLL[1] = gps.location.lng(); myAlt[0]= bmp.readAltitude(101500); printf("Altitude = "); Serial.print(myAlt[0],6); printf(" lat: "); Serial.print(myLL[0],6); printf(" lng: "); Serial.print(myLL[1],6); printf("\n"); } }
void sendPayload() //kirim data yang telah terbaca {
payload_t payload = {packets_sent++, myLL[0], myLL[1], myAlt[0]}; RF24NetworkHeader header(/*to node*/ other_node);
bool ok = network.write(header,&payload,sizeof(payload));
radio.powerDown(); // Power down the radio. Note that the radio will get powered back up on the next write() call.
}
static void smartDelay(unsigned long ms) // ensures that the gps object is being "fed"
unsigned long start = millis(); do
{
while (ss.available()) gps.encode(ss.read()); } while (millis() - start < ms); }
Sintaks Program Sistem Autotracking pada Stasiun Penerima
#include <TinyGPS++.h> #include <SoftwareSerial.h> #include <Servo.h> #include <RF24Network.h> #include <RF24.h> #include <SPI.h> #include "printf.h" #include <Wire.h> #include <Adafruit_BMP085.h> #include <LiquidCrystal_I2C.h> #include <HMC5883L.h> HMC5883L compass; int error = 0;
static const uint32_t GPSBaud = 9600; Servo myservo; Servo myservo1; LiquidCrystal_I2C lcd(0x27, 20, 4); Adafruit_BMP085 bmp; TinyGPSPlus gps;
SoftwareSerial ss(RXPin, TXPin);
double x1,x2,y1,y2,a,b,c,alt1,alt2; double sudut,jarak,sudut_elevasi;
RF24 radio(7,8);
RF24Network network(radio); // Network uses that radio const uint16_t channel = 60; // Channel of our node const uint16_t this_node = 0; // Address of our node const uint16_t other_node = 1; // Address of the other node
unsigned long packets_sent; // How many packets have we sent already
// GPS Latitude[0];Longitude[1] double setLL[2]; //stored location
double myLL[2]; //current GPS location double setAlt[1]; //stored altitude
// Structure of our payload, limited to 32 bytes struct payload_t // 32 bytes max
{
unsigned long counter; // 4 bytes double lat; // 4 bytes double lng; // 4 bytes float Altitude; // 4 bytes
}; void setup() { lcd.begin(); lcd.backlight(); Serial.begin(9600); bmp.begin(); myservo.attach(9); //azimuth myservo.write(180); delay(900); myservo1.attach(10); //elevasi myservo1.write(16);
delay(900); myservo.detach(); myservo1.detach(); printf_begin(); ss.begin(9600);
SPI.begin(); // Start the SPI interface.
radio.begin();
network.begin(channel,this_node);
Wire.begin(); // Start the I2C interface.
compass = HMC5883L(); // Construct a new HMC5883 compass. error = compass.SetScale(1.3); // Set the scale of the compass.
if(error != 0) // If there is an error, print it out. Serial.println(compass.GetErrorText(error));
// Set the measurement mode to Continuous
error = compass.SetMeasurementMode(Measurement_Continuous); if(error != 0) // If there is an error, print it out.
Serial.println(compass.GetErrorText(error));
void loop() { ss.begin(9600); //GPS on delay(10);
network.update(); //pump the radio network regularly delay(100);
//latitude, longitude & altitude stasiun penerima--- x1 = gps.location.lat(); y1 = gps.location.lng(); alt1 = bmp.readAltitude(101500); Serial.print("x1 : "); Serial.println(x1,6); Serial.print("y1 : "); Serial.println(y1,6); Serial.print("alt1 : "); Serial.println(alt1); smartDelay(100); //---
x2 = setLL[0]; y2 = setLL[1]; alt2 = setAlt[0]; Serial.print("x2 : "); Serial.println(x2,6); Serial.print("y2 : "); Serial.println(y2,6); Serial.print("alt2 : "); Serial.println(alt2);
//latitude, longitude & altitude stasiun pengirim---
ss.end(); //GPS off
//kompas---
MagnetometerRaw raw = compass.ReadRawAxis(); MagnetometerScaled scaled = compass.ReadScaledAxis();
int MilliGauss_OnThe_XAxis = scaled.XAxis;// (or YAxis, or ZAxis) float heading = atan2(scaled.YAxis, scaled.XAxis);
float declinationAngle = 0.0457; heading += declinationAngle; if(heading < 0) heading += 2*PI;
if(heading > 2*PI) heading -= 2*PI;
float headingDegrees = heading * 180/M_PI; Serial.println(headingDegrees);
//kompas---
while(network.available()) {
getRadioData(); //Terima data Stasiun pengirim
//LCD--- lcd.clear(); lcd.setCursor(0, 0); lcd.print(x2,6); lcd.setCursor(0, 1); lcd.print(y2,6); lcd.setCursor(0, 2); lcd.print(x1,6); lcd.setCursor(0, 3); lcd.print(y1,6);
lcd.setCursor(10,0); lcd.print("sdt"); lcd.setCursor(10,1); lcd.print(sudut); lcd.setCursor(10,2); lcd.print("b/a"); lcd.setCursor(10,3); lcd.print(c); lcd.setCursor(15,0); lcd.print("komp"); lcd.setCursor(15,1); lcd.print(headingDegrees); lcd.setCursor(15,2); lcd.print("elv"); lcd.setCursor(15,3); lcd.print(sudut_elevasi); //LCD--- }
if (x1 != 0 && x2 != 0) { hitung_sudut(); elevasi(); //---AZIMUTH---
if (headingDegrees >=100 && headingDegrees <= 110) // ----> badan stasiun penerima ke arah TIMUR
{ if(a>0 && b >0) { int pos; pos = 180 - (sudut * 0.84); myservo.attach(9); myservo.write(pos); delay(100); myservo.detach(); }
else if (a<0 && b>0) { int pos; pos = 180 - ((180-sudut) *0.84) ; myservo.attach(9); myservo.write(pos); delay(100);
myservo.detach(); } } //---AZIMUTH--- //---elevasi--- int pos; myservo1.attach(10); pos = 16 + sudut_elevasi; myservo1.write(pos); delay(1000); myservo1.detach(); //---elevasi--- }
if (millis() > 5000 && gps.charsProcessed() < 10)
Serial.println(F("No GPS data received: check wiring"));
} //end of void loop
double hitung_sudut() { a = x2 - x1; b = y2 - y1; c = b/a; if (c < 0)
{ c = c*(-1); } sudut = round(atan(c)*180/3.14159265); delay(10); Serial.print("sudut : "); Serial.println(sudut); } double elevasi() { //Euclidean Formula
double xy = sqrt((pow(a,2)) + (pow(b,2))); jarak = 111319 * xy;
double t_per_j = (alt2 - alt1)/jarak;
sudut_elevasi = round(atan(t_per_j)*180/3.14159265);
}
// This custom version of delay() ensures that the gps object is being "fed". static void smartDelay(unsigned long ms)
{
unsigned long start = millis(); do
{
while (ss.available()) gps.encode(ss.read()); } while (millis() - start < ms); }
void getRadioData() {
RF24NetworkHeader header;
payload_t payload={packets_sent++, myLL[0], myLL[1], myAlt[0]}; bool done = false;
while (!done) { done = network.read(header,&payload,sizeof(payload)); setLL[0] = payload.lat; setLL[1] = payload.lng; setAlt[0]= payload.Altitude;
printf(" Alt: ",setAlt[0],6); Serial.print(setAlt[0],6);
printf(" Lat: ",setLL[0],6); Serial.print(setLL[0],6);
Serial.print(setLL[1],6); printf("\n");
} }
LAMPIRAN B
Diagram Alir Sistem Autotracking Sudut Elevasi
LAMPIRAN C
Tabel hasil pengujian autotracking sudut azimuth pertama
No
Posisi RX Posisi TX Besar Sudut
Perhitungan
Besar Sudut Pengukuran
Besar Kesalahan
Latitude Longitude Latitude Longitude
1 3.557109 98.658201 3.557471 98.658882 62° 63° 1° 2 3.557109 98.658201 3.557471 98.658882 62° 62° 0° 3 3.557109 98.658201 3.557471 98.658882 62° 63° 1° 4 3.557109 98.658201 3.557471 98.658882 62° 63° 1° 5 3.557109 98.658201 3.557471 98.658882 62° 63° 1° 6 3.557109 98.658201 3.557471 98.658882 62° 62° 0° 7 3.557109 98.658201 3.557471 98.658882 62° 63° 1° 8 3.557109 98.658201 3.557471 98.658882 62° 63° 1° 9 3.557109 98.658201 3.557471 98.658882 62° 63° 1° 10 3.557109 98.658201 3.557471 98.658882 62° 63° 1° Rata-Rata 3.557109 98.658201 3.557471 98.658882 62° 62,8° 0,8°
Grafik hasil pengujian autotracking sudut azimuth pertama
61.5 62 62.5 63 63.5 1 2 3 4 5 6 7 8 9 1 0 BE SA R S UD UT ( DE R A JA T) PERCOBAAN
PENGUJIAN AUTOTRACKING
AZIMUTH 1
Tabel hasil pengujian autotracking sudut azimuth kedua
No
Posisi RX Posisi TX Besar Sudut
Perhitungan
Besar Sudut Pengukuran
Besar Kesalahan
Latitude Longitude Latitude Longitude
1 3.557109 98.658201 3.556967 98.659556 96° 95° 1° 2 3.557109 98.658201 3.556967 98.659556 96° 95° 1° 3 3.557109 98.658201 3.556967 98.659556 96° 95° 1° 4 3.557109 98.658201 3.556967 98.659556 96° 95° 1° 5 3.557109 98.658201 3.556967 98.659556 96° 95° 1° 6 3.557109 98.658201 3.556967 98.659556 96° 95° 1° 7 3.557109 98.658201 3.556967 98.659556 96° 95° 1° 8 3.557109 98.658201 3.556967 98.659556 96° 95° 1° 9 3.557109 98.658201 3.556967 98.659556 96° 95° 1° 10 3.557109 98.658201 3.556967 98.659556 96° 95° 1° Rata-Rata 3.557109 98.658201 3.556967 98.659556 96° 95° 1°
Grafik hasil pengujian autotracking sudut azimuth kedua
94.4 94.6 94.8 95 95.2 95.4 95.6 95.8 96 96.2 1 2 3 4 5 6 7 8 9 1 0 BE SA R S UD UT ( DE R A JA T) PERCOBAAN
PENGUJIAN AUTOTRACKING AZIMUTH 2
Tabel hasil pengujian autotracking sudut azimuth ketiga
No
Posisi RX Posisi TX Besar Sudut
Perhitungan
Besar Sudut Pengukuran
Besar Kesalahan
Latitude Longitude Latitude Longitude
1 3.557109 98.658201 3.556495 98.659558 114° 112° 2° 2 3.557109 98.658201 3.556967 98.659556 114° 112° 2° 3 3.557109 98.658201 3.556967 98.659556 114° 113° 1° 4 3.557109 98.658201 3.556967 98.659556 114° 112° 2° 5 3.557109 98.658201 3.556967 98.659556 114° 112° 2° 6 3.557109 98.658201 3.556967 98.659556 114° 112° 2° 7 3.557109 98.658201 3.556967 98.659556 114° 112° 2° 8 3.557109 98.658201 3.556967 98.659556 114° 112° 2° 9 3.557109 98.658201 3.556967 98.659556 114° 112° 2° 10 3.557109 98.658201 3.556967 98.659556 114° 113° 1° Rata-Rata 3.557109 98.658201 3.556967 98.659556 114° 112° 1,8°
Grafik hasil pengujian autotracking sudut azimuth ketiga
111 111.5 112 112.5 113 113.5 114 114.5 1 2 3 4 5 6 7 8 9 1 0 BE SA R S UD UT ( DE R A JA T) PERCOBAAN
PENGUJIAN AUTOTRACKING AZIMUTH 3
Tabel hasil pengujian autotracking sudut elevasi pertama No Ketinggian RX (m) Ketinggian TX (m) Jarak kedua Stasiun (m) Besar Sudut Perhitungan Besar Sudut Pengukuran Besar Kesalahan 1 71 76 17,37 16° 16° 0° 2 71 76 17,37 16° 17° 1° 3 71 76 17,37 16° 16° 0° 4 71 76 17,37 16° 16° 0° 5 71 76 17,37 16° 16° 0° 6 71 76 17,37 16° 17° 1° 7 71 76 17,37 16° 17° 1° 8 71 76 17,37 16° 16° 0° 9 71 76 17,37 16° 16° 0° 10 71 76 17,37 16° 15° 1° Rata-Rata 71 76 17,37 16° 16,2° 0,4°
Grafik hasil pengujian autotracking sudut elevasi pertama
14 14.5 15 15.5 16 16.5 17 17.5 1 2 3 4 5 6 7 8 9 1 0 BE SA R S UD UT ( DE R A JA T) PERCOBAAN
PENGUJIAN AUTOTRACKING ELEVASI 1
Tabel hasil pengujian autotracking sudut elevasi kedua No Ketinggian RX (m) Ketinggian TX (m) Jarak kedua Stasiun (m) Besar Sudut Perhitungan Besar Sudut Pengukuran Besar Kesalahan 1 71 81 17,37 30° 31° 1° 2 71 81 17,37 30° 32° 2° 3 71 81 17,37 30° 30° 0° 4 71 81 17,37 30° 31° 1° 5 71 81 17,37 30° 31° 1° 6 71 81 17,37 30° 31° 1° 7 71 81 17,37 30° 32° 2° 8 71 81 17,37 30° 31° 1° 9 71 81 17,37 30° 31° 1° 10 71 81 17,37 30° 31° 1° Rata-Rata 71 81 17,37 30° 31,1° 1,1°
Grafik hasil pengujian autotracking sudut elevasi kedua
29 29.5 30 30.5 31 31.5 32 32.5 1 2 3 4 5 6 7 8 9 1 0 BE SA R S UD UT ( DE R A JA T) PERCOBAAN
PENGUJIAN AUTOTRACKING ELEVASI 2
Tabel hasil pengujian autotracking sudut elevasi ketiga No Ketinggian RX (m) Ketinggian TX (m) Jarak kedua Stasiun (m) Besar Sudut Perhitungan Besar Sudut Pengukuran Besar Kesalahan 1 71 86 17,37 41° 41° 0° 2 71 86 17,37 41° 41° 0° 3 71 86 17,37 41° 40° 1° 4 71 86 17,37 41° 40° 1° 5 71 86 17,37 41° 41° 0° 6 71 86 17,37 41° 41° 0° 7 71 86 17,37 41° 41° 0° 8 71 86 17,37 41° 41° 0° 9 71 86 17,37 41° 41° 0° 10 71 86 17,37 41° 41° 0° Rata-Rata 71 86 17,37 41° 40,8° 0,2°
Grafik hasil pengujian autotracking sudut elevasi ketiga
39.4 39.6 39.8 40 40.2 40.4 40.6 40.8 41 41.2 1 2 3 4 5 6 7 8 9 1 0 BE SA R S UD UT ( DE R A JA T) PERCOBAAN