Subversion Repositories FlightCtrl

Rev

Rev 2099 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1910 - 1
#include <inttypes.h>
2
/*
3
 * An attempt to define a generic control. That could be an R/C receiver, an external control
4
 * (serial over Bluetooth, Wi232, XBee, whatever) or the NaviCtrl.
5
 * This resembles somewhat an object-oriented class definition (except that there are no virtuals).
6
 * The idea is that the combination of different control inputs, of the way they superimpose upon
7
 * each other, the priorities between them and the behavior in case that one fails is simplified,
8
 * and all in one place.
9
 */
10
 
11
/*
12
 * Signal qualities, used to determine the availability of a control.
13
 * NO_SIGNAL means there was never a signal. SIGNAL_LOST that there was a signal, but it was lost.
14
 * SIGNAL_BAD is too bad for flight. This is the hysteresis range for deciding whether to engage
15
 * or disengage emergency landing.
16
 * SIGNAL_OK means the signal is usable for flight.
17
 * SIGNAL_GOOD means the signal can also be used for setting parameters.
18
 */
19
#define NO_SIGNAL   0
20
#define SIGNAL_LOST 1
21
#define SIGNAL_BAD  2
22
#define SIGNAL_OK   3
23
#define SIGNAL_GOOD 4
24
 
25
/*
26
 * The EATR arrays
27
 */
28
#define CONTROL_ELEVATOR 0
29
#define CONTROL_AILERONS 1
30
#define CONTROL_THROTTLE 2
31
#define CONTROL_RUDDER   3
32
 
33
/*
34
 * This is only relevant for "abstract controls" ie. all control sources have the
35
 * same interface. This struct of code pointers is used like an abstract class
36
 * definition from object-oriented languages, and all control input implementations
37
 * will declare an instance of the stuct (=implementation of the abstract class).
38
 */
39
typedef struct {
40
        /* Get the pitch input in the nominal range [-STICK_RANGE, STICK_RANGE]. */
41
        int16_t(*getPitch)(void);
42
 
43
        /* Get the roll input in the nominal range [-STICK_RANGE, STICK_RANGE]. */
44
        int16_t(*getRoll)(void);
45
 
46
        /* Get the yaw input in the nominal range [-STICK_RANGE, STICK_RANGE]. */
47
        int16_t(*getYaw)(void);
48
 
49
        /* Get the throttle input in the nominal range [0, THROTTLE_RANGE]. */
50
        uint16_t(*getThrottle)(void);
51
 
52
        /* Signal quality, by the above SIGNAL_... definitions. */
53
        uint8_t (*getSignalQuality)(void);
54
 
55
        /* Calibrate sticks to their center positions (only relevant for R/C, really) */
56
        void (*calibrate)(void);
57
} t_control;
58
 
59
/*
60
 * Our output.
61
 */
62
extern int16_t control[4];
63
extern int32_t controlIntegrals[4];
64
extern uint16_t controlActivity;
65
extern uint16_t maxControl[2];
66
 
67
extern volatile uint8_t MKFlags;
68
extern uint16_t isFlying;
69
 
70
void controlMixer_initVariables(void);
71
void controlMixer_updateVariables(void);
72
 
73
void controlMixer_setNeutral(void);
74
 
75
/*
76
 * Update the exported variables. Called at every flight control cycle.
77
 */
78
void controlMixer_update(void);
79
 
80
/*
81
 * Get the current command. See the COMMAND_.... define's
82
 */
83
uint8_t controlMixer_getCommand(void);
84
 
85
void controlMixer_performCalibrationCommands(uint8_t command);
86
 
87
uint8_t controlMixer_getSignalQuality(void);
88
 
89
/*
90
 * The controls operate in [-1024, 1024] just about.
91
 * Throttle is [0..255] just about.
92
 */
93
// Scale controls to 1 byte:
94
#define CONTROL_SCALING (1024/256)
95
 
96
// Scale throttle levels to byte:
97
#define MOTOR_SCALING (1024/256)
98
 
99
/*
100
 * Gets the argument for the current command (a number).
101
 *
102
 * Stick position to argument values (for stick control):
103
 * 2--3--4
104
 * |     |  +
105
 * 1  9  5  ^ 0
106
 * |     |  |  
107
 * 8--7--6
108
 *    
109
 * + <--
110
 *    0
111
 *
112
 * Not in any of these positions: 0
113
 */
114
// void controlMixer_handleCommands(void);
115
uint8_t controlMixer_getArgument(void);
116
uint8_t controlMixer_isCommandRepeated(void);
117
// TODO: Abstract away if possible.
118
uint8_t controlMixer_testCompassCalState(void);