attitude_controller.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2010, UC Regents
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of the University of California nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *********************************************************************/
00034 #include "flyer_controller/attitude_controller.h"
00035 namespace flyer_controller
00036 {
00037 
00038 AttitudeController::AttitudeController() :
00039   yaw_cmd(0), max_pitch_cmd(10), max_roll_cmd(10), external_command_frame(false), external_frame_heading(0)
00040 {
00041 }
00042 
00043 void AttitudeController::outputControl(const nav_msgs::OdometryConstPtr& latest_state,
00044                                        const starmac_msgs::OperatorCommandsConstPtr& latest_opercmd,
00045                                        control_mode_outputPtr& control_out)
00046 
00047 {
00048   ros::Time now_time = ros::Time::now();
00049   double dt = (now_time - last_time).toSec();
00050 
00051   double roll_cmd, pitch_cmd, alt_cmd;
00052   double roll_cmd_rot, pitch_cmd_rot;
00053   double relative_angle, cos_ang, sin_ang;
00054 
00055   roll_cmd = latest_opercmd->roll_cmd * max_roll_cmd;
00056   pitch_cmd = latest_opercmd->pitch_cmd * max_pitch_cmd;
00057 
00058   double yaw_rate_cmd = 0; //std::numeric_limits<double>::quiet_NaN();
00059   if (not direct_yaw_rate_control)
00060   {
00061     yaw_cmd = yaw_cmd + latest_opercmd->yaw_cmd * max_yaw_rate_cmd * dt;
00062     yaw_rate_cmd = 0; //std::numeric_limits<double>::quiet_NaN();
00063   }
00064   else
00065   {
00066     //yaw_cmd = 0; std::numeric_limits<double>::quiet_NaN();
00067     //yaw_cmd = yaw;
00068     yaw_rate_cmd = latest_opercmd->yaw_cmd * max_yaw_rate_cmd;
00069   }
00070 
00071   alt_cmd = min_alt_cmd + (max_alt_cmd - min_alt_cmd) * latest_opercmd->alt_cmd;
00072 
00073   if (external_command_frame)
00074   {
00075     double current_yaw, current_pitch, current_roll;
00076     odom_msg_to_ypr(latest_state, current_yaw, current_pitch, current_roll);
00077     relative_angle = current_yaw - angles::from_degrees(external_frame_heading);
00078     cos_ang = cos(relative_angle);
00079     sin_ang = sin(relative_angle);
00080     roll_cmd_rot = cos_ang * roll_cmd + sin_ang * pitch_cmd;
00081     pitch_cmd_rot = -sin_ang * roll_cmd + cos_ang * pitch_cmd;
00082   }
00083   else
00084   {
00085     roll_cmd_rot = roll_cmd;
00086     pitch_cmd_rot = pitch_cmd;
00087   }
00088 
00089   control_out->roll_cmd = roll_cmd_rot;
00090   control_out->pitch_cmd = pitch_cmd_rot;
00091   control_out->direct_thrust_commands = false;
00092   control_out->alt_cmd = alt_cmd;
00093   control_out->thrust_cmd = 0;
00094   control_out->direct_yaw_rate_commands = direct_yaw_rate_control;
00095   control_out->yaw_cmd = yaw_cmd;
00096   control_out->yaw_rate_cmd = yaw_rate_cmd;
00097   control_out->motors_on = latest_opercmd->motors_on;
00098 
00099   last_time = now_time;
00100 }
00101 
00102 void AttitudeController::useCurrentYaw(const nav_msgs::OdometryConstPtr& latest_state)
00103 {
00104   double current_yaw, current_pitch, current_roll;
00105   odom_msg_to_ypr(latest_state, current_yaw, current_pitch, current_roll);
00106   setYawCmd(to_degrees(current_yaw));
00107 
00108 }
00109 } // namespace


flyer_controller
Author(s): Patrick Bouffard
autogenerated on Sun Jan 5 2014 11:37:53