MAV'RIC
remote.h
1 /*******************************************************************************
2  * Copyright (c) 2009-2014, MAV'RIC Development Team
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  ******************************************************************************/
31 
32 /*******************************************************************************
33  * \file remote.h
34  *
35  * \author MAV'RIC Team
36  * \author Julien Lecoeur
37  *
38  * \brief This file is the driver for the remote control
39  *
40  ******************************************************************************/
41 
42 
43 #ifndef REMOTE_H__
44 #define REMOTE_H__
45 
46 #ifdef __cplusplus
47  extern "C" {
48 #endif
49 
50 #include "satellite.h"
51 #include "stabilisation.h"
52 #include "mav_modes.h"
53 
54 #define REMOTE_CHANNEL_COUNT 8
55 
59 typedef enum
60 {
61  SIGNAL_GOOD = 100,
62  SIGNAL_BAD = 50,
63  SIGNAL_LOST = 0,
64 } signal_quality_t;
65 
69 typedef enum
70 {
71  NORMAL = 1,
72  INVERTED = -1,
73 } channel_inv_t;
74 
78 typedef enum
79 {
80  CHANNEL_THROTTLE = 0,
81  CHANNEL_ROLL = 1,
82  CHANNEL_PITCH = 2,
83  CHANNEL_YAW = 3,
84  CHANNEL_GEAR = 4,
85  CHANNEL_FLAPS = 5,
86  CHANNEL_AUX1 = 6,
87  CHANNEL_AUX2 = 7,
88 } remote_channel_t;
89 
93 typedef enum
94 {
95  REMOTE_TURNIGY = 0,
96  REMOTE_SPEKTRUM = 1,
97 } remote_type_t;
98 
102 typedef struct
103 {
104  remote_channel_t safety_channel;
106  remote_channel_t mode_switch_channel;
111  remote_channel_t custom_switch_channel;
113  remote_channel_t test_switch_channel;
115  remote_channel_t disable_remote_mode_channel;
117 
121 typedef struct
122 {
123  remote_channel_t safety_channel;
125  remote_channel_t mode_switch_channel;
130  remote_channel_t custom_switch_channel;
132  remote_channel_t test_switch_channel;
134  remote_channel_t disable_remote_mode_channel;
136 } remote_mode_t;
137 
141 typedef struct
142 {
143  remote_type_t type;
145 } remote_conf_t;
146 
150 typedef struct
151 {
153  float channels[REMOTE_CHANNEL_COUNT];
154  channel_inv_t channel_inv[REMOTE_CHANNEL_COUNT];
155  float trims[REMOTE_CHANNEL_COUNT];
156  float scale;
157  int16_t deadzone;
158  signal_quality_t signal_quality;
159  remote_type_t type;
161 } remote_t;
162 
171 bool remote_init(remote_t* remote, const remote_conf_t* config);
172 
178 void remote_update(remote_t* remote);
179 
180 
188 signal_quality_t remote_check(remote_t* remote);
189 
197 void remote_calibrate(remote_t* remote, remote_channel_t channel);
198 
206 float remote_get_throttle(const remote_t* remote);
207 
215 float remote_get_roll(const remote_t* remote);
216 
224 float remote_get_pitch(const remote_t* remote);
225 
233 float remote_get_yaw(const remote_t* remote);
234 
241 void remote_mode_init(remote_mode_t* remote_mode, const remote_mode_conf_t* config);
242 
248 void remote_mode_update(remote_t* remote);
249 
257 mav_mode_t remote_mode_get(const remote_t* remote);
258 
265 void remote_get_command_from_remote(remote_t* remote, control_command_t * controls);
266 
273 void remote_get_velocity_vector_from_remote(remote_t* remote, control_command_t* controls);
274 
275 
276 #ifdef __cplusplus
277  }
278 #endif
279 
280 #endif
remote_channel_t safety_channel
Channel to use as 2-way "safety" switch. When 100%: safety mode, When -100%: normal mode (defined by ...
Definition: remote.h:123
The configuration structure of the remote.
Definition: remote.h:141
remote_channel_t mode_switch_channel
Channel to use as 3-way mode switch. The 3 corresponding modes are used when the safety channel is at...
Definition: remote.h:125
mav_mode_t mode_switch_up
Mode when the mode switch is UP (ARMED and HIL bit flags are ignored)
Definition: remote.h:126
satellite_t sat
The pointer to the raw values of the remote received by the interrupt.
Definition: remote.h:152
remote_mode_conf_t mode_config
The configuration structure.
Definition: remote.h:144
The configuration structure of the remote.
Definition: remote.h:150
mav_mode_t current_desired_mode
Mav mode indicated by the remote.
Definition: remote.h:135
int16_t deadzone
The size of the deadzone.
Definition: remote.h:157
The configuration structure of the remote mode.
Definition: remote.h:102
remote_type_t type
The type of remote used.
Definition: remote.h:143
remote_mode_t mode
The remote mode structure.
Definition: remote.h:160
remote_channel_t test_switch_channel
Channel to use as 2-way test switch. If not in safety, the switch overrides the test bit flag: 0 when...
Definition: remote.h:132
signal_quality_t signal_quality
The quality of signal.
Definition: remote.h:158
remote_channel_t test_switch_channel
See remote_mode_t for documentation.
Definition: remote.h:113
bool use_disable_remote_mode_switch
See remote_mode_t for documentation.
Definition: remote.h:114
mav_mode_t safety_mode
See remote_mode_t for documentation.
Definition: remote.h:105
mav_mode_t mode_switch_up
See remote_mode_t for documentation.
Definition: remote.h:107
remote_channel_t safety_channel
See remote_mode_t for documentation.
Definition: remote.h:104
The control command typedef.
Definition: stabilisation.h:77
Structure containing the satellite receiver's data.
Definition: satellite.h:56
bool use_test_switch
See remote_mode_t for documentation.
Definition: remote.h:112
mav_mode_t mode_switch_middle
See remote_mode_t for documentation.
Definition: remote.h:108
float scale
The scale of the remote channels.
Definition: remote.h:156
mav_mode_t mode_switch_down
Mode when the mode switch is DOWN (ARMED and HIL bit flags are ignored)
Definition: remote.h:128
bool use_custom_switch
See remote_mode_t for documentation.
Definition: remote.h:110
mav_mode_t mode_switch_middle
Mode when the mode switch is MIDDLE (ARMED and HIL bit flags are ignored)
Definition: remote.h:127
The structure of the remote mode.
Definition: remote.h:121
mav_mode_t safety_mode
Mode when the safety channel is at 100% (ARMED and HIL bit flags are ignored)
Definition: remote.h:124
remote_channel_t disable_remote_mode_channel
See remote_mode_t for documentation.
Definition: remote.h:115
remote_type_t type
The type of remote.
Definition: remote.h:159
Definition: mav_modes.h:147
remote_channel_t disable_remote_mode_channel
Channel to use as 2-way switch. When 100%: follow mode indicated by the remote, when -100%: override ...
Definition: remote.h:134
bool use_test_switch
Indicates whether a switch to activate the test flag should be used.
Definition: remote.h:131
mav_mode_t mode_switch_down
See remote_mode_t for documentation.
Definition: remote.h:109
remote_channel_t custom_switch_channel
Channel to use as 2-way custom switch. If not in safety, the switch overrides the custom bit flag: 0 ...
Definition: remote.h:130
remote_channel_t custom_switch_channel
See remote_mode_t for documentation.
Definition: remote.h:111
bool use_disable_remote_mode_switch
Indicates whether a switch should be used to use/override the mode indicated by the remote...
Definition: remote.h:133
bool use_custom_switch
Indicates whether a switch to activate the custom flag should be used.
Definition: remote.h:129
remote_channel_t mode_switch_channel
See remote_mode_t for documentation.
Definition: remote.h:106