HLCombine.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 HLCOMBINE_HPP_
00038 #define HLCOMBINE_HPP_
00039 #include <auv_msgs/BodyVelocityReq.h>
00040 
00041 #include <boost/array.hpp>
00042 
00043 #include <string>
00044 #include <set>
00045 
00046 struct ControllerInfo
00047 {
00048         std::string name;
00049         std::vector<std::string> requiredSubControllers;
00050         std::vector<int> requiredDOF;
00051 };
00052 
00053 
00054 
00055 struct HLCombine
00056 {
00057         HLCombine()
00058         {
00059                 //Empty the usage case
00060                 for (int i=0; i<nuVals.size(); ++i)      nuVals[i]="";
00061         }
00062 
00063         typedef std::set<std::string> ControllerCollection;
00064 
00065         void setControllers(const std::vector<ControllerInfo>& controllers)
00066         {
00067                 std::vector<std::string> disableControllers;
00068                 std::vector<std::string> enableControllers;
00069 
00070                 //enable all sub-controllers of the enabled controller
00071                 std::vector<ControllerInfo> subcon;
00072                 for (int j=0; j<controller.requiredSubControllers.size(); ++j)
00073                 {
00074                         //TEST IF REQUEIRED SUB-CONTROLLER IS REGISTERED
00075                         subcon.push_back(regControllers[controller.requredSubControllers[j]]);
00076                 }
00077 
00078                 setControllers(subcon);
00079 
00080                 //Enable basic controller requests
00081                 for (int i=0; i< controllers.size(); ++i)
00082                 {
00083                         ControllerInfo& controller = controllers[i];
00084                         for(int j=0; j<controller.requiredDOF.size(); ++j)
00085                         {
00086                                 int reqDOF = controller.requiredDOF[j];
00087                                 if (nuVals[reqDOF] != "")
00088                                 {
00089                                         disableControllers.push_back(nuVals[reqDOF]);
00090                                         //schedule all sub-controllers of the disable controller for disable
00091                                         disableControllers.insert(disableControllers.end(),
00092                                                         regControllers[nuVals[reqDOF]].requiredSubControllers.begin(),
00093                                                         regControllers[nuVals[reqDOF]].requiredSubControllers.end());
00094                                 }
00095                                 nuVals[reqDOF] = controller.name;
00096                         }
00097 
00098                         enableControllers.push_back(controller.name);
00099                 }
00100         }
00101 
00102         void step(const std::map<std::string, boost::array<double,6> >& results, boost::array<double,6>& nuRef)
00103         {
00104                 for (size_t i=0; i<6;++i)
00105                 {
00106                         nuRef[0] = results[nuVals[0]][0];
00107                 }
00108         }
00109 
00110         const std::map<std::string, ControllerInfo> regControllers;
00111         boost::array<std::string,6> nuVals;
00112 };
00113 
00114 #endif
00115 
00116 
00117 


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