MAV'RIC
/home/travis/build/lis-epfl/MAVRIC_Library/flight_controller/flight_controller_copter.hxx
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 flight_controller_copter.hxx
00034  *
00035  * \author MAV'RIC Team
00036  * \author Julien Lecoeur
00037  *
00038  * \brief   Full flight controller for copter
00039  *
00040  ******************************************************************************/
00041 
00042  #ifndef FLIGHT_CONTROLLER_COPTER_HXX_
00043  #define FLIGHT_CONTROLLER_COPTER_HXX_
00044 
00045 template<uint32_t N_ROTORS>
00046 Flight_controller_copter<N_ROTORS>::Flight_controller_copter(const INS& ins, const AHRS& ahrs, typename Servos_mix_matrix<N_ROTORS>::args_t mix_args, conf_t config):
00047     Flight_controller_stack(pos_ctrl_, vel_ctrl_, att_ctrl_, rate_ctrl_, mix_ctrl_),
00048     pos_ctrl_({ahrs, ins}, config.pos_config),
00049     vel_ctrl_({{ahrs, ins, command_.velocity, command_.attitude, command_.thrust}}, config.vel_config),
00050     att_ctrl_({ahrs, command_.attitude, command_.rate}, config.att_config),
00051     rate_ctrl_({ahrs, command_.rate, command_.torque}, config.rate_config),
00052     mix_ctrl_(mix_args, config.mix_config),
00053     ahrs_(ahrs)
00054 {};
00055 
00056 
00057 template<uint32_t N_ROTORS>
00058 bool Flight_controller_copter<N_ROTORS>::set_manual_rate_command(const Manual_control& manual_control)
00059 {
00060     bool ret = true;
00061     rate_command_t rate_command;
00062     thrust_command_t thrust_command;
00063     manual_control.get_rate_command(rate_command);
00064     manual_control.get_thrust_command_copter(thrust_command);
00065     ret &= set_command(rate_command);
00066     ret &= set_command(thrust_command);
00067     return ret;
00068 };
00069 
00070 
00071 template<uint32_t N_ROTORS>
00072 bool Flight_controller_copter<N_ROTORS>::set_manual_attitude_command(const Manual_control& manual_control)
00073 {
00074     bool ret = true;
00075     attitude_command_t att_command;
00076     thrust_command_t thrust_command;
00077     manual_control.get_attitude_command(att_command, ahrs_.attitude());
00078     manual_control.get_thrust_command_copter(thrust_command);
00079     ret &= set_command(att_command);
00080     ret &= set_command(thrust_command);
00081     return ret;
00082 };
00083 
00084 
00085 template<uint32_t N_ROTORS>
00086 bool Flight_controller_copter<N_ROTORS>::set_manual_velocity_command(const Manual_control& manual_control)
00087 {
00088     bool ret = true;
00089     velocity_command_t new_vel_command;
00090     manual_control.get_velocity_command_copter(new_vel_command, ahrs_.attitude(), command_.velocity);
00091     ret &= set_command(new_vel_command);
00092     return ret;
00093 };
00094 
00095 #endif  // FLIGHT_CONTROLLER_COPTER_HXX_
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines