Subversion Repositories FlightCtrl

Rev

Rev 2059 | Rev 2073 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2056 - 1
#include "controlMixer.h"
2
#include "timer0.h"
3
#include "configuration.h"
4
#include "twimaster.h"
5
#include "flight.h"
6
#include "output.h"
7
 
8
uint16_t emergencyFlightTime;
9
 
2059 - 10
void FC_setNeutral(void) {
11
  configuration_setNormalFlightParameters();
2056 - 12
}
13
 
2059 - 14
void FC_periodicTaskAndPRTY(uint16_t* PRTY) {
2056 - 15
 
2059 - 16
  debugOut.analog[25] = emergencyFlightTime;
2056 - 17
 
2069 - 18
  debugOut.analog[30] = controlMixer_getSignalQuality();
19
 
2056 - 20
  if (controlMixer_getSignalQuality() <= SIGNAL_BAD) { // the rc-frame signal is not reveived or noisy
21
    if (controlMixer_didReceiveSignal)
22
      beepRCAlarm(); // Only make alarm if a control signal was received before the signal loss.
23
 
24
    // There are the possibilities: We are not yet in emergency flight, we are already in emergency flight.
25
    if (!(MKFlags & MKFLAG_EMERGENCY_FLIGHT)) {
26
      if (isFlying > 256) {
27
        MKFlags |= MKFLAG_EMERGENCY_FLIGHT; // Set flag for emergency landing
2059 - 28
        configuration_setFailsafeFlightParameters();
2056 - 29
        // Set the time in whole seconds.
2059 - 30
        if (staticParams.emergencyFlightDuration > (65535 - (uint16_t)F_MAINLOOP) / (uint16_t)F_MAINLOOP)
2056 - 31
          emergencyFlightTime = 0xffff;
32
        else
2059 - 33
          emergencyFlightTime = (uint16_t)staticParams.emergencyFlightDuration * (uint16_t)F_MAINLOOP;
2056 - 34
      }
35
    } else {
36
      if (emergencyFlightTime) {
37
        emergencyFlightTime--;
38
      } else {
39
        // stop motors but stay in emergency flight.
40
        MKFlags &= ~(MKFLAG_MOTOR_RUN);
41
      }
42
    }
43
 
2058 - 44
    // In either case, use e. throttle and neutral controls. TODO: If there is supposed to be a navi come-home, this should affect RC control only and not navi.
2056 - 45
    PRTY[CONTROL_THROTTLE] = staticParams.emergencyThrottle; // Set emergency throttle
2058 - 46
    PRTY[CONTROL_PITCH] = PRTY[CONTROL_ROLL] = PRTY[CONTROL_YAW] = 0;
2056 - 47
  } else {
48
    // Signal is OK.
49
    if (MKFlags & MKFLAG_EMERGENCY_FLIGHT) {
50
      MKFlags &= ~MKFLAG_EMERGENCY_FLIGHT; // Clear flag for emergency landing
2059 - 51
      configuration_setNormalFlightParameters();
2056 - 52
    }
53
  }
54
 
55
  /*
56
   * If a Bl-Ctrl is missing, prevent takeoff.
57
   */
58
  if (missingMotor) {
59
    // if we are in the lift off condition. Hmmmmmm when is throttleTerm == 0 anyway???
60
    if (isFlying > 1 && isFlying < 50 && PRTY[CONTROL_THROTTLE] > 0) isFlying = 1; // keep within lift off condition
61
    PRTY[CONTROL_THROTTLE] = staticParams.minThrottle; // reduce throttle to min to prevent takeoff
62
  }
63
}