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