dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
transmitter_control.h
Go to the documentation of this file.
1 
16 /*
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation; either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful, but
23  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25  * for more details.
26  *
27  * You should have received a copy of the GNU General Public License along
28  * with this program; if not, see <http://www.gnu.org/licenses/>
29  *
30  * Additional note on redistribution: The copyright and license notices above
31  * must be maintained in each individual source file that is a derivative work
32  * of this source file; otherwise redistribution is prohibited.
33  */
34 
35 #ifndef TRANSMITTER_CONTROL_H
36 #define TRANSMITTER_CONTROL_H
37 
38 #include "stdint.h"
39 #include "flightstatus.h"
40 #include "manualcontrolcommand.h"
41 #include "manualcontrolsettings.h"
42 #include "stabilizationdesired.h"
43 #include "stabilizationsettings.h"
44 
45 /*
46  * These are assumptions we make in the flight code about the order of settings and their consistency between
47  * objects. Please keep this synchronized to the UAVObjects
48  */
49 #define assumptions1 ( \
50 ((int)MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_DISABLED == (int)STABILIZATIONDESIRED_STABILIZATIONMODE_DISABLED) && \
51 ((int)MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_MANUAL == (int)STABILIZATIONDESIRED_STABILIZATIONMODE_MANUAL) && \
52 ((int)MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_RATE == (int)STABILIZATIONDESIRED_STABILIZATIONMODE_RATE) && \
53 ((int)MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_AXISLOCK == (int)STABILIZATIONDESIRED_STABILIZATIONMODE_AXISLOCK) && \
54 ((int)MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_WEAKLEVELING == (int)STABILIZATIONDESIRED_STABILIZATIONMODE_WEAKLEVELING) && \
55 ((int)MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_ATTITUDE == (int)STABILIZATIONDESIRED_STABILIZATIONMODE_ATTITUDE) &&\
56 ((int)MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_LQG == (int)STABILIZATIONDESIRED_STABILIZATIONMODE_LQG) &&\
57 ((int)MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_ATTITUDELQG == (int)STABILIZATIONDESIRED_STABILIZATIONMODE_ATTITUDELQG) \
58 )
59 
60 #define assumptions3 ( \
61 ((int)MANUALCONTROLSETTINGS_STABILIZATION2SETTINGS_DISABLED == (int)STABILIZATIONDESIRED_STABILIZATIONMODE_DISABLED) && \
62 ((int)MANUALCONTROLSETTINGS_STABILIZATION2SETTINGS_MANUAL == (int)STABILIZATIONDESIRED_STABILIZATIONMODE_MANUAL) && \
63 ((int)MANUALCONTROLSETTINGS_STABILIZATION2SETTINGS_RATE == (int)STABILIZATIONDESIRED_STABILIZATIONMODE_RATE) && \
64 ((int)MANUALCONTROLSETTINGS_STABILIZATION2SETTINGS_AXISLOCK == (int)STABILIZATIONDESIRED_STABILIZATIONMODE_AXISLOCK) && \
65 ((int)MANUALCONTROLSETTINGS_STABILIZATION2SETTINGS_WEAKLEVELING == (int)STABILIZATIONDESIRED_STABILIZATIONMODE_WEAKLEVELING) && \
66 ((int)MANUALCONTROLSETTINGS_STABILIZATION2SETTINGS_ATTITUDE == (int)STABILIZATIONDESIRED_STABILIZATIONMODE_ATTITUDE) &&\
67 ((int)MANUALCONTROLSETTINGS_STABILIZATION2SETTINGS_LQG == (int)STABILIZATIONDESIRED_STABILIZATIONMODE_LQG) &&\
68 ((int)MANUALCONTROLSETTINGS_STABILIZATION2SETTINGS_ATTITUDELQG == (int)STABILIZATIONDESIRED_STABILIZATIONMODE_ATTITUDELQG) \
69 )
70 
71 #define assumptions5 ( \
72 ((int)MANUALCONTROLSETTINGS_STABILIZATION3SETTINGS_DISABLED == (int)STABILIZATIONDESIRED_STABILIZATIONMODE_DISABLED) && \
73 ((int)MANUALCONTROLSETTINGS_STABILIZATION3SETTINGS_MANUAL == (int)STABILIZATIONDESIRED_STABILIZATIONMODE_MANUAL) && \
74 ((int)MANUALCONTROLSETTINGS_STABILIZATION3SETTINGS_RATE == (int)STABILIZATIONDESIRED_STABILIZATIONMODE_RATE) && \
75 ((int)MANUALCONTROLSETTINGS_STABILIZATION3SETTINGS_AXISLOCK == (int)STABILIZATIONDESIRED_STABILIZATIONMODE_AXISLOCK) && \
76 ((int)MANUALCONTROLSETTINGS_STABILIZATION3SETTINGS_WEAKLEVELING == (int)STABILIZATIONDESIRED_STABILIZATIONMODE_WEAKLEVELING) && \
77 ((int)MANUALCONTROLSETTINGS_STABILIZATION3SETTINGS_ATTITUDE == (int)STABILIZATIONDESIRED_STABILIZATIONMODE_ATTITUDE) &&\
78 ((int)MANUALCONTROLSETTINGS_STABILIZATION3SETTINGS_LQG == (int)STABILIZATIONDESIRED_STABILIZATIONMODE_LQG) &&\
79 ((int)MANUALCONTROLSETTINGS_STABILIZATION3SETTINGS_ATTITUDELQG == (int)STABILIZATIONDESIRED_STABILIZATIONMODE_ATTITUDELQG) \
80 )
81 
82 #define assumptions_flightmode ( \
83 ( (int)MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_MANUAL == (int) FLIGHTSTATUS_FLIGHTMODE_MANUAL) && \
84 ( (int)MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_ACRO == (int) FLIGHTSTATUS_FLIGHTMODE_ACRO) && \
85 ( (int)MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_LEVELING == (int) FLIGHTSTATUS_FLIGHTMODE_LEVELING) && \
86 ( (int)MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_HORIZON == (int) FLIGHTSTATUS_FLIGHTMODE_HORIZON) && \
87 ( (int)MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_AXISLOCK == (int) FLIGHTSTATUS_FLIGHTMODE_AXISLOCK) && \
88 ( (int)MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_VIRTUALBAR == (int) FLIGHTSTATUS_FLIGHTMODE_VIRTUALBAR) && \
89 ( (int)MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_STABILIZED1 == (int) FLIGHTSTATUS_FLIGHTMODE_STABILIZED1) && \
90 ( (int)MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_STABILIZED2 == (int) FLIGHTSTATUS_FLIGHTMODE_STABILIZED2) && \
91 ( (int)MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_STABILIZED3 == (int) FLIGHTSTATUS_FLIGHTMODE_STABILIZED3) && \
92 ( (int)MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_POSITIONHOLD == (int) FLIGHTSTATUS_FLIGHTMODE_POSITIONHOLD) && \
93 ( (int)MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_RETURNTOHOME == (int) FLIGHTSTATUS_FLIGHTMODE_RETURNTOHOME) \
94 )
95 
96 #define assumptions_channelcount ( \
97 ( (int)MANUALCONTROLCOMMAND_CHANNEL_NUMELEM == (int)MANUALCONTROLSETTINGS_CHANNELGROUPS_NUMELEM ) && \
98 ( (int)MANUALCONTROLCOMMAND_CHANNEL_NUMELEM == (int)MANUALCONTROLSETTINGS_CHANNELNUMBER_NUMELEM ) && \
99 ( (int)MANUALCONTROLCOMMAND_CHANNEL_NUMELEM == (int)MANUALCONTROLSETTINGS_CHANNELMIN_NUMELEM ) && \
100 ( (int)MANUALCONTROLCOMMAND_CHANNEL_NUMELEM == (int)MANUALCONTROLSETTINGS_CHANNELMAX_NUMELEM ) && \
101 ( (int)MANUALCONTROLCOMMAND_CHANNEL_NUMELEM == (int)MANUALCONTROLSETTINGS_CHANNELNEUTRAL_NUMELEM ) )
102 
103 DONT_BUILD_IF(!(assumptions1), TransmitterControlAssumptions1);
104 DONT_BUILD_IF(!(assumptions3), TransmitterControlAssumptions3);
105 DONT_BUILD_IF(!(assumptions5), TransmitterControlAssumptions5);
106 DONT_BUILD_IF(!(assumptions_flightmode), TransmitterControlAssumptions_fm);
107 DONT_BUILD_IF(!(assumptions_channelcount), TransmitterControlAssumptions_cc);
108 
109 #define NEQ(a,b) (((int) (a)) != ((int) (b)))
110 
112  NEQ(STABILIZATIONDESIRED_STABILIZATIONMODE_ROLL, MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_ROLL) ||
113  NEQ(STABILIZATIONDESIRED_STABILIZATIONMODE_ROLL, STABILIZATIONSETTINGS_MANUALRATE_ROLL) ||
114  NEQ(STABILIZATIONDESIRED_STABILIZATIONMODE_ROLL, STABILIZATIONSETTINGS_RATEEXPO_ROLL) ||
115  NEQ(STABILIZATIONDESIRED_STABILIZATIONMODE_ROLL, STABILIZATIONSETTINGS_HORIZONEXPO_ROLL) ||
116  NEQ(STABILIZATIONDESIRED_STABILIZATIONMODE_ROLL, STABILIZATIONSETTINGS_DEADBANDWIDTH_ROLL) ||
117  NEQ(STABILIZATIONDESIRED_STABILIZATIONMODE_ROLL, STABILIZATIONSETTINGS_DEADBANDSLOPE_ROLL),
118  ROLLIndicesMismatch);
119 
121  NEQ(STABILIZATIONDESIRED_STABILIZATIONMODE_PITCH, MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_PITCH) ||
122  NEQ(STABILIZATIONDESIRED_STABILIZATIONMODE_PITCH, STABILIZATIONSETTINGS_MANUALRATE_PITCH) ||
123  NEQ(STABILIZATIONDESIRED_STABILIZATIONMODE_PITCH, STABILIZATIONSETTINGS_RATEEXPO_PITCH) ||
124  NEQ(STABILIZATIONDESIRED_STABILIZATIONMODE_PITCH, STABILIZATIONSETTINGS_HORIZONEXPO_PITCH) ||
125  NEQ(STABILIZATIONDESIRED_STABILIZATIONMODE_PITCH, STABILIZATIONSETTINGS_DEADBANDWIDTH_PITCH) ||
126  NEQ(STABILIZATIONDESIRED_STABILIZATIONMODE_PITCH, STABILIZATIONSETTINGS_DEADBANDSLOPE_PITCH),
127  PITCHIndicesMismatch);
128 
130  NEQ(STABILIZATIONDESIRED_STABILIZATIONMODE_YAW, MANUALCONTROLSETTINGS_STABILIZATION1SETTINGS_YAW) ||
131  NEQ(STABILIZATIONDESIRED_STABILIZATIONMODE_YAW, STABILIZATIONSETTINGS_MANUALRATE_YAW) ||
132  NEQ(STABILIZATIONDESIRED_STABILIZATIONMODE_YAW, STABILIZATIONSETTINGS_RATEEXPO_YAW) ||
133  NEQ(STABILIZATIONDESIRED_STABILIZATIONMODE_YAW, STABILIZATIONSETTINGS_HORIZONEXPO_YAW) ||
134  NEQ(STABILIZATIONDESIRED_STABILIZATIONMODE_YAW, STABILIZATIONSETTINGS_DEADBANDWIDTH_YAW) ||
135  NEQ(STABILIZATIONDESIRED_STABILIZATIONMODE_YAW, STABILIZATIONSETTINGS_DEADBANDSLOPE_YAW),
136  YAWIndicesMismatch);
137 
140 
143 
145 int32_t transmitter_control_select(bool reset_controller);
146 
149 
152 
153 #endif /* TRANSMITTER_CONTROL_H */
154 
#define assumptions3
#define assumptions_flightmode
int32_t transmitter_control_select(bool reset_controller)
Select and use transmitter control.
#define assumptions_channelcount
#define assumptions5
enum control_status transmitter_control_get_status()
Get any control events.
control_status
Definition: control.h:33
DONT_BUILD_IF(!(assumptions1), TransmitterControlAssumptions1)
#define NEQ(a, b)
int32_t transmitter_control_update()
Process inputs and arming.
#define assumptions1
int32_t transmitter_control_initialize()
Initialize the transmitter control mode.
uint8_t transmitter_control_get_flight_mode()
Query what the flight mode would be if this is selected.