HeadingControl_test.hpp
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2010, LABUST, UNIZG-FER
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 LABUST 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 *  Author: Dula Nad
00035 *  Created: 01.02.2013.
00036 *********************************************************************/
00037 #ifndef HEADINGCONTROL_TEST_HPP_
00038 #define HEADINGCONTROL_TEST_HPP_
00039 #include <labust/control/HLControl.hpp>
00040 #include <labust/control/PIDController.h>
00041 #include <labust/math/NumberManipulation.hpp>
00042 #include <std_msgs/Float32.h>
00043 
00044 struct HeadingControl
00045 {
00046         HeadingControl():Ts(0.1){};
00047 
00048         void init()
00049         {
00050                 ros::NodeHandle nh;
00051                 headingRef = nh.subscribe<std_msgs::Float32>("heading_ref", 1,
00052                                         &HeadingControl::onHeadingRef,this);
00053 
00054                 initialize_controller();
00055         }
00056 
00057         void onHeadingRef(const std_msgs::Float32::ConstPtr& ref)
00058         {
00059                 headingController.desired = ref->data;
00060         };
00061 
00062         void windup(const auv_msgs::BodyForceReq& tauAch)
00063         {
00064                 //Copy into controller
00065                 headingController.windup = tauAch.disable_axis.yaw;
00066         };
00067 
00068         void step(const auv_msgs::NavSts::ConstPtr& state, auv_msgs::BodyVelocityReqPtr nu)
00069         {
00070                 //if (!enable) return;
00071                 //this->safetyTest();
00072                 headingController.state = labust::math::wrapRad(state->orientation.yaw);
00073                 float errorWrap = labust::math::wrapRad(headingController.desired - headingController.state);
00074                 PIFFExtController_stepWrap(&headingController,Ts, errorWrap);
00075 
00076                 nu->header.stamp = ros::Time::now();
00077                 nu->goal.requester = "heading_controller";
00078                 nu->twist.angular.z = headingController.output;
00079         }
00080 
00081         void initialize_controller()
00082         {
00083                 ROS_INFO("Initializing heading controller...");
00084 
00085                 double w(1);
00086                 ros::NodeHandle nh;
00087                 nh.param("heading_control/heading_closed_loop_freq", w,w);
00088                 nh.param("heading_control/sampling",Ts,Ts);
00089 
00090                 enum {Kp=0, Ki, Kd, Kt};
00091                 PIDController_init(&headingController);
00092                 headingController.gains[Kp] = 2*w;
00093                 headingController.gains[Ki] = w*w;
00094                 headingController.autoTracking = 0;
00095 
00096                 ROS_INFO("Heading controller initialized.");
00097         }
00098 
00099 private:
00100         PIDController headingController;
00101         ros::Subscriber headingRef;
00102         double Ts;
00103 };
00104 
00105 #endif
00106 
00107 
00108 


labust_uvapp
Author(s): Dula Nad
autogenerated on Sun Mar 1 2015 12:12:22