Subversion Repositories FlightCtrl

Rev

Details | Last modification | View Log | RSS feed

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