-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting.py
More file actions
72 lines (61 loc) · 2.74 KB
/
testing.py
File metadata and controls
72 lines (61 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# from serial import Serial
# import dronekit as dk
# import time
# from time import strftime
# from pymavlink import mavutil
from datetime import datetime
from digi.xbee.devices import XBeeDevice
from digi.xbee.devices import RemoteXBeeDevice
from digi.xbee.models.address import XBee64BitAddress
import serial
import pandas as pd
# import matplotlib.pyplot as plt
# =========== CONFIGURATION ===========
# PORT = "/dev/tty.usbserial-AB0OPBOT"
PORT = "COM6" # matched with MAC: 0013A200422F2FDF
BAUDRATE = 9600
# open serial port on wired XBee
localXbee = XBeeDevice(PORT, BAUDRATE) # connect the device
localXbee.open()
# Option 1. Setup remote Xbee drone with MAC address of the current plugged in XBee (same as localXbee)
# remote_xbee_address = localXbee.get_64bit_addr()
# droneXbee = RemoteXBeeDevice(localXbee, remote_xbee_address)
# Option 2. OR get the MAC address of a remote XBee (found on the underside of the smaller chip on the XBee board)
# remote_xbee_address = "0013A200422F2FDF"
# remote_xbee_address = "13A200422F2FDF" # Xbee_A, COM3?
remote_xbee_address = "13A20041D365C4" #Xbee_C, COM6?
# remote_xbee_address = "13A200420396EE" #GCSXbee, COM7?
droneXbee = RemoteXBeeDevice(localXbee, XBee64BitAddress.from_hex_string(remote_xbee_address))
print("XBee open")
def data_receive_callback(xbee_message):
# Callback function when data is received
print(f"Received data: {xbee_message.data.decode()}")
# localXbee.send_data_async(droneXbee, "hi drone")
def send_UAV_data_Xbee(ICAO, pos_lat, pos_lon, pos_alt_rel,velocity,airspeed,battery):
#print("In send ADSB funtion\n")
msg = "ICAO: " + ICAO + '\n'
msg += "Lattitude: " + str(pos_lat) + '\n'
msg += "Longitude: " + str(pos_lon) + '\n'
msg += "Altitude: " + str(pos_alt_rel) + '\n'
msg += "Velocity: " + str(velocity) + '\n'
msg += "Airspeed: " + str(round(airspeed,5)) + '\n'
#make sure that this line works; changed from vehicle.battery.voltage to battery parameter
msg += "Battery Level: " + str(battery) + '\n'
print(msg)
return msg
localXbee.add_data_received_callback(data_receive_callback)
# =========== TRANSMISSION / RECEPTION ===========
data_list = []
i = 0
# localXbee.send_data_async(droneXbee, "hi drone")
while (True):
i += .00001
localXbee.send_data_async(droneXbee, send_UAV_data_Xbee("A", float(34.04285) + i, float(-117.81194) + i, [0.0, 0.0, 0.0], 0, 100))
# print(i)
# # print(str(i) + " sending")
# # localXbee.send_data_async(droneXbee, "something")
# # print(str(i) + " recieving")
# message = localXbee.read_data(5) # Wait __ seconds before calling a timeout exception
# data_list.append({'Sent Time': message.timestamp, 'Received Time': datetime.now().timestamp()})
localXbee.close()
print("XBee closed\n")