Rev 1612 | Rev 1775 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1612 | dongfang | 1 | #include <inttypes.h> |
2 | /* |
||
3 | * The throttle range is normalized to [0, THROTTLE_RANGE[ |
||
4 | * This is the normal range. Exceeding it a little is allowed. |
||
5 | */ |
||
6 | #define THROTTLE_RANGE 256 |
||
7 | |||
8 | /* |
||
9 | * The stick (pitch, roll, yaw) ranges are normalized to [-STICK_RANGE, STICK_RANGE] |
||
10 | * This is the normal range. Exceeding it a little is allowed. |
||
11 | */ |
||
12 | #define STICK_RANGE 256 |
||
13 | |||
14 | /* |
||
15 | * An attempt to define a generic control. That could be an R/C receiver, an external control |
||
16 | * (serial over Bluetooth, Wi232, XBee, whatever) or the NaviCtrl. |
||
17 | * This resembles somewhat an object-oriented class definition (except that there are no virtuals). |
||
18 | * The idea is that the combination of different control inputs, of the way they superimpose upon |
||
19 | * each other, the proirities between them and the behavior in case that one fails is simplified, |
||
20 | * and all in one place. |
||
21 | */ |
||
22 | |||
23 | /* |
||
24 | * Signal qualities, used to determine the availability of a control. |
||
25 | * NO_SIGNAL means there was never a signal. SIGNAL_LOST that there was a signal, but it was lost. |
||
26 | * SIGNAL_BAD is too bad for flight. This is the hysteresis range for deciding whether to engage |
||
27 | * or disengage emergency landing. |
||
28 | * SIGNAL_OK means the signal is usable for flight. |
||
29 | * SIGNAL_GOOD means the signal can also be used for setting parameters. |
||
30 | */ |
||
31 | #define NO_SIGNAL 0 |
||
32 | #define SIGNAL_LOST 1 |
||
33 | #define SIGNAL_BAD 2 |
||
34 | #define SIGNAL_OK 3 |
||
35 | #define SIGNAL_GOOD 4 |
||
36 | |||
37 | /* |
||
38 | * An enumeration over the start motors, stop motors, calibrate gyros |
||
39 | * and calibreate acc. meters commands. |
||
40 | */ |
||
41 | #define COMMAND_NONE 0 |
||
42 | #define COMMAND_START 6 |
||
43 | #define COMMAND_STOP 8 |
||
44 | #define COMMAND_GYROCAL 2 |
||
45 | #define COMMAND_ACCCAL 4 |
||
46 | |||
47 | /* |
||
48 | * The PRTY arrays |
||
49 | */ |
||
50 | #define CONTROL_PITCH 0 |
||
51 | #define CONTROL_ROLL 1 |
||
52 | #define CONTROL_THROTTLE 2 |
||
53 | #define CONTROL_YAW 3 |
||
54 | |||
55 | /* |
||
56 | * Looping flags. |
||
57 | * LOOPING_UP || LOOPING_DOWN <=> LOOPING_PITCH_AXIS |
||
58 | * LOOPING_LEFT || LOOPING_RIGHT <=> LOOPING_ROLL_AXIS |
||
59 | */ |
||
60 | #define LOOPING_UP (1<<0) |
||
61 | #define LOOPING_DOWN (1<<1) |
||
62 | #define LOOPING_LEFT (1<<2) |
||
63 | #define LOOPING_RIGHT (1<<3) |
||
64 | #define LOOPING_PITCH_AXIS (1<<4) |
||
65 | #define LOOPING_ROLL_AXIS (1<<5) |
||
66 | |||
67 | /* |
||
68 | * This is only relevant for "abstract controls" ie. all control sources have the |
||
69 | * same interface. This struct of code pointers is used like an abstract class |
||
70 | * definition from object-oriented languages, and all control input implementations |
||
71 | * will declare an instance of the stuct (=implementation of the abstract class). |
||
72 | */ |
||
73 | typedef struct { |
||
74 | /* Get the pitch input in the nominal range [-STICK_RANGE, STICK_RANGE]. */ |
||
75 | int16_t(*getPitch)(void); |
||
76 | |||
77 | /* Get the roll input in the nominal range [-STICK_RANGE, STICK_RANGE]. */ |
||
78 | int16_t(*getRoll)(void); |
||
79 | |||
80 | /* Get the yaw input in the nominal range [-STICK_RANGE, STICK_RANGE]. */ |
||
81 | int16_t(*getYaw)(void); |
||
82 | |||
83 | /* Get the throttle input in the nominal range [0, THROTTLE_RANGE]. */ |
||
84 | uint16_t(*getThrottle)(void); |
||
85 | |||
86 | /* Signal quality, by the above SIGNAL_... definitions. */ |
||
87 | uint8_t (*getSignalQuality)(void); |
||
88 | |||
89 | /* Calibrate sticks to their center positions (only relevant for R/C, really) */ |
||
90 | void (*calibrate)(void); |
||
91 | } t_control; |
||
92 | |||
93 | /* |
||
94 | * Our output. |
||
95 | */ |
||
1645 | - | 96 | extern int16_t control[2], controlYaw, controlThrottle; |
1612 | dongfang | 97 | // extern int16_t stickOffsetNick, stickOffsetRoll; |
1645 | - | 98 | extern uint16_t maxControl[2]; |
1612 | dongfang | 99 | extern uint8_t looping; |
100 | |||
101 | void controlMixer_initVariables(void); |
||
102 | void controlMixer_updateVariables(void); |
||
103 | |||
104 | void controlMixer_setNeutral(uint8_t calibrate); |
||
105 | |||
106 | /* |
||
107 | * Update the exported variables. Called at every flight control cycle. |
||
108 | */ |
||
109 | void controlMixer_update(void); |
||
110 | |||
111 | /* |
||
112 | * Get the current command. See the COMMAND_.... define's |
||
113 | */ |
||
114 | uint8_t controlMixer_getCommand(void); |
||
115 | |||
116 | void controlMixer_performCalibrationCommands(uint8_t command); |
||
117 | |||
118 | uint8_t controlMixer_getSignalQuality(void); |
||
119 | |||
1645 | - | 120 | /* |
121 | * The motor throttles can be set in an [0..256[ interval. |
||
122 | * The calculation of motor throttle values from sensor and control information (basically |
||
123 | * flight.c) take place in an [0..256*CONTROL_SCALING[ interval for better precision. |
||
124 | */ |
||
125 | #define CONTROL_SCALING 4 |
||
1612 | dongfang | 126 | |
127 | /* |
||
128 | * Gets the argument for the current command (a number). |
||
129 | * |
||
130 | * Stick position to argument values (for stick control): |
||
131 | * 2--3--4 |
||
132 | * | | + |
||
133 | * 1 9 5 ^ 0 |
||
134 | * | | | |
||
135 | * 8--7--6 |
||
136 | * |
||
137 | * + <-- |
||
138 | * 0 |
||
139 | * |
||
140 | * Not in any of these positions: 0 |
||
141 | */ |
||
142 | uint8_t controlMixer_getArgument(void); |
||
143 | uint8_t controlMixer_isCommandRepeated(void); |
||
144 | // TODO: Abstract away if possible. |
||
145 | // void controlMixer_setCompassCalState(void); |
||
146 | // void controlMixer_updateCompass(void); |