branch for tests with T265
Dependencies: Lib_Cntrl AHRS Lib_Misc
Sources/main.cpp
- Committer:
- altb2
- Date:
- 2019-10-09
- Revision:
- 1:d8c9f6b16279
- Parent:
- 0:a479dc61e931
File content as of revision 1:d8c9f6b16279:
#define PI 3.141592653589793 #include "mbed.h" #define _MBED_ #include "LinearCharacteristics.h" #include "UAV.h" #include "RCin.h" #include "define_constants.h" #include "PID_Cntrl.h" #include "IIR_filter.h" #include "data_structs.h" #include "Signal.h" #include "RangeFinder.h" #include "AHRS.h" #include "TFMini_i2c.h" #include "data_structs.h" #include "Controller_Loops.h" #include "QK_StateMachine.h" #include "Data_Logger.h" #include "Read_Xtern_Sensors.h" // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- // define IOs Serial pc(SERIAL_TX, SERIAL_RX,115200); // serial connection via USB - programmer PwmOut motor_pwms[4] = {PC_6,PC_8,PB_14,PB_9}; // ---------------------------------------------------------------------------- RCin myRC(PB_6); // read PWM of RC (Graupner Hott) // ---------------------------------------------------------------------------- // PX4 Optical flow (OF), use same i2c like imu I2C i2c(PC_9, PA_8); PX4Flow optical_flow(i2c); TFMini_i2c tfmini(&i2c,0x10); // ----------------------------------------------------------------------------- // Timers Timer global_timer; // in main loop // ----------------------------------------------------------------------------- // The copter! UAV copter(QUAD2,AIRGEAR350); // Copter and Motor definition // ----------------------------------------------------------------------------- DATA_Xchange data; // ----------------------------------------------------------------------------- // sample rates float Ts200 = 0.005f; float Ts100 = 0.01f; float Ts50 = 0.02f; float Ts25 = 0.04f; // ----------------------------------- float TsCntrl = Ts200; // ----------------------------------- // some values needed float dt; // time elapsed in current state // ------ THREADS --- THREADS --- THREADS --- THREADS --- THREADS --- Controller_Loops controller(TsCntrl,4,4,true); // run ahrs within the controller Thread // controllers are not properly initialized at this point (esp limits)!!! //AHRS ahrs(1,Ts100,true); Read_Xtern_Sensors xternal_sens(Ts50); // read external sensors (OF, Lidar etc. QK_StateMachine main_statemachine(Ts50); // the main state machine Data_Logger my_datalogger(22,Ts50); // the data logger // ----------------------------------------------------------------------------- // MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN // ----------------------------------------------------------------------------- int main() { i2c.frequency(400000); copter.calc_copter(); // calc the copter (length, etc) controller.set_controller_limits(copter); // finalize init function for controllers wait(.1); for(uint8_t k=0;k < copter.nb_motors;k++) motor_pwms[k].period_ms(5); wait(0.1); myRC.map_Channels(); wait(0.01); global_timer.reset(); global_timer.start(); wait(.1); while(!myRC.isAlive) { wait(.5); pc.printf("Failed to receive RC - signal!\r\n"); } pc.printf("RC - signal is on!\r\n"); wait(.5); // start main threads: controller.init_loop(); wait(0.1); controller.start_loop(); wait(0.1); xternal_sens.start_loop(); wait(0.1); main_statemachine.start_loop(); wait(0.1); my_datalogger.start_logging(); //ahrs.start_loop(); wait(0.1); while(1) wait(1); }