MAV'RIC
/home/travis/build/lis-epfl/MAVRIC_Library/manual_control/manual_control.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 manual_control.hpp
00034  *
00035  * \author MAV'RIC Team
00036  *
00037  * \brief This module takes care of taking the correct input for the control
00038  * (i.e. the remote or the joystick)
00039  *
00040  ******************************************************************************/
00041 
00042 
00043 #ifndef MANUAL_CONTROL_HPP_
00044 #define MANUAL_CONTROL_HPP_
00045 
00046 #include "manual_control/remote.hpp"
00047 #include "manual_control/joystick.hpp"
00048 #include "status/state.hpp"
00049 
00050 
00051 /* forward declaration for friend function */
00052 class Onboard_parameters;
00053 
00057 class Manual_control
00058 {
00059 public:
00063     enum mode_source_t : int32_t
00064     {
00065         MODE_SOURCE_REMOTE      = 0,
00066         MODE_SOURCE_GND_STATION = 1,
00067         MODE_SOURCE_JOYSTICK    = 2,
00068     };
00069 
00070 
00074     enum control_source_t : int32_t
00075     {
00076         CONTROL_SOURCE_REMOTE       = 0,
00077         CONTROL_SOURCE_NONE         = 1,
00078         CONTROL_SOURCE_JOYSTICK     = 2,
00079     };
00080 
00084     struct conf_t
00085     {
00086         Joystick::conf_t    joystick_config;    
00087         mode_source_t       mode_source;        
00088         control_source_t    control_source;     
00089     };
00090 
00091 
00098     Manual_control(Satellite* sat, conf_t config, remote_conf_t remote_config);
00099 
00100 
00106     float throttle() const;
00107 
00108 
00114     float roll() const;
00115 
00116 
00122     float pitch() const;
00123 
00124 
00130     float yaw() const;
00131 
00132 
00141     void get_torque_command(torque_command_t& command,
00142                             float scale_roll = 1.0f,
00143                             float scale_pitch = 1.0f,
00144                             float scale_yaw = 1.0f) const;
00145 
00146 
00155     void get_rate_command(rate_command_t& command,
00156                           float scale_roll = 1.0f,
00157                           float scale_pitch = 1.0f,
00158                           float scale_yaw = 1.0f) const;
00159 
00160 
00167     void get_thrust_command_copter(thrust_command_t& command, float scale = 1.0f) const;
00168 
00169 
00176     void get_thrust_command_wing(thrust_command_t& command, float scale = 1.0f) const;
00177 
00178 
00187     void get_attitude_command_absolute_yaw( attitude_command_t& command,
00188                                             float scale_roll = 1.0f,
00189                                             float scale_pitch = 1.0f,
00190                                             float scale_yaw = 1.0f) const;
00191 
00192 
00205     void get_attitude_command(  attitude_command_t& command,
00206                                 const quat_t& current_attitude,
00207                                 float scale_roll = 1.0f,
00208                                 float scale_pitch = 1.0f,
00209                                 float scale_yaw = 0.5f) const;
00210 
00211 
00222     void get_attitude_command_vtol( attitude_command_t& command,
00223                                     const quat_t& current_attitude,
00224                                     float reference_pitch,
00225                                     float scale_roll = 1.0f,
00226                                     float scale_pitch = 1.0f,
00227                                     float scale_yaw = 0.25f) const;
00228 
00229 
00240     void get_velocity_command_copter(velocity_command_t& command,
00241                                     const quat_t& current_attitude,
00242                                     const velocity_command_t& current_velocity_command,
00243                                     float scale_x = 10.0f,
00244                                     float scale_y = 10.0f,
00245                                     float scale_z = 1.5f,
00246                                     float scale_heading = 0.25f) const;
00247 
00248 
00256     Mav_mode get_mode_from_source(Mav_mode mode_current);
00257 
00258 
00267     void set_mode_of_source(Mav_mode mode_current);
00268 
00274     signal_quality_t get_signal_strength();
00275 
00281     inline void set_mode_source(mode_source_t mode_source) {mode_source_ = mode_source;};
00282 
00288     inline mode_source_t mode_source() const {return mode_source_;};
00289 
00295     inline void set_control_source(control_source_t control_source) {control_source_ = control_source;};
00296 
00302     inline control_source_t control_source() const {return control_source_;};
00303 
00304 
00305     static inline conf_t default_config();
00306 
00307 
00308     remote_t                remote;             
00309     Joystick                joystick;           
00310     mode_source_t           mode_source_;        
00311     control_source_t        control_source_;     
00312 };
00313 
00314 Manual_control::conf_t Manual_control::default_config()
00315 {
00316     conf_t conf = {};
00317 
00318     conf.joystick_config = Joystick::default_config();
00319     conf.mode_source = MODE_SOURCE_REMOTE;
00320     conf.control_source = CONTROL_SOURCE_REMOTE;
00321 
00322     return conf;
00323 };
00324 
00325 
00326 
00327 
00328 
00329 #endif /* MANUAL_CONTROL_HPP_ */
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines