00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
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
00059 x = vector::Zero(stateNum);
00060 xdot = 0;
00061 ydot = 0;
00062
00063 derivativeAW();
00064 R0 = R;
00065 V0 = V;
00066
00067
00068 }
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 void RelativeTrackingModel::step(const input_type& input){
00088
00089
00090
00091
00092
00093
00094
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)));
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
00113
00114
00115
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
00155
00156
00157
00158
00159
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
00174
00175 H.row(i)=Hnl.row(arrived[i]);
00176 y(i) = ynl(arrived[i]);
00177
00178
00179
00180
00181
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
00192
00193
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
00206
00207
00208 Hnl=matrix::Identity(stateNum,stateNum);
00209 ynl = Hnl*x;
00210
00211
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