Subversion Repositories FlightCtrl

Rev

Rev 1612 | Rev 1775 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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