XYModel.cpp
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 *  Created on: Feb 25, 2013
00035 *  Author: Dula Nad
00036 *********************************************************************/
00037 #include <labust/navigation/XYModel.hpp>
00038 #include <vector>
00039 
00040 using namespace labust::navigation;
00041 
00042 XYModel::XYModel():
00043                 xdot(0),
00044                 ydot(0)
00045 {
00046         this->initModel();
00047 };
00048 
00049 XYModel::~XYModel(){};
00050 
00051 void XYModel::initModel()
00052 {
00053   //std::cout<<"Init model."<<std::endl;
00054   x = vector::Zero(stateNum);
00055   xdot = 0;
00056   ydot = 0;
00057   //Setup the transition matrix
00058   derivativeAW();
00059   //std::cout<<"R:"<<R<<"\n"<<V<<std::endl;
00060 }
00061 
00062 const XYModel::output_type& XYModel::update(vector& measurements, vector& newMeas)
00063 {
00064         std::vector<size_t> arrived;
00065         std::vector<double> dataVec;
00066 
00067         for (size_t i=0; i<newMeas.size(); ++i)
00068         {
00069                 if (newMeas(i))
00070                 {
00071                         arrived.push_back(i);
00072                         dataVec.push_back(measurements(i));
00073                         newMeas(i) = 0;
00074                 }
00075         }
00076 
00077         measurement.resize(arrived.size());
00078         H = matrix::Zero(arrived.size(),stateNum);
00079         R = matrix::Zero(arrived.size(),arrived.size());
00080         V = matrix::Zero(arrived.size(),arrived.size());
00081 
00082         for (size_t i=0; i<arrived.size();++i)
00083         {
00084                 measurement(i) = dataVec[i];
00085                 H(i,arrived[i]) = 1;
00086                 for (size_t j=0; j<arrived.size(); ++j)
00087                 {
00088                         R(i,j)=R0(arrived[i],arrived[j]);
00089                         V(i,j)=V0(arrived[i],arrived[j]);
00090                 }
00091         }
00092 
00093         //std::cout<<"Setup H:"<<H<<std::endl;
00094         //std::cout<<"Setup R:"<<R<<std::endl;
00095         //std::cout<<"Setup V:"<<V<<std::endl;
00096 
00097         return measurement;
00098 }
00099 
00100 //const XYModel::output_type& XYModel::yawUpdate(double yaw)
00101 //{
00102 //      derivativeHV(1);
00103 //      measurement(psiOnly_m) = yaw;
00104 //      return measurement;
00105 //}
00106 //
00107 //const XYModel::output_type& XYModel::fullUpdate(double x,
00108 //                double y,
00109 //                double yaw)
00110 //{
00111 //      derivativeHV(3);
00112 //      measurement(x_m) = x;
00113 //      measurement(y_m) = y;
00114 //      measurement(psi_m) = yaw;
00115 //
00116 //      return measurement;
00117 //}
00118 //
00119 //const XYModel::output_type& XYModel::positionUpdate(double x,
00120 //                double y)
00121 //{
00122 //      derivativeHV(2);
00123 //      measurement(x_m) = x;
00124 //      measurement(y_m) = y;
00125 //
00126 //      return measurement;
00127 //}
00128 
00129 void XYModel::calculateXYInovationVariance(const XYModel::matrix& P, double& xin,double &yin)
00130 {
00131         xin = sqrt(P(xp,xp)) + sqrt(R0(xp,xp));
00132         yin = sqrt(P(yp,yp)) + sqrt(R0(yp,yp));
00133 }
00134 
00135 void XYModel::step(const input_type& input)
00136 {
00137   x(u) += Ts*(-surge.Beta(x(u))/surge.alpha*x(u) + 1/surge.alpha * input(X));
00138   x(v) += Ts*(-sway.Beta(x(v))/sway.alpha*x(v) + 1/sway.alpha * input(Y));
00139   x(r) += Ts*(-yaw.Beta(x(r))/yaw.alpha*x(r) + 1/yaw.alpha * input(N) + 0*x(b2));
00140 
00141   xdot = x(u)*cos(x(psi)) - x(v)*sin(x(psi)) + x(xc);
00142   ydot = x(u)*sin(x(psi)) + x(v)*cos(x(psi)) + x(yc);
00143   x(xp) += Ts * xdot;
00144   x(yp) += Ts * ydot;
00145   x(psi) += Ts * (x(r) + x(b1));
00146 
00147   xk_1 = x;
00148 
00149   derivativeAW();
00150 };
00151 
00152 void XYModel::derivativeAW()
00153 {
00154         A = matrix::Identity(stateNum, stateNum);
00155 
00156         A(u,u) = 1-Ts*(surge.beta + 2*surge.betaa*fabs(x(u)))/surge.alpha;
00157         A(v,v) = 1-Ts*(sway.beta + 2*sway.betaa*fabs(x(v)))/sway.alpha;
00158         A(r,r) = 1-Ts*(yaw.beta + 2*yaw.betaa*fabs(x(r)))/yaw.alpha;
00159         A(r,b2) = 0*Ts;
00160 
00161         A(xp,u) = Ts*cos(x(psi));
00162         A(xp,v) = -Ts*sin(x(psi));
00163         A(xp,psi) = Ts*(-x(u)*sin(x(psi) - x(v)*cos(x(psi))));
00164         A(xp,xc) = Ts;
00165 
00166         A(yp,u) = Ts*sin(x(psi));
00167         A(yp,v) = Ts*cos(x(psi));
00168         A(yp,psi) = Ts*(x(u)*cos(x(psi)) - x(v)*sin(x(psi)));
00169         A(yp,yc) = Ts;
00170 
00171         A(psi,r) = Ts;
00172         A(psi,b1) = Ts;
00173 }
00174 
00175 //void XYModel::derivativeHV(int numMeas)
00176 //{
00177 //      H = mzeros(numMeas,stateNum);
00178 //
00179 //      if (numMeas == 1)
00180 //      {
00181 //              H(psiOnly_m,psi) = 1;
00182 //              R = V = mzeros(1,1);
00183 //              R(0,0) = R0(psi_m,psi_m);
00184 //              V(0,0) = V0(psi_m,psi_m);
00185 //      }
00186 //      else if (numMeas == 2)
00187 //      {
00188 //              H(x_m,xp) = H(y_m,yp) = 1;
00189 //              R = boost::numeric::ublas::subrange(R0, x_m,y_m, x_m,y_m);
00190 //              V = boost::numeric::ublas::subrange(V0, x_m,y_m, x_m,y_m);
00191 //      }
00192 //      else
00193 //      {
00194 //              H(x_m,xp) = H(y_m,yp) = H(psi_m,psi) = 1;
00195 //              R = R0;
00196 //              V = V0;
00197 //      }
00198 //
00199 //      measurement.resize(numMeas);
00200 //}
00201 
00202 void XYModel::estimate_y(output_type& y)
00203 {
00204   y=H*x;
00205 }
00206 


labust_navigation
Author(s): Gyula Nagy
autogenerated on Fri Feb 7 2014 11:36:19