motionModel.cpp
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
32 #include <mtt/motionModel.h>
33 
35 {
36  _x = Vector5d::Zero();
37  _xp = Vector5d::Zero();
38  _z = Vector3d::Zero();
39  _P = Matrix5d::Zero();
40 }
41 
43 {
44  //Pre existing estimator
46 }
47 
49 {
50  //New estimator
51 
52  Vector5d x_init;
53 
54  x_init(0)=z(0);//x
55  x_init(1)=z(1);//y
56  x_init(2)=0;//v
57  x_init(3)=z(2);//t
58  x_init(4)=0;//f
59 
60  _x=x_init;
61  _xp=_x;
62  _z=z;
63 
64  _estimator.InitFilter(x_init);
65 
66  kMatrix P = _estimator.calculateP();
67  //Convert from ekfilter to eigen format
68  _P(0,0)=P(0,0);
69  _P(0,1)=P(0,1);
70  _P(0,2)=P(0,2);
71  _P(0,3)=P(0,3);
72  _P(0,4)=P(0,4);
73 
74  _P(1,0)=P(1,0);
75  _P(1,1)=P(1,1);
76  _P(1,2)=P(1,2);
77  _P(1,3)=P(1,3);
78  _P(1,4)=P(1,4);
79 
80  _P(2,0)=P(2,0);
81  _P(2,1)=P(2,1);
82  _P(2,2)=P(2,2);
83  _P(2,3)=P(2,3);
84  _P(2,4)=P(2,4);
85 
86  _P(3,0)=P(3,0);
87  _P(3,1)=P(3,1);
88  _P(3,2)=P(3,2);
89  _P(3,3)=P(3,3);
90  _P(3,4)=P(3,4);
91 
92  _P(4,0)=P(4,0);
93  _P(4,1)=P(4,1);
94  _P(4,2)=P(4,2);
95  _P(4,3)=P(4,3);
96  _P(4,4)=P(4,4);
97 }
98 
100 {
101  kVector u(0);
102 
103  _estimator.z_measured=z;//Copy to estimator
104  _z=z;
105 
107 
108  //Convert from eigen format to ekfilter
109  kVector z_(3);
110  z_(0)=z(0);
111  z_(1)=z(1);
112  z_(2)=z(2);
113 
114  //Makes one prediction-correction step
115  _estimator.step(u,z_);
116 
117 // cout<<"Xa: "<<_estimator.getX()<<endl;
118 // cout<<"Pa: "<<_estimator.calculateP()<<endl;
119 
120 // cout<<"Z: "<<z<<endl;
121 
122  //Returns the corrected state (a posteriori state estimate)
123  kVector x_(5);
124  x_ = _estimator.getX();
125 
126  //Convert from ekfilter to eigen format
127  _x(0)=x_(0);
128  _x(1)=x_(1);
129  _x(2)=x_(2);
130  _x(3)=x_(3);
131  _x(4)=x_(4);
132 
133 // cout<<"_X: "<<_x<<endl;
134 
135  //Returns the a posteriori error covariance estimate matrix
136  kMatrix P=_estimator.calculateP();
137 
138  //Convert from ekfilter to eigen format
139  _P(0,0)=P(0,0);
140  _P(0,1)=P(0,1);
141  _P(0,2)=P(0,2);
142  _P(0,3)=P(0,3);
143  _P(0,4)=P(0,4);
144 
145  _P(1,0)=P(1,0);
146  _P(1,1)=P(1,1);
147  _P(1,2)=P(1,2);
148  _P(1,3)=P(1,3);
149  _P(1,4)=P(1,4);
150 
151  _P(2,0)=P(2,0);
152  _P(2,1)=P(2,1);
153  _P(2,2)=P(2,2);
154  _P(2,3)=P(2,3);
155  _P(2,4)=P(2,4);
156 
157  _P(3,0)=P(3,0);
158  _P(3,1)=P(3,1);
159  _P(3,2)=P(3,2);
160  _P(3,3)=P(3,3);
161  _P(3,4)=P(3,4);
162 
163  _P(4,0)=P(4,0);
164  _P(4,1)=P(4,1);
165  _P(4,2)=P(4,2);
166  _P(4,3)=P(4,3);
167  _P(4,4)=P(4,4);
168 
169 // cout<<"P:"<<_P<<endl;
170 
171  //Returns the predicted state vector (a priori state estimate)
172  kVector xp=_estimator.predict(u);
173 
174  //Convert from ekfilter to eigen format
175  _xp(0)=xp(0);
176  _xp(1)=xp(1);
177  _xp(2)=xp(2);
178  _xp(3)=xp(3);
179  _xp(4)=xp(4);
180 
181 // cout<<"h123"<<endl;
182 // cout<<"xP:"<<_xp<<endl;
183 // assert(is_finite(_xp));
184 // assert(is_finite(_P));
185 
186  _estimator.x_predicted=_xp;//Copy to estimator
187 }
EKFilter< double, 0, false, false, false >::Matrix kMatrix
EKfilter matrix type.
Definition: mht_types.h:86
void InitFilter(Vector5d &x_init)
Init filter.
EKFilter< double, 0, false, false, false >::Vector kVector
EKfilter vector type.
Definition: mht_types.h:79
Vector3d _z
Measurement vector.
Definition: motionModel.h:54
Eigen::Matrix< double, 3, 1 > Vector3d
void initEstimator(Vector5d &x, Matrix5d &P)
Definition: motionModel.cpp:42
Vector5d _x
Estimated state.
Definition: motionModel.h:50
Motion model class declaration.
Vector5d _xp
Predicted x.
Definition: motionModel.h:52
nonholonomicEKFilter _estimator
Local estimator for process, Kalman filter with a constant velocity.
Definition: motionModel.h:59
Matrix5d _P
Posteriori error covariance.
Definition: motionModel.h:56
Eigen::Matrix< double, 5, 5 > Matrix5d
Eigen::Matrix< double, 5, 1 > Vector5d
void stepEstimator(Vector3d z)
Definition: motionModel.cpp:99


mtt
Author(s): Jorge Almeida
autogenerated on Mon Mar 2 2015 01:32:18