MAV'RIC
/home/travis/build/lis-epfl/MAVRIC_Library/manual_control/remote.hpp
00001 /*******************************************************************************
00002  * Copyright (c) 2009-2016, MAV'RIC Development Team
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright notice,
00009  * this list of conditions and the following disclaimer.
00010  *
00011  * 2. Redistributions in binary form must reproduce the above copyright notice,
00012  * this list of conditions and the following disclaimer in the documentation
00013  * and/or other materials provided with the distribution.
00014  *
00015  * 3. Neither the name of the copyright holder nor the names of its contributors
00016  * may be used to endorse or promote products derived from this software without
00017  * specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00020  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00022  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00023  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00024  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00025  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00026  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00027  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00028  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00029  * POSSIBILITY OF SUCH DAMAGE.
00030  ******************************************************************************/
00031 
00032 /*******************************************************************************
00033  * \file remote.hpp
00034  *
00035  * \author MAV'RIC Team
00036  * \author Julien Lecoeur
00037  *
00038  * \brief This file is the driver for the remote control
00039  *
00040  ******************************************************************************/
00041 
00042 
00043 #ifndef REMOTE_HPP__
00044 #define REMOTE_HPP__
00045 
00046 #include "status/mav_modes.hpp"
00047 #include "drivers/satellite.hpp"
00048 #include "control/controller.hpp"
00049 #include "control/control_command.hpp"
00050 
00051 
00052 #define REMOTE_CHANNEL_COUNT 14
00053 
00054 
00058 typedef enum
00059 {
00060     SIGNAL_GOOD = 100,
00061     SIGNAL_BAD  = 50,
00062     SIGNAL_LOST = 0,
00063 } signal_quality_t;
00064 
00065 
00069 typedef enum
00070 {
00071     NORMAL      = 1,
00072     INVERTED    = -1,
00073 } channel_inv_t;
00074 
00075 
00079 typedef enum
00080 {
00081     CHANNEL_THROTTLE = 0,
00082     CHANNEL_ROLL     = 1,
00083     CHANNEL_PITCH    = 2,
00084     CHANNEL_YAW      = 3,
00085     CHANNEL_GEAR     = 4,
00086     CHANNEL_FLAPS    = 5,
00087     CHANNEL_AUX1     = 6,
00088     CHANNEL_AUX2     = 7,
00089     CHANNEL_AUX3     = 8,
00090     CHANNEL_AUX4     = 9,
00091     CHANNEL_AUX5     = 10,
00092     CHANNEL_AUX6     = 11,
00093     CHANNEL_AUX7     = 12,
00094     CHANNEL_AUX8     = 13
00095 } remote_channel_t;
00096 
00097 
00101 typedef enum
00102 {
00103     REMOTE_TURNIGY  = 0,
00104     REMOTE_SPEKTRUM = 1,
00105 } remote_type_t;
00106 
00107 
00111 typedef struct
00112 {
00113     remote_channel_t    safety_channel;                     
00114     Mav_mode            safety_mode;                        
00115     remote_channel_t    mode_switch_channel;                
00116     Mav_mode            mode_switch_up;                     
00117     Mav_mode            mode_switch_middle;                 
00118     Mav_mode            mode_switch_down;                   
00119     bool                use_custom_switch;                  
00120     remote_channel_t    custom_switch_channel;              
00121     bool                use_test_switch;                    
00122     remote_channel_t    test_switch_channel;                
00123     bool                use_disable_remote_mode_switch;     
00124     remote_channel_t    disable_remote_mode_channel;        
00125 } remote_mode_conf_t;
00126 
00127 
00131 typedef struct
00132 {
00133     remote_channel_t    safety_channel;                     
00134     Mav_mode            safety_mode;                        
00135     remote_channel_t    mode_switch_channel;                
00136     Mav_mode            mode_switch_up;                     
00137     Mav_mode            mode_switch_middle;                 
00138     Mav_mode            mode_switch_down;                   
00139     bool                use_custom_switch;                  
00140     remote_channel_t    custom_switch_channel;              
00141     bool                use_test_switch;                    
00142     remote_channel_t    test_switch_channel;                
00143     bool                use_disable_remote_mode_switch;     
00144     remote_channel_t    disable_remote_mode_channel;        
00145     Mav_mode            current_desired_mode;               
00146     arm_action_t            arm_action;
00147 } remote_mode_t;
00148 
00149 
00153 typedef struct
00154 {
00155     remote_type_t type;                                     
00156     remote_mode_conf_t mode_config;                         
00157 } remote_conf_t;
00158 
00159 
00163 typedef struct
00164 {
00165     float channels[REMOTE_CHANNEL_COUNT];                   
00166     channel_inv_t channel_inv[REMOTE_CHANNEL_COUNT];        
00167     float trims[REMOTE_CHANNEL_COUNT];                      
00168     float scale;                                            
00169     int16_t deadzone;                                       
00170     signal_quality_t signal_quality;                        
00171     remote_type_t type;                                     
00172     remote_mode_t mode;                                     
00173     uint32_t last_satellite_update;                         
00174     Satellite* sat;                                         
00175 } remote_t;
00176 
00177 
00187 bool remote_init(remote_t* remote, Satellite* sat, const remote_conf_t config);
00188 
00189 
00190 
00196 bool remote_update(remote_t* remote);
00197 
00198 
00206 signal_quality_t remote_check(remote_t* remote);
00207 
00208 
00216 void remote_calibrate(remote_t* remote, remote_channel_t channel);
00217 
00218 
00227 float remote_get_channel(const remote_t* remote, remote_channel_t ch);
00228 
00229 
00237 float remote_get_throttle(const remote_t* remote);
00238 
00239 
00247 float remote_get_roll(const remote_t* remote);
00248 
00249 
00257 float remote_get_pitch(const remote_t* remote);
00258 
00259 
00267 float remote_get_yaw(const remote_t* remote);
00268 
00269 
00276 void remote_mode_init(remote_mode_t* remote_mode, const remote_mode_conf_t config);
00277 
00278 
00279 
00285 void remote_mode_update(remote_t* remote);
00286 
00287 
00295 Mav_mode remote_mode_get(remote_t* remote, Mav_mode mode_current);
00296 
00297 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines