Skip to main content
. 2024 Feb 7;10:e1759. doi: 10.7717/peerj-cs.1759
Algorithm 3. Moving the Laser Pointer towards the drone:
Drone Tracking and Pointer Algorithm: Ensures the LCS’s laser pointer dynamically tracks the drone’s position, adjusting the pan and tilt mechanism in real-time based on GPS and IMU data, maintaining a consistent line of sight.
Input: GPS and IMU values from the drone
Output: Pan and Tilt motors move to the required angles
1: initialize R as 6371000 (Earth’s radius in meters)
2: initialize ground_station_lat as 12.971598 (replace with ground station’s latitude)
3: initialize ground_station_lon as 77.594566 (replace with ground station’s longitude)
4: define haversine_distance(lat1, lon1, lat2, lon2) function
5: convert lat1, lon1, lat2, lon2 to radians
6: calculate dlat as the difference between lat2 and lat1
7: calculate dlon as the difference between lon2 and lon1
8: calculate a using the haversine formula
9: calculate c as 2 * atan2(sqrt(a), sqrt(1 - a))
10: return the product of R and c
11: define calculate_angles(latitude, longitude) function
12: calculate distance using the haversine_distance function
13: calculate dlon as the difference between longitude and ground_station_lon
14: calculate pan_angle using the formula for calculating the bearing
15: convert pan_angle to degrees
16: set tilt_angle as 0
17: return pan_angle and tilt_angle
18: define handle_client(client_socket) function
19: while true do