forked from Lexicon121/Strix-Interceptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain initializer.cpp
127 lines (105 loc) · 7.7 KB
/
Main initializer.cpp
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <AP_Math.h> // ArduPilot math library
#include <AP_Common.h> // ArduPilot common library
#include <AP_Param.h> // ArduPilot parameter library
#include <AP_HAL.h> // ArduPilot hardware abstraction layer library
#include <AP_HAL_ChibiOS.h> // ArduPilot ChibiOS HAL library
#include <AP_HAL_Empty.h> // ArduPilot Empty HAL library
#include <AP_HAL_Linux.h> // ArduPilot Linux HAL library
#include <AP_HAL_PX4.h> // ArduPilot PX4 HAL library
#include <AP_HAL_AVR.h> // ArduPilot AVR HAL library
#include <AP_HAL_AVR_SITL.h> // ArduPilot AVR SITL HAL library
#include <AP_HAL_Boards.h> // ArduPilot board definition library
#include <AP_HAL_Empty.h> // ArduPilot Empty HAL library
#include <AP_InertialSensor.h> // ArduPilot inertial sensor library
#include <AP_AHRS.h> // ArduPilot attitude and heading reference system library
#include <AP_BoardConfig.h> // ArduPilot board configuration library
#include <AP_HAL_Empty.h> // ArduPilot Empty HAL library
#include <AP_Motors.h> // ArduPilot motor control library
#include <AP_MotorsMatrix.h> // ArduPilot matrix motor control library
#include <AP_MotorsQuad.h> // ArduPilot quadcopter motor control library
#include <AP_MotorsTri.h> // ArduPilot tricopter motor control library
#include <AP_GPS.h> // ArduPilot GPS library
#include <AP_Compass.h> // ArduPilot compass library
#include <AP_Airspeed.h> // ArduPilot airspeed library
#include <AP_RangeFinder.h> // ArduPilot rangefinder library
#include <AP_Terrain.h> // ArduPilot terrain library
#include <AP_Buffer.h> // ArduPilot buffer library
#include <AP_Audio.h> // ArduPilot audio library
#include <AP_LED.h> // ArduPilot LED library
#include <AP_Mission.h> // ArduPilot mission library
#include <AP_NavEKF3.h> // ArduPilot navigation EKF3 library
#include <AP_NavEKF3_Core.h> // ArduPilot navigation EKF3 core library
#include <AP_Logger.h> // ArduPilot logger library
#include <AP_Perfmon.h> // ArduPilot performance monitoring library
#include <AP_WebServer.h> // ArduPilot web server library
#include <opencv2/opencv.hpp> // OpenCV library
using namespace cv;
int main(int argc, char *argv[])
{
// initialize the flight controller
AP_HAL_Empty hal_empty; // create an instance of the ArduPilot Empty HAL
AP_HAL::set_hardware(&hal_empty); // set the ArduPilot hardware
AP_HAL::set_scheduler(&hal_empty.scheduler); // set the ArduPilot scheduler
AP_HAL::set_fast_loop_timer(&hal_empty.scheduler_timer);// set the ArduPilot fast loop timer
AP_HAL::set_semaphore(&hal_empty.semaphore); // set the ArduPilot semaphore
// initialize the sensors
AP_InertialSensor ins; // create an instance of the ArduPilot inertial sensor
AP_AHRS ahrs(&ins); // create an instance of the ArduPilot AHRS using the inertial sensor
AP_GPS gps; // create an instance of the ArduPilot GPS
AP_Compass compass; // create an instance of the ArduPilot compass
AP_Airspeed airspeed; // create an instance of the ArduPilot airspeed sensor
AP_RangeFinder rangefinder; // create an instance of the ArduPilot rangefinder
AP_Terrain terrain; // create an instance of the ArduPilot terrain library
// initialize the motors
AP_MotorsQuad motors; // create an instance of the ArduPilot quadcopter motor control library
AP_MotorsMatrix motor_matrix; // create an instance of the ArduPilot matrix motor control library
AP_MotorsTri motor_tri; // create an instance of the ArduPilot tricopter motor control library
// initialize the audio, LED, and mission systems
AP_Buffer buffer; // create an instance of the ArduPilot buffer library
AP_Audio audio; // create an instance of the ArduPilot audio library
AP_LED led; // create an instance of the ArduPilot LED library
AP_Mission mission; // create an instance of the ArduPilot mission library
// initialize the navigation and logging systems
AP_NavEKF3_Core nav_ekf3_core(&ins, &gps, &compass, &airspeed, &rangefinder, &terrain); // create an instance of the ArduPilot navigation EKF3 core library using the sensors
AP_NavEKF3 nav_ekf3(&nav_ekf3_core); // create an instance of the ArduPilot navigation EKF3 library
AP_Logger logger; // create an instance of the ArduPilot logger library
AP_Perfmon perfmon; // create an instance of the ArduPilot performance monitoring library
AP_WebServer webserver; // create an instance of the ArduPilot web server library
// initialize the camera and image processing variables
VideoCapture cap(0); // create an instance of the OpenCV camera object
Mat frame, edges; // create instances of the OpenCV frame and edge matrices
int low_threshold = 100; // set the low threshold for the Canny edge detection algorithm
int high_threshold = 200; // set the high threshold for the Canny edge detection algorithm
// run the flight controller loop
while (true) {
// read sensor data
ins.update(); // update the inertial sensor data
gps.update(); // update the GPS data
compass.update(); // update the compass data
airspeed.update(); // update the airspeed data
rangefinder.update(); // update the rangefinder data
terrain.update(); // update the terrain data
// run navigation algorithm
nav_ekf3.update(); // update the navigation EKF3 algorithm
// process camera data
cap >> frame; // read a frame from the camera
cvtColor(frame, edges, COLOR_BGR2GRAY); //
convert the color of the frame to grayscale
Canny(edges, edges, low_threshold, high_threshold); // apply the Canny edge detection algorithm to the grayscale image
// run motor control algorithm
motors.output(); // update the motor outputs for the quadcopter
motor_matrix.output(); // update the motor outputs for the matrix motor configuration
motor_tri.output(); // update the motor outputs for the tricopter
// run audio, LED, and mission systems
buffer.update(); // update the buffer
audio.update(); // update the audio system
led.update(); // update the LED system
mission.update(); // update the mission system
// log data
logger.update(); // update the logger
perfmon.update(); // update the performance monitoring system
// handle web server requests
webserver.handle_requests(); // handle any incoming web server requests
}
return 0;
}