int main(void) { //******************************************************************* Init(); TMRInit(2); // Initialize Timer interface with Priority=2 BLIInit(); // Initialize Signal interface ADCInit(3); // Initialize ADC UARTInitTX(6, 350); // Initialize UART1 for TX // This initialization routine accepts BaudRate in multiples // of 2400 bps; Thus: // BaudRate = 1 => 2400 bps // BaudRate = 2 => 4800 bps // ... // BaudRate = 48 => 115200 bps //------------------------------------------------------------ // High speed //------------------------------------------------------------ // BaudRate = 100 => 250,000 bps // BaudRate = 200 => 500,000 bps // BaudRate = 250 => 625,000 bps // BaudRate = 350 => 833,333 bps // BaudRate = 500 => 1,250,000 bps // BaudRate = 1000 => 2,500,000 bps //******************************************************************* struct { float V; uint Raw; uint Stat; } UData; int i = 0; int j = 0; BLISignalON(); while(j < 10) { TMRDelay(10); //-------------------------- UData.V = ADCGetBatteryVoltage(); UData.Raw = ADCGetRawSample(); UData.Stat = ADCGetBatteryStatus(); //-------------------------- UARTPostWhenReady((uchar*)&UData, sizeof(UData)); i++; //-------------------------- if (i >= 100) { UARTPostWhenReady(NULL, 0); BLISignalFlip(); //------------------------ i = 0; j++; } TMRDelay(10); } return 1; }
int main(void) { //******************************************************************* Init(); TMRInit(2); // Initialize Timer interface with Priority=2 BLIInit(); // Initialize Signal interface //-------------------------- BLIAsyncMorse("S", 1); // dot-dot-dot MCMInitF(50, 2500); // Initialize Motor Control at 50 Hz with setting // Throttle to HIGH for delay interval to let ESC // capture Throttle range BLIAsyncStop(); //-------------------------- RCInit(4); // Initialize Receiver interface with Priority=4 //-------------------------- UARTInitTX(6, 48); // Initialize UART1 for TX on IPL=6 at 115200 bps // This initialization routine accepts BaudRate in multiples // of 2400 bps; Thus: // BaudRate = 1 => 2400 bps // BaudRate = 2 => 4800 bps // ... // BaudRate = 48 => 115200 bps //------------------------------------------------------------ // High speed //------------------------------------------------------------ // BaudRate = 100 => 250,000 bps // BaudRate = 200 => 500,000 bps // BaudRate = 250 => 625,000 bps // BaudRate = 350 => 833,333 bps // BaudRate = 500 => 1,250,000 bps // BaudRate = 1000 => 2,500,000 bps //******************************************************************* BLISignalON(); TMRDelay(2000); // Wait for extra 2 sec - to let ESC arm... // (finish the song :) ) BLISignalOFF(); //================================================================== MCMData MC; RCData RC; //------------------------------------------------- BLIAsyncMorse("R", 1); // dot-doh-dot RCArm(); BLIAsyncStop(); //------------------------------------------------- BLISignalON(); while(1) { RCReadWhenReady(&RC); //--------------------------------------------- if (0 == RC.Control) MC.F = MC.B = MC.L = MC.R = 0.0; else { MC.F = RC.Throttle; MC.B = RC.Throttle; //-------------- MC.L = RC.Throttle; MC.R = RC.Throttle; //-------------- } //--------------------------------------------- MCMSet(&MC); //--------------------------------------------- UARTPostWhenReady((uchar*)&RC, sizeof(RC)); //--------------------------------------------- BLISignalFlip(); } return 1; }
int main(void) { //******************************************************************* Init(); TMRInit(2); // Initialize Timer interface with Priority=2 BLIInit(); // Initialize Signal interface I2CInit(5, 0); // Initialize I2C1 module with IPL=5 and Fscl=400 KHz //-------------------------- TMRDelay(1000); // Wait for 1 sec so that the shake from turning on // power switch dissipates... //-------------------------- if (MPUInit(3, 1)) // Initialize motion Sensor - 1 kHz/4 (250 Hz) BLIDeadStop("EA", 2); //-------------------------- #ifdef __MAG_Use__ if (HMCInit(6, 1, 0)) // Initialize magnetic Sensor // ODR = 6 (max, 75 Hz), // Gain = 2 (1.3 Gs) // DLPF = 0 (no averaging) BLIDeadStop("EM", 2); #endif //-------------------------- UARTInitTX(6, 48); // Initialize UART1 for TX on IPL=6 at 115200 bps // This initialization routine accepts BaudRate in multiples // of 2400 bps; Thus: // BaudRate = 1 => 2400 bps // BaudRate = 2 => 4800 bps // ... // BaudRate = 48 => 115200 bps //------------------------------------------------------------ // High speed //------------------------------------------------------------ // BaudRate = 100 => 250,000 bps // BaudRate = 200 => 500,000 bps // BaudRate = 250 => 625,000 bps // BaudRate = 350 => 833,333 bps // BaudRate = 500 => 1,250,000 bps // BaudRate = 1000 => 2,500,000 bps //******************************************************************* uint RC = 0; //-------------------------- MPUSample AGSample; #ifdef __MAG_Use__ HMCSample MSample; #endif //-------------------------- if (MPUAsyncStart()) BLIDeadStop("A", 1); //-------------------------- #ifdef __MAG_Use__ if (HMCAsyncStart()) BLIDeadStop("M", 1); #endif //-------------------------- struct { ulong TS; // Timestamp of the cycle //----------------------------------------------- ulong MPUCount; // Sequential number of MPU sample #ifdef __MAG_Use__ ulong MAGCount; // Sequential number of MAG sample #endif //----------------------------------------------- // Accelerometer (in units of G) //----------------------------------------------- Vector A; //----------------------------------------------- // Gyroscopes (in Rad/sec) //----------------------------------------------- Vector G; #ifdef __MAG_Use__ //----------------------------------------------- // Magnetometer (in mGs) //----------------------------------------------- Vector M; #endif } UData; //******************************************************************* BLISignalON(); while(1) { TMRDelay(100); //------------------------ #ifdef __MAG_Use__ RC = HMCAsyncReadWhenReady(&MSample); if (RC) BLIDeadStop("M", 1); #endif //------------------------ RC = MPUAsyncReadWhenReady(&AGSample); if (RC) BLIDeadStop("A", 1); //--------------------------------------------- UData.MPUCount = AGSample.Count; #ifdef __MAG_Use__ UData.MAGCount = MSample.Count; #endif //------------------------ VectorCopy(&AGSample.A, &UData.A); VectorCopy(&AGSample.G, &UData.G); #ifdef __MAG_Use__ VectorCopy(&MSample.M, &UData.M); #endif //------------------------ UData.TS = AGSample.TS; //--------------------------------------------- UARTPostWhenReady((uchar*)&UData, sizeof(UData)); //--------------------------------------------- BLISignalFlip(); } return 1; }
int main(void) { //******************************************************************* Init(); TMRInit(2); // Initialize Timer interface with Priority=2 BLIInit(); // Initialize Signal interface ADCInit(3); // Initialize ADC to control battery I2CInit(5, 0); // Initialize I2C1 module with IPL=5 and Fscl=400 KHz //-------------------------- BLISignalON(); //-------------------------- if (MPUInit(3, 1)) // Initialize motion Sensor - 1 kHz/4 (250 Hz) DeadStop("A", 1); //-------------------------- BLISignalOFF(); //-------------------------- UARTInitTX(6, 48); // Initialize UART1 for TX on IPL=6 at 115200 bps // This initialization routine accepts BaudRate in multiples // of 2400 bps; Thus: // BaudRate = 1 => 2400 bps // BaudRate = 2 => 4800 bps // ... // BaudRate = 48 => 115200 bps //------------------------------------------------------------ // High speed //------------------------------------------------------------ // BaudRate = 100 => 250,000 bps // BaudRate = 200 => 500,000 bps // BaudRate = 250 => 625,000 bps // BaudRate = 350 => 833,333 bps // BaudRate = 500 => 1,250,000 bps // BaudRate = 1000 => 2,500,000 bps //******************************************************************* uint RC = 0; //-------------------------- _MPURawData RawData; //-------------------------- struct { ulong TS; // Timestamp of the cycle //----------------------------------------------- // Temperature //----------------------------------------------- float Temp; //----------------------------------------------- // Accelerometer //----------------------------------------------- float AX; float AY; float AZ; //----------------------------------------------- // Gyroscopes //----------------------------------------------- float GX; float GY; float GZ; //----------------------------------------------- } UData; //******************************************************************* long AX, AY, AZ, GX, GY, GZ, Temp; //******************************************************************* while(1) { //------------------------ if (ADCGetBatteryStatus() < 30) DeadStop("SOS", 3); //------------------------ AX= AY= AZ= GX= GY= GZ= Temp = 0; //------------------------ int i; for (i=0; i<128; i++) { RC = _MPUReadRawData(&RawData); if (RC) DeadStop("A", 1); //----------------------------- AX += RawData.AX; AY += RawData.AY; AZ += RawData.AZ; //----------------- GX += RawData.GX; GY += RawData.GY; GZ += RawData.GZ; //----------------- Temp+= RawData.Temp; //----------------------------- } //--------------------------------------------- UData.TS = TMRGetTS(); //------------------------ UData.Temp = ((float)Temp/128.0 - _MPU_Temp_OffsetTo0) * _MPU_Temp_Sensitivity - 25.0; //------------------------ UData.AX = (float)AX/128.0; UData.AY = (float)AY/128.0; UData.AZ = (float)AZ/128.0; //------------------------ UData.GX = (float)GX/128.0; UData.GY = (float)GY/128.0; UData.GZ = (float)GZ/128.0; //--------------------------------------------- UARTPostWhenReady((uchar*)&UData, sizeof(UData)); //--------------------------------------------- } return 1; }