Subversion Repositories FlightCtrl

Rev

Rev 1910 | Rev 2099 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1910 Rev 1927
1
#include <stdlib.h>
1
#include <stdlib.h>
2
#include "commands.h"
2
#include "commands.h"
3
#include "controlMixer.h"
3
#include "controlMixer.h"
4
#include "flight.h"
4
#include "flight.h"
5
#include "eeprom.h"
5
#include "eeprom.h"
6
#include "attitude.h"
6
#include "attitude.h"
7
#include "output.h"
7
#include "output.h"
8
 
8
 
9
void commands_handleCommands(void) {
9
void commands_handleCommands(void) {
10
        /*
10
        /*
11
         * Get the current command (start/stop motors, calibrate), if any.
11
         * Get the current command (start/stop motors, calibrate), if any.
12
         */
12
         */
13
        uint8_t command = controlMixer_getCommand();
13
        uint8_t command = controlMixer_getCommand();
14
        uint8_t repeated = controlMixer_isCommandRepeated();
14
        uint8_t repeated = controlMixer_isCommandRepeated();
15
        uint8_t argument = controlMixer_getArgument();
-
 
16
 
15
 
17
        if (!(MKFlags & MKFLAG_MOTOR_RUN)) {
16
        if (!(MKFlags & MKFLAG_MOTOR_RUN)) {
18
                if (command == COMMAND_GYROCAL && !repeated) {
17
                if (command == COMMAND_GYROCAL && !repeated) {
19
                        // Run gyro calibration but do not repeat it.
18
                        // Run gyro calibration but do not repeat it.
20
                        GRN_OFF;
19
                        GRN_OFF;
21
 
20
 
22
                        // TODO: out of here. Anyway, MKFLAG_MOTOR_RUN is cleared. Not enough?
21
                        // TODO: out of here. Anyway, MKFLAG_MOTOR_RUN is cleared. Not enough?
23
                        // isFlying = 0;
22
                        // isFlying = 0;
24
                        // check roll/pitch stick position
23
                        // check roll/pitch stick position
25
                        // if pitch stick is top or roll stick is left or right --> change parameter setting
24
                        // if pitch stick is top or roll stick is left or right --> change parameter setting
26
                        // according to roll/pitch stick position
25
                        // according to roll/pitch stick position
27
 
-
 
28
                        if (argument < 6) {
-
 
29
                                // Gyro calinbration, with or without selecting a new parameter-set.
-
 
30
                                if (argument > 0 && argument < 6) {
-
 
31
                                        // A valid parameter-set (1..5) was chosen - use it.
-
 
32
                                        setActiveParamSet(argument);
-
 
33
                                }
26
 
34
                                ParamSet_ReadFromEEProm(getActiveParamSet());
27
                                ParamSet_ReadFromEEProm();
35
                                attitude_setNeutral();
28
                                attitude_setNeutral();
36
                                flight_setNeutral();
29
                                flight_setNeutral();
37
                                controlMixer_setNeutral();
30
                                controlMixer_setNeutral();
38
                                beepNumber(getActiveParamSet());
-
 
39
                        } else if (staticParams.GlobalConfig & (CFG_COMPASS_ACTIVE
-
 
40
                                        | CFG_GPS_ACTIVE) && argument == 7) {
-
 
41
                                // If right stick is centered and down
-
 
42
                                // TODO: Out of here! State machine instead.
-
 
43
                                compassCalState = 1;
-
 
44
                                beep(1000);
31
                                beepNumber(1);
45
                        }
-
 
46
                }
32
                }
47
 
33
 
48
                // save the ACC neutral setting to eeprom
34
                // save the ACC neutral setting to eeprom
49
                else {
-
 
50
                        if (command == COMMAND_ACCCAL && !repeated) {
35
                else if (command == COMMAND_ACCCAL && !repeated) {
51
                                // Run gyro and acc. meter calibration but do not repeat it.
36
                                // Run gyro and acc. meter calibration but do not repeat it.
52
                                GRN_OFF;
37
                                GRN_OFF;
53
                                analog_calibrateAcc();
38
                                analog_calibrateAcc();
54
                                attitude_setNeutral();
39
                                attitude_setNeutral();
55
                                flight_setNeutral();
40
                                flight_setNeutral();
56
                                controlMixer_setNeutral();
41
                                controlMixer_setNeutral();
57
                                beepNumber(getActiveParamSet());
42
                                beepNumber(1);
58
                        }
-
 
59
                }
43
                }
60
        } // end !MOTOR_RUN condition.
44
        } // end !MOTOR_RUN condition.
61
        if (command == COMMAND_START) {
45
        if (command == COMMAND_START) {
62
                isFlying = 1; // TODO: Really????
46
                isFlying = 1; // TODO: Really????
63
                // if (!controlMixer_isCommandRepeated()) {
47
                // if (!controlMixer_isCommandRepeated()) {
64
                // attitude_startDynamicCalibration(); // Try sense the effect of the motors on sensors.
48
                // attitude_startDynamicCalibration(); // Try sense the effect of the motors on sensors.
65
                MKFlags |= (MKFLAG_MOTOR_RUN | MKFLAG_START); // set flag RUN and START. TODO: Is that START flag used at all???
49
                MKFlags |= (MKFLAG_MOTOR_RUN | MKFLAG_START); // set flag RUN and START. TODO: Is that START flag used at all???
66
                // } else { // Pilot is holding stick, ever after motor start. Continue to sense the effect of the motors on sensors.
50
                // } else { // Pilot is holding stick, ever after motor start. Continue to sense the effect of the motors on sensors.
67
                // attitude_continueDynamicCalibration();
51
                // attitude_continueDynamicCalibration();
68
                // setPointYaw = 0;
52
                // setPointYaw = 0;
69
                // IPartPitch = 0;
53
                // IPartPitch = 0;
70
                // IPartRoll = 0;
54
                // IPartRoll = 0;
71
                // }
55
                // }
72
        } else if (command == COMMAND_STOP) {
56
        } else if (command == COMMAND_STOP) {
73
                isFlying = 0;
57
                isFlying = 0;
74
                MKFlags &= ~(MKFLAG_MOTOR_RUN);
58
                MKFlags &= ~(MKFLAG_MOTOR_RUN);
75
        }
59
        }
76
}
60
}
77
 
61