1,3 → 1,6 |
#ifndef _CONTROLMIXER_H |
#define _CONTROLMIXER_H |
|
#include <inttypes.h> |
/* |
* An attempt to define a generic control. That could be an R/C receiver, an external control |
9,66 → 12,6 |
*/ |
|
/* |
* Signal qualities, used to determine the availability of a control. |
* NO_SIGNAL means there was never a signal. SIGNAL_LOST that there was a signal, but it was lost. |
* SIGNAL_BAD is too bad for flight. This is the hysteresis range for deciding whether to engage |
* or disengage emergency landing. |
* SIGNAL_OK means the signal is usable for flight. |
* SIGNAL_GOOD means the signal can also be used for setting parameters. |
*/ |
#define NO_SIGNAL 0 |
#define SIGNAL_LOST 1 |
#define SIGNAL_BAD 2 |
#define SIGNAL_OK 3 |
#define SIGNAL_GOOD 4 |
|
/* |
* The PRTY arrays |
*/ |
#define CONTROL_PITCH 0 |
#define CONTROL_ROLL 1 |
#define CONTROL_THROTTLE 2 |
#define CONTROL_YAW 3 |
|
/* |
* Looping flags. |
* LOOPING_UP || LOOPING_DOWN <=> LOOPING_PITCH_AXIS |
* LOOPING_LEFT || LOOPING_RIGHT <=> LOOPING_ROLL_AXIS |
*/ |
#define LOOPING_UP (1<<0) |
#define LOOPING_DOWN (1<<1) |
#define LOOPING_LEFT (1<<2) |
#define LOOPING_RIGHT (1<<3) |
#define LOOPING_PITCH_AXIS (1<<4) |
#define LOOPING_ROLL_AXIS (1<<5) |
|
/* |
* This is only relevant for "abstract controls" ie. all control sources have the |
* same interface. This struct of code pointers is used like an abstract class |
* definition from object-oriented languages, and all control input implementations |
* will declare an instance of the stuct (=implementation of the abstract class). |
*/ |
typedef struct { |
/* Get the pitch input in the nominal range [-STICK_RANGE, STICK_RANGE]. */ |
int16_t(*getPitch)(void); |
|
/* Get the roll input in the nominal range [-STICK_RANGE, STICK_RANGE]. */ |
int16_t(*getRoll)(void); |
|
/* Get the yaw input in the nominal range [-STICK_RANGE, STICK_RANGE]. */ |
int16_t(*getYaw)(void); |
|
/* Get the throttle input in the nominal range [0, THROTTLE_RANGE]. */ |
uint16_t(*getThrottle)(void); |
|
/* Signal quality, by the above SIGNAL_... definitions. */ |
uint8_t (*getSignalQuality)(void); |
|
/* Calibrate sticks to their center positions (only relevant for R/C, really) */ |
void (*calibrate)(void); |
} t_control; |
|
/* |
* Our output. |
*/ |
extern int16_t controls[4]; |
95,16 → 38,7 |
uint8_t controlMixer_getSignalQuality(void); |
extern uint8_t controlMixer_didReceiveSignal; |
|
/* |
* The controls operate in [-1024, 1024] just about. |
* Throttle is [0..255] just about. |
*/ |
// Scale controls to 1 byte: |
#define CONTROL_SCALING (1024/256) |
|
// Scale throttle levels to byte: |
#define MOTOR_SCALING (1024/256) |
|
/* |
* Gets the argument for the current command (a number). |
* |
122,3 → 56,5 |
*/ |
uint8_t controlMixer_getArgument(void); |
uint8_t controlMixer_isCommandRepeated(void); |
|
#endif |