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