Subversion Repositories FlightCtrl

Rev

Rev 2058 | Rev 2069 | 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
 
18
  if (controlMixer_getSignalQuality() <= SIGNAL_BAD) { // the rc-frame signal is not reveived or noisy
19
    if (controlMixer_didReceiveSignal)
20
      beepRCAlarm(); // Only make alarm if a control signal was received before the signal loss.
21
 
22
    // There are the possibilities: We are not yet in emergency flight, we are already in emergency flight.
23
    if (!(MKFlags & MKFLAG_EMERGENCY_FLIGHT)) {
24
      if (isFlying > 256) {
25
        MKFlags |= MKFLAG_EMERGENCY_FLIGHT; // Set flag for emergency landing
2059 - 26
        configuration_setFailsafeFlightParameters();
2056 - 27
        // Set the time in whole seconds.
2059 - 28
        if (staticParams.emergencyFlightDuration > (65535 - (uint16_t)F_MAINLOOP) / (uint16_t)F_MAINLOOP)
2056 - 29
          emergencyFlightTime = 0xffff;
30
        else
2059 - 31
          emergencyFlightTime = (uint16_t)staticParams.emergencyFlightDuration * (uint16_t)F_MAINLOOP;
2056 - 32
      }
33
    } else {
34
      if (emergencyFlightTime) {
35
        emergencyFlightTime--;
36
      } else {
37
        // stop motors but stay in emergency flight.
38
        MKFlags &= ~(MKFLAG_MOTOR_RUN);
39
      }
40
    }
41
 
2058 - 42
    // 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 - 43
    PRTY[CONTROL_THROTTLE] = staticParams.emergencyThrottle; // Set emergency throttle
2058 - 44
    PRTY[CONTROL_PITCH] = PRTY[CONTROL_ROLL] = PRTY[CONTROL_YAW] = 0;
2056 - 45
  } else {
46
    // Signal is OK.
47
    if (MKFlags & MKFLAG_EMERGENCY_FLIGHT) {
48
      MKFlags &= ~MKFLAG_EMERGENCY_FLIGHT; // Clear flag for emergency landing
2059 - 49
      configuration_setNormalFlightParameters();
2056 - 50
    }
51
  }
52
 
53
  /*
54
   * If a Bl-Ctrl is missing, prevent takeoff.
55
   */
56
  if (missingMotor) {
57
    // if we are in the lift off condition. Hmmmmmm when is throttleTerm == 0 anyway???
58
    if (isFlying > 1 && isFlying < 50 && PRTY[CONTROL_THROTTLE] > 0) isFlying = 1; // keep within lift off condition
59
    PRTY[CONTROL_THROTTLE] = staticParams.minThrottle; // reduce throttle to min to prevent takeoff
60
  }
61
}