RelativeTrackingModel.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 *  Modified by: Filip Mandic
00038 *********************************************************************/
00039 #include <labust/navigation/RelativeTrackingModel.hpp>
00040 #include <vector>
00041 #include <iostream>
00042 #include <ros/ros.h>
00043 
00044 using namespace labust::navigation;
00045 
00046 RelativeTrackingModel::RelativeTrackingModel():
00047                 dvlModel(0),
00048                 xdot(0),
00049                 ydot(0)
00050 {
00051         this->initModel();
00052 };
00053 
00054 RelativeTrackingModel::~RelativeTrackingModel(){};
00055 
00056 void RelativeTrackingModel::initModel()
00057 {
00058   //std::cout<<"Init model."<<std::endl;
00059   x = vector::Zero(stateNum);
00060   xdot = 0;
00061   ydot = 0;
00062   //Setup the transition matrix
00063   derivativeAW();
00064   R0 = R;
00065   V0 = V;
00066 
00067   //std::cout<<"R:"<<R<<"\n"<<V<<std::endl;
00068 }
00069 
00070 //void RelativeTrackingModel::calculateXYInovationVariance(const RelativeTrackingModel::matrix& P, double& xin,double &yin)
00071 //{
00072 //      xin = sqrt(P(xp,xp)) + sqrt(R0(xp,xp));
00073 //      yin = sqrt(P(yp,yp)) + sqrt(R0(yp,yp));
00074 //}
00075 
00076 //double RelativeTrackingModel::calculateAltInovationVariance(const RelativeTrackingModel::matrix& P)
00077 //{
00078 //      return 0; //sqrt(P(altitude,altitude)) + sqrt(R0(altitude,altitude));
00079 //}
00080 
00081 //void RelativeTrackingModel::calculateUVInovationVariance(const RelativeTrackingModel::matrix& P, double& uin,double &vin)
00082 //{
00083 //      uin = sqrt(P(u,u)) + sqrt(R0(u,u));// Greska??? napomena: ispravljeno
00084 //      vin = sqrt(P(v,v)) + sqrt(R0(v,v));
00085 //}
00086 
00087 void RelativeTrackingModel::step(const input_type& input){
00088 
00089         /*****************************************************************
00090         *** Relative target tracking
00091         *****************************************************************/
00092 
00093         /* States --- delta_x ,delta_y, delta_z, psi_t, u_t, w_t, r_t */
00094         /* Inputs ---   x_dot, y_dot, psi, X, Y, Z */
00095 
00096         x(delta_x) += Ts*(input(x_dot) - x(u_t)*cos(x(psi_t)));
00097         x(delta_y) += Ts*(input(y_dot) - x(u_t)*sin(x(psi_t)));
00098         x(delta_z) += Ts*x(w_t);
00099         x(psi_t) += Ts*x(r_t);
00100         x(u_t) += Ts*(-surge.Beta(x(u_t))/surge.alpha*x(u_t) + 1/surge.alpha * input(X));
00101         x(w_t) += Ts*(-heave.Beta(x(w_t))/heave.alpha*x(w_t) + 1/heave.alpha * (input(Z))); /* Buoyancy ignored */
00102         x(r_t) += Ts*(-yaw.Beta(x(r_t))/yaw.alpha*x(r_t) + 1/yaw.alpha * input(N));
00103 
00104         xk_1 = x;
00105 
00106         derivativeAW();
00107 };
00108 
00109 void RelativeTrackingModel::derivativeAW(){
00110 
00111         /*****************************************************************
00112         *** Relative target tracking
00113         *****************************************************************/
00114 
00115         /* States --- delta_x ,delta_y, delta_z, psi_t, u_t, w_t, r_t */
00116 
00117         A = matrix::Identity(stateNum, stateNum);
00118 
00119         A(delta_x, psi_t) = Ts*x(u_t)*sin(x(psi_t));
00120         A(delta_x, u_t) = -Ts*cos(x(psi_t));
00121 
00122         A(delta_y, psi_t) = -Ts*x(u_t)*cos(x(psi_t));
00123         A(delta_y, u_t) = -Ts*sin(x(psi_t));
00124 
00125         A(delta_z, w_t) = Ts;
00126 
00127         A(psi_t,r_t) = Ts;
00128 
00129         A(u_t, u_t) = 1-Ts*(surge.beta + 2*surge.betaa*fabs(x(u_t)))/surge.alpha;
00130 
00131         A(w_t,w_t) = 1-Ts*(heave.beta + 2*heave.betaa*fabs(x(w_t)))/heave.alpha;
00132 
00133         A(r_t,r_t) = 1-Ts*(yaw.beta + 2*yaw.betaa*fabs(x(r_t)))/yaw.alpha;
00134 
00135 }
00136 
00137 const RelativeTrackingModel::output_type& RelativeTrackingModel::update(vector& measurements, vector& newMeas)
00138 {
00139         std::vector<size_t> arrived;
00140         std::vector<double> dataVec;
00141 
00142         for (size_t i=0; i<newMeas.size(); ++i)
00143         {
00144 
00145                 if (newMeas(i))
00146                 {
00147                         arrived.push_back(i);
00148                         dataVec.push_back(measurements(i));
00149                         newMeas(i) = 0;
00150                 }
00151         }
00152 
00153 
00154         //ROS_ERROR("broj mjerenja: %d", arrived.size());
00155         //for( std::vector<size_t>::const_iterator it = arrived.begin(); it != arrived.end(); ++it)
00156         //      ROS_ERROR("%d", *it);
00157 
00158 
00159         //if (dvlModel != 0) derivativeH();
00160 
00161         derivativeH();
00162 
00163         measurement.resize(arrived.size());
00164         H = matrix::Zero(arrived.size(),stateNum);
00165         y = vector::Zero(arrived.size());
00166         R = matrix::Zero(arrived.size(),arrived.size());
00167         V = matrix::Zero(arrived.size(),arrived.size());
00168 
00169         for (size_t i=0; i<arrived.size();++i)
00170         {
00171                 measurement(i) = dataVec[i];
00172 
00173                 //if (dvlModel != 0)
00174                 //{
00175                         H.row(i)=Hnl.row(arrived[i]);
00176                         y(i) = ynl(arrived[i]);
00177                 //}
00178                 //else
00179                 //{
00180                 //      H(i,arrived[i]) = 1;
00181                 //      y(i) = x(arrived[i]);
00182                 //}
00183 
00184                 for (size_t j=0; j<arrived.size(); ++j)
00185                 {
00186                         R(i,j)=R0(arrived[i],arrived[j]);
00187                         V(i,j)=V0(arrived[i],arrived[j]);
00188                 }
00189         }
00190 
00191         //std::cout<<"Setup H:"<<H<<std::endl;
00192         //std::cout<<"Setup R:"<<R<<std::endl;
00193         //std::cout<<"Setup V:"<<V<<std::endl;
00194 
00195         return measurement;
00196 }
00197 
00198 void RelativeTrackingModel::estimate_y(output_type& y){
00199 
00200   y=this->y;
00201 }
00202 
00203 void RelativeTrackingModel::derivativeH(){
00204 
00205         //Hnl = matrix::Zero(measSize,stateNum);
00206         //ynl = vector::Zero(measSize);
00207 
00208         Hnl=matrix::Identity(stateNum,stateNum);
00209         ynl = Hnl*x;
00210 
00211         /* Measurement vector --- d, theta, depth, psi_tm, delta_xm, delat_ym, delta_zm*/
00212 
00213         ynl(d) = sqrt(pow(x(delta_x),2)+pow(x(delta_y),2)+pow(x(delta_z),2));
00214         ynl(theta) = atan2(x(delta_y),x(delta_x));
00215         ynl(depth) = x(delta_z);
00216         ynl(psi_tm) = x(psi_t);
00217         ynl(delta_xm) = x(delta_x);
00218         ynl(delta_ym) = x(delta_y);
00219         ynl(delta_zm) = x(delta_z);
00220 
00221         Hnl(d, delta_x)  = (x(delta_x))/sqrt(pow(x(delta_x),2)+pow(x(delta_y),2)+pow(x(delta_z),2));
00222         Hnl(d, delta_y)  = (x(delta_y))/sqrt(pow(x(delta_x),2)+pow(x(delta_y),2)+pow(x(delta_z),2));
00223         Hnl(d, delta_z)  = (x(delta_z))/sqrt(pow(x(delta_x),2)+pow(x(delta_y),2)+pow(x(delta_z),2));
00224 
00225         Hnl(theta, delta_x) = -x(delta_y)/(pow(x(delta_x),2)*(pow(x(delta_y)/x(delta_x),2) + 1));
00226         Hnl(theta, delta_y) = 1/(x(delta_x)*(pow(x(delta_y)/x(delta_x),2) + 1));
00227 
00228         Hnl(depth, delta_z) = 1;
00229 
00230         Hnl(psi_tm, psi_t) = 1;
00231 
00232         Hnl(delta_xm, delta_x) = 1;
00233 
00234         Hnl(delta_ym, delta_y) = 1;
00235 
00236         Hnl(delta_zm, delta_z) = 1;
00237 }
00238 


labust_navigation
Author(s): Gyula Nagy
autogenerated on Fri Aug 28 2015 11:23:33