Robot's source code

Dependencies:   mbed

Committer:
Near32
Date:
Thu Mar 26 18:04:23 2015 +0000
Revision:
47:4909e97570f6
Parent:
44:d5f95af61243
Child:
50:16c033eea17d
logger baudrate + usb comm; pid motors; state : phi r and l; asserv vd wd pid phi r and l

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Near32 36:54f86bc6fd80 1 /*KalmanFilter*/
Near32 36:54f86bc6fd80 2 #include "EKF.h"
Near32 36:54f86bc6fd80 3 #include "Odometry.h"
Near32 43:87bdce65341f 4 /*
Near32 36:54f86bc6fd80 5 template<typename T>
Near32 36:54f86bc6fd80 6 Mat<T> motion_bicycle3( Mat<T> state, Mat<T> command, T dt = (T)0.5);
Near32 36:54f86bc6fd80 7 template<typename T>
Near32 36:54f86bc6fd80 8 Mat<T> sensor_bicycle3( Mat<T> state, Mat<T> command, Mat<T> d_state, T dt = 0.5 );
Near32 36:54f86bc6fd80 9 template<typename T>
Near32 36:54f86bc6fd80 10 Mat<T> jmotion_bicycle3( Mat<T> state, Mat<T> command, T dt = 0.5);
Near32 36:54f86bc6fd80 11 template<typename T>
Near32 36:54f86bc6fd80 12 Mat<T> jmotion_bicycle3_command(Mat<T> state, Mat<T> command, T dt = 0.5);
Near32 36:54f86bc6fd80 13 template<typename T>
Near32 36:54f86bc6fd80 14 Mat<T> jsensor_bicycle3( Mat<T> state, Mat<T> command, Mat<T> d_state, T dt = 0.5);
Near32 36:54f86bc6fd80 15 template<typename T>
Near32 36:54f86bc6fd80 16 bool setPWM(PwmOut *servo,T p);
Near32 43:87bdce65341f 17 */
Near32 36:54f86bc6fd80 18
Near32 36:54f86bc6fd80 19 template<typename T>
Near32 36:54f86bc6fd80 20 bool setPWM(PwmOut *servo,T p)
Near32 36:54f86bc6fd80 21 {
Near32 36:54f86bc6fd80 22 if(p <= (T)1.0 && p >= (T)0.0)
Near32 36:54f86bc6fd80 23 {
Near32 36:54f86bc6fd80 24 servo->write((float)p);
Near32 36:54f86bc6fd80 25 return true;
Near32 36:54f86bc6fd80 26 }
Near32 36:54f86bc6fd80 27
Near32 36:54f86bc6fd80 28 return false;
Near32 36:54f86bc6fd80 29 }
Near32 36:54f86bc6fd80 30
Near32 36:54f86bc6fd80 31 template<typename T>
Near32 36:54f86bc6fd80 32 Mat<T> motion_bicycle3( Mat<T> state, Mat<T> command, T dt)
Near32 43:87bdce65341f 33 {
Near32 36:54f86bc6fd80 34 Mat<T> bicycle(3,1);
Near32 36:54f86bc6fd80 35 bicycle.set((T)36, 1,1); /*radius*/
Near32 36:54f86bc6fd80 36 bicycle.set((T)36, 2,1);
Near32 36:54f86bc6fd80 37 bicycle.set((T)220, 3,1); /*entre-roue*/
Near32 47:4909e97570f6 38 Mat<T> r(state);
Near32 47:4909e97570f6 39
Near32 47:4909e97570f6 40 /*state v w */
Near32 47:4909e97570f6 41 /*
Near32 36:54f86bc6fd80 42 T v = state.get(4,1);
Near32 36:54f86bc6fd80 43 T w = state.get(5,1);
Near32 47:4909e97570f6 44 */
Near32 47:4909e97570f6 45 /*state phi_l phi_r */
Near32 47:4909e97570f6 46 T v = bicycle.get(1,1)/(2*bicycle.get(3,1))*(r.get(4,1)+r.get(5,1));
Near32 47:4909e97570f6 47 T w = bicycle.get(1,1)/(2*bicycle.get(3,1))*(r.get(4,1)-r.get(5,1));
Near32 36:54f86bc6fd80 48
Near32 36:54f86bc6fd80 49 r.set( r.get(1,1) + v*cos(r.get(3,1))*dt, 1,1);
Near32 36:54f86bc6fd80 50 r.set( r.get(2,1) + v*sin(r.get(3,1))*dt, 2,1);
Near32 36:54f86bc6fd80 51
Near32 36:54f86bc6fd80 52 T angle = (r.get(3,1) + dt*w);
Near32 36:54f86bc6fd80 53 if( angle < -PI)
Near32 36:54f86bc6fd80 54 {
Near32 36:54f86bc6fd80 55 angle = angle - PI*ceil(angle/PI);
Near32 36:54f86bc6fd80 56 }
Near32 36:54f86bc6fd80 57 else if( angle > PI)
Near32 36:54f86bc6fd80 58 {
Near32 36:54f86bc6fd80 59 angle = angle - PI*floor(angle/PI);
Near32 36:54f86bc6fd80 60 }
Near32 36:54f86bc6fd80 61
Near32 36:54f86bc6fd80 62 r.set( atan21(sin(angle), cos(angle)), 3,1);
Near32 36:54f86bc6fd80 63
Near32 36:54f86bc6fd80 64
Near32 36:54f86bc6fd80 65 /*----------------------------------------*/
Near32 36:54f86bc6fd80 66 /*Modele du moteur*/
Near32 36:54f86bc6fd80 67 /*----------------------------------------*/
Near32 36:54f86bc6fd80 68 //double r1 = bicycle.get(3,1)/bicycle.get(1,1)*(command.get(1,1)/bicycle.get(3,1)+command.get(2,1));
Near32 47:4909e97570f6 69 //double r2 = bicycle.get(3,1)/bicycle.get(1,1)*(command.get(1,1)/bicycle.get(3,1)-command.get(2,1));
Near32 47:4909e97570f6 70 /*state v w */
Near32 47:4909e97570f6 71 /*
Near32 36:54f86bc6fd80 72 T r1 = bicycle.get(1,1)/2*(command.get(1,1)+command.get(2,1));
Near32 36:54f86bc6fd80 73 T r2 = bicycle.get(1,1)/bicycle.get(3,1)*(command.get(1,1)-command.get(2,1));
Near32 47:4909e97570f6 74 */
Near32 47:4909e97570f6 75 /*state phi_l phi_r*/
Near32 47:4909e97570f6 76 T r1 = command.get(1,1);
Near32 47:4909e97570f6 77 T r2 = command.get(2,1);
Near32 36:54f86bc6fd80 78
Near32 36:54f86bc6fd80 79
Near32 36:54f86bc6fd80 80 r.set( r1, 4,1);
Near32 36:54f86bc6fd80 81 r.set( r2, 5,1);
Near32 36:54f86bc6fd80 82
Near32 36:54f86bc6fd80 83
Near32 36:54f86bc6fd80 84 /*----------------------------------------*/
Near32 36:54f86bc6fd80 85 /*----------------------------------------*/
Near32 36:54f86bc6fd80 86
Near32 36:54f86bc6fd80 87 return r;
Near32 36:54f86bc6fd80 88 }
Near32 36:54f86bc6fd80 89
Near32 36:54f86bc6fd80 90 template<typename T>
Near32 36:54f86bc6fd80 91 Mat<T> sensor_bicycle3( Mat<T> state, Mat<T> command, Mat<T> d_state, T dt)
Near32 36:54f86bc6fd80 92 {
Near32 36:54f86bc6fd80 93 /*
Near32 36:54f86bc6fd80 94 double angle = state.get(3,1);
Near32 36:54f86bc6fd80 95 if( angle < -PI)
Near32 36:54f86bc6fd80 96 {
Near32 36:54f86bc6fd80 97 angle = angle - PI*ceil(angle/PI);
Near32 36:54f86bc6fd80 98 }
Near32 36:54f86bc6fd80 99 else if( angle > PI)
Near32 36:54f86bc6fd80 100 {
Near32 36:54f86bc6fd80 101 angle = angle - PI*floor(angle/PI);
Near32 36:54f86bc6fd80 102 }
Near32 36:54f86bc6fd80 103
Near32 36:54f86bc6fd80 104 state.set( atan21(sin(angle), cos(angle)), 3,1);
Near32 36:54f86bc6fd80 105 */
Near32 36:54f86bc6fd80 106 return state;
Near32 36:54f86bc6fd80 107 }
Near32 36:54f86bc6fd80 108
Near32 36:54f86bc6fd80 109 template<typename T>
Near32 36:54f86bc6fd80 110 Mat<T> jmotion_bicycle3( Mat<T> state, Mat<T> command, T dt)
Near32 43:87bdce65341f 111 {
Near32 43:87bdce65341f 112 T h = pow(numeric_limits<T>::epsilon(),(T)0.5)*norme2(state)+ pow(numeric_limits<T>::epsilon(), (T)0.5);
Near32 36:54f86bc6fd80 113 Mat<T> var( (T)0, state.getLine(), state.getColumn());
Near32 36:54f86bc6fd80 114 var.set( h, 1,1);
Near32 36:54f86bc6fd80 115 Mat<T> G(motion_bicycle3(state+var, command, dt) - motion_bicycle3(state-var, command,dt));
Near32 36:54f86bc6fd80 116
Near32 36:54f86bc6fd80 117 for(int i=2;i<=state.getLine();i++)
Near32 36:54f86bc6fd80 118 {
Near32 36:54f86bc6fd80 119 var.set( (T)0, i-1,1);
Near32 36:54f86bc6fd80 120 var.set( h, i,1);
Near32 36:54f86bc6fd80 121 G = operatorL(G, motion_bicycle3(state+var, command, dt) - motion_bicycle3(state-var, command,dt) );
Near32 36:54f86bc6fd80 122 }
Near32 36:54f86bc6fd80 123
Near32 36:54f86bc6fd80 124
Near32 36:54f86bc6fd80 125 return ((T)1.0/(2*h))*G;
Near32 36:54f86bc6fd80 126 }
Near32 36:54f86bc6fd80 127
Near32 36:54f86bc6fd80 128 template<typename T>
Near32 36:54f86bc6fd80 129 Mat<T> jmotion_bicycle3_command(Mat<T> state, Mat<T> command, T dt)
Near32 36:54f86bc6fd80 130 {
Near32 43:87bdce65341f 131 T h = pow(numeric_limits<T>::epsilon(), (T)0.5)+sqrt(numeric_limits<T>::epsilon())*norme2(state);
Near32 36:54f86bc6fd80 132 Mat<T> var( (T)0, command.getLine(), command.getColumn());
Near32 36:54f86bc6fd80 133 var.set( h, 1,1);
Near32 36:54f86bc6fd80 134 Mat<T> G(motion_bicycle3(state, command+var, dt) - motion_bicycle3(state, command-var,dt));
Near32 36:54f86bc6fd80 135
Near32 36:54f86bc6fd80 136 for(int i=2;i<=command.getLine();i++)
Near32 36:54f86bc6fd80 137 {
Near32 36:54f86bc6fd80 138 var.set( (T)0, i-1,1);
Near32 36:54f86bc6fd80 139 var.set( h, i,1);
Near32 36:54f86bc6fd80 140 G = operatorL(G, motion_bicycle3(state, command+var, dt) - motion_bicycle3(state, command-var,dt) );
Near32 36:54f86bc6fd80 141 }
Near32 36:54f86bc6fd80 142
Near32 36:54f86bc6fd80 143
Near32 36:54f86bc6fd80 144 return (1.0/(2*h))*G;
Near32 36:54f86bc6fd80 145 }
Near32 36:54f86bc6fd80 146
Near32 36:54f86bc6fd80 147
Near32 36:54f86bc6fd80 148 template<typename T>
Near32 36:54f86bc6fd80 149 Mat<T> jsensor_bicycle3( Mat<T> state, Mat<T> command, Mat<T> d_state, T dt)
Near32 36:54f86bc6fd80 150 {
Near32 36:54f86bc6fd80 151 T h = pow(numeric_limits<T>::epsilon(), (T)0.5)+sqrt(numeric_limits<T>::epsilon())*norme2(state);
Near32 36:54f86bc6fd80 152 Mat<T> var((T)0, state.getLine(), state.getColumn());
Near32 36:54f86bc6fd80 153 var.set( h, 1,1);
Near32 36:54f86bc6fd80 154 Mat<T> H(sensor_bicycle3(state+var, command, d_state, dt) - sensor_bicycle3(state-var, command, d_state, dt));
Near32 36:54f86bc6fd80 155
Near32 36:54f86bc6fd80 156 for(int i=2;i<=state.getLine();i++)
Near32 36:54f86bc6fd80 157 {
Near32 36:54f86bc6fd80 158 var.set( (T)0, i-1,1);
Near32 36:54f86bc6fd80 159 var.set( h, i,1);
Near32 36:54f86bc6fd80 160 H = operatorL(H, sensor_bicycle3(state+var, command, d_state, dt) - sensor_bicycle3(state-var, command, d_state, dt) );
Near32 36:54f86bc6fd80 161 }
Near32 36:54f86bc6fd80 162
Near32 36:54f86bc6fd80 163
Near32 36:54f86bc6fd80 164 return ((T)1.0/(2*h))*H;
Near32 36:54f86bc6fd80 165 /*
Near32 36:54f86bc6fd80 166 double h = sqrt(numeric_limits<double>::epsilon())*10e2+sqrt(numeric_limits<double>::epsilon())*norme2(state);
Near32 36:54f86bc6fd80 167 Mat<double> var((double)0, state.getLine(), state.getColumn());
Near32 36:54f86bc6fd80 168 var.set( h, 1,1);
Near32 36:54f86bc6fd80 169 Mat<double> H(sensor_bicycle3(state+var, command, d_state, dt) - sensor_bicycle3(state-var, command, d_state, dt));
Near32 36:54f86bc6fd80 170
Near32 36:54f86bc6fd80 171 for(int i=2;i<=state.getLine();i++)
Near32 36:54f86bc6fd80 172 {
Near32 36:54f86bc6fd80 173 var.set( (double)0, i-1,1);
Near32 36:54f86bc6fd80 174 var.set( h, i,1);
Near32 36:54f86bc6fd80 175 H = operatorL(H, sensor_bicycle3(state+var, command, d_state, dt) - sensor_bicycle3(state-var, command, d_state, dt) );
Near32 36:54f86bc6fd80 176
Near32 36:54f86bc6fd80 177 }
Near32 36:54f86bc6fd80 178
Near32 36:54f86bc6fd80 179
Near32 36:54f86bc6fd80 180 return (1.0/(2*h))*H;
Near32 36:54f86bc6fd80 181 */
Near32 43:87bdce65341f 182 }
Near32 43:87bdce65341f 183 //int reduc = 16;
Near32 43:87bdce65341f 184
Near32 43:87bdce65341f 185 extern Serial logger;
Near32 43:87bdce65341f 186
Near32 43:87bdce65341f 187 /*---------------------------------------------------------------------------------------------------------*/
Near32 43:87bdce65341f 188 /*---------------------------------------------------------------------------------------------------------*/
Near32 43:87bdce65341f 189
Near32 43:87bdce65341f 190 template<typename T>
Near32 43:87bdce65341f 191 class Asserv
Near32 43:87bdce65341f 192 {
Near32 43:87bdce65341f 193 private :
Near32 43:87bdce65341f 194
Near32 43:87bdce65341f 195 Odometry* odometry;
Near32 43:87bdce65341f 196 EKF<T>* instanceEKF;
Near32 43:87bdce65341f 197 int nbrstate;
Near32 43:87bdce65341f 198 int nbrcontrol;
Near32 43:87bdce65341f 199 int nbrobs;
Near32 43:87bdce65341f 200 T dt;
Near32 43:87bdce65341f 201
Near32 43:87bdce65341f 202 T stdnoise;
Near32 43:87bdce65341f 203 Mat<T> X;
Near32 43:87bdce65341f 204 Mat<T> dX;
Near32 43:87bdce65341f 205 Mat<T> initX;
Near32 43:87bdce65341f 206 Mat<T> z;
Near32 43:87bdce65341f 207 Mat<T> u;
Near32 43:87bdce65341f 208 bool extended;
Near32 43:87bdce65341f 209 bool filterOn;
Near32 43:87bdce65341f 210
Near32 43:87bdce65341f 211 Mat<T> ki;
Near32 43:87bdce65341f 212 Mat<T> kp;
Near32 43:87bdce65341f 213 Mat<T> kd;
Near32 43:87bdce65341f 214
Near32 43:87bdce65341f 215 public :
Near32 43:87bdce65341f 216
Near32 43:87bdce65341f 217 T phi_r;
Near32 43:87bdce65341f 218 T phi_l;
Near32 43:87bdce65341f 219 T phi_max;
Near32 43:87bdce65341f 220 bool execution;
Near32 43:87bdce65341f 221 bool isarrived;
Near32 43:87bdce65341f 222
Near32 43:87bdce65341f 223 Asserv(Odometry* odometry)
Near32 43:87bdce65341f 224 {
Near32 43:87bdce65341f 225 /*Odometry*/
Near32 43:87bdce65341f 226 this->odometry = odometry;
Near32 44:d5f95af61243 227 phi_max = (T)100.0;
Near32 43:87bdce65341f 228
Near32 43:87bdce65341f 229 /*KalmanFilter*/
Near32 43:87bdce65341f 230 //double phi_max = 100;
Near32 43:87bdce65341f 231 /*en millimetres*/
Near32 43:87bdce65341f 232
Near32 43:87bdce65341f 233 nbrstate = 5;
Near32 43:87bdce65341f 234 nbrcontrol = 2;
Near32 43:87bdce65341f 235 nbrobs = 5;
Near32 43:87bdce65341f 236 dt = (T)0.05;
Near32 43:87bdce65341f 237 stdnoise = (T)0.05;
Near32 43:87bdce65341f 238
Near32 43:87bdce65341f 239 initX = Mat<T>((T)0, nbrstate, 1);
Near32 43:87bdce65341f 240 initX.set( (T)0, 3,1);
Near32 43:87bdce65341f 241 X = initX;
Near32 43:87bdce65341f 242
Near32 43:87bdce65341f 243 extended = true;
Near32 43:87bdce65341f 244 filterOn = true;
Near32 43:87bdce65341f 245
Near32 43:87bdce65341f 246 instanceEKF = new EKF<T>(nbrstate, nbrcontrol, nbrobs, dt, stdnoise, /*current state*/ initX, extended, filterOn);
Near32 43:87bdce65341f 247
Near32 43:87bdce65341f 248 instanceEKF->initMotion(motion_bicycle3);
Near32 43:87bdce65341f 249 instanceEKF->initSensor(sensor_bicycle3);
Near32 43:87bdce65341f 250 instanceEKF->initJMotion(jmotion_bicycle3);
Near32 43:87bdce65341f 251 //instanceEKF.initJMotionCommand(jmotion_bicycle3_command);
Near32 43:87bdce65341f 252 instanceEKF->initJSensor(jsensor_bicycle3);
Near32 43:87bdce65341f 253
Near32 43:87bdce65341f 254 /*desired State : (x y theta phiright phileft)*/
Near32 43:87bdce65341f 255 dX = Mat<T>((T)0, nbrstate, 1);
Near32 43:87bdce65341f 256 dX.set( (T)0, 1,1);
Near32 43:87bdce65341f 257 dX.set( (T)0, 2,1);
Near32 43:87bdce65341f 258 dX.set( (T)0, 3,1);
Near32 43:87bdce65341f 259 dX.set( (T)0, 4,1);
Near32 43:87bdce65341f 260 dX.set( (T)0, 5,1);
Near32 43:87bdce65341f 261
Near32 43:87bdce65341f 262 ki = Mat<T>((T)0, nbrcontrol, nbrstate);
Near32 43:87bdce65341f 263 kp = Mat<T>((T)0, nbrcontrol, nbrstate);
Near32 43:87bdce65341f 264 kd = Mat<T>((T)0, nbrcontrol, nbrstate);
Near32 43:87bdce65341f 265 //Mat<double> kdd((double)0.0015, nbrcontrol, nbrstate);
Near32 43:87bdce65341f 266
Near32 43:87bdce65341f 267 for(int i=1;i<=nbrstate;i++)
Near32 43:87bdce65341f 268 {
Near32 43:87bdce65341f 269 kp.set( (T)0.01, i, i);
Near32 43:87bdce65341f 270 kd.set( (T)0.0001, i, i);
Near32 43:87bdce65341f 271 ki.set( (T)0.0001, i, i);
Near32 43:87bdce65341f 272 }
Near32 43:87bdce65341f 273
Near32 43:87bdce65341f 274 instanceEKF->setKi(ki);
Near32 43:87bdce65341f 275 instanceEKF->setKp(kp);
Near32 43:87bdce65341f 276 instanceEKF->setKd(kd);
Near32 43:87bdce65341f 277 //instance.setKdd(kdd);
Near32 43:87bdce65341f 278
Near32 43:87bdce65341f 279 u = Mat<T>(transpose( instanceEKF->getCommand()) );
Near32 43:87bdce65341f 280
Near32 43:87bdce65341f 281 /*Observations*/
Near32 43:87bdce65341f 282 /*il nous faut 5 observation : mais on n'en met à jour que 3...*/
Near32 43:87bdce65341f 283 z = Mat<T>((T)0,5,1);
Near32 43:87bdce65341f 284 this->measurementCallback(&z);
Near32 43:87bdce65341f 285
Near32 43:87bdce65341f 286 /*----------------------------------------------------------------------------------------------*/
Near32 43:87bdce65341f 287 isarrived = true;
Near32 43:87bdce65341f 288 execution = false;
Near32 43:87bdce65341f 289
Near32 43:87bdce65341f 290 }
Near32 43:87bdce65341f 291
Near32 43:87bdce65341f 292 ~Asserv()
Near32 43:87bdce65341f 293 {
Near32 43:87bdce65341f 294 delete instanceEKF;
Near32 43:87bdce65341f 295 }
Near32 43:87bdce65341f 296
Near32 43:87bdce65341f 297 void setGoal(T x, T y, T theta)
Near32 43:87bdce65341f 298 {
Near32 43:87bdce65341f 299 dX.set(x,1,1);
Near32 43:87bdce65341f 300 dX.set(y,2,1);
Near32 43:87bdce65341f 301 dX.set(theta,3,1);
Near32 43:87bdce65341f 302 dX.set((T)0,4,1);
Near32 43:87bdce65341f 303 dX.set((T)0,5,1);
Near32 43:87bdce65341f 304 execution = true;
Near32 43:87bdce65341f 305 isarrived = false;
Near32 43:87bdce65341f 306
Near32 43:87bdce65341f 307 }
Near32 43:87bdce65341f 308
Near32 43:87bdce65341f 309 bool isArrived() { return isarrived;}
Near32 43:87bdce65341f 310
Near32 43:87bdce65341f 311 void stop()
Near32 43:87bdce65341f 312 {
Near32 43:87bdce65341f 313 execution = false;
Near32 43:87bdce65341f 314 }
Near32 43:87bdce65341f 315
Near32 43:87bdce65341f 316 void update(T deltat)
Near32 43:87bdce65341f 317 {
Near32 43:87bdce65341f 318 if(execution)
Near32 43:87bdce65341f 319 {
Near32 47:4909e97570f6 320 dt = deltat;
Near32 47:4909e97570f6 321
Near32 43:87bdce65341f 322 /*Asservissement*/
Near32 47:4909e97570f6 323 this->measurementCallback(&z);
Near32 47:4909e97570f6 324 transpose(z).afficherMblue();
Near32 43:87bdce65341f 325 instanceEKF->measurement_Callback( z, dX, true );
Near32 43:87bdce65341f 326 instanceEKF->state_Callback();
Near32 47:4909e97570f6 327 //instanceEKF->setX(z);
Near32 43:87bdce65341f 328 X = instanceEKF->getX();
Near32 43:87bdce65341f 329
Near32 47:4909e97570f6 330 instanceEKF->computeCommand(dX, (T)dt, -1);
Near32 47:4909e97570f6 331 //instanceEKF->computeCommand(dX, (T)dt, -2);
Near32 44:d5f95af61243 332 phi_l = instanceEKF->getCommand().get(1,1);
Near32 44:d5f95af61243 333 phi_r = instanceEKF->getCommand().get(2,1);
Near32 43:87bdce65341f 334 }
Near32 43:87bdce65341f 335 else
Near32 43:87bdce65341f 336 {
Near32 43:87bdce65341f 337 phi_r = (T)0;
Near32 43:87bdce65341f 338 phi_l = (T)0;
Near32 43:87bdce65341f 339 }
Near32 43:87bdce65341f 340 }
Near32 43:87bdce65341f 341
Near32 47:4909e97570f6 342 void measurementCallbackVW( Mat<T>* z)
Near32 43:87bdce65341f 343 {
Near32 43:87bdce65341f 344 z->set( (T)/*conversionUnitée mm */this->odometry->getX(), 1,1);
Near32 43:87bdce65341f 345 z->set( (T)/*conversionUnitée mm*/this->odometry->getY(), 2,1);
Near32 43:87bdce65341f 346 T theta = (T)this->odometry->getTheta();
Near32 43:87bdce65341f 347 theta = atan21(sin(theta),cos(theta));
Near32 43:87bdce65341f 348 z->set( (double)/*conversionUnitée rad*/theta, 3,1);//odometry->getTheta(), 3,1);
Near32 43:87bdce65341f 349 T vx = (T)this->odometry->getVx();
Near32 43:87bdce65341f 350 T vy = (T)this->odometry->getVy();
Near32 43:87bdce65341f 351 z->set( sqrt(vx*vx+vy*vy),4,1);
Near32 43:87bdce65341f 352 z->set( (T)odometry->getW(),5,1);
Near32 43:87bdce65341f 353
Near32 44:d5f95af61243 354 //transpose(*z).afficherMblue();
Near32 47:4909e97570f6 355 }
Near32 47:4909e97570f6 356
Near32 47:4909e97570f6 357 void measurementCallback( Mat<T>* z)
Near32 47:4909e97570f6 358 {
Near32 47:4909e97570f6 359 z->set( (T)/*conversionUnitée mm */this->odometry->getX(), 1,1);
Near32 47:4909e97570f6 360 z->set( (T)/*conversionUnitée mm*/this->odometry->getY(), 2,1);
Near32 47:4909e97570f6 361 T theta = (T)this->odometry->getTheta();
Near32 47:4909e97570f6 362 theta = atan21(sin(theta),cos(theta));
Near32 47:4909e97570f6 363 z->set( (double)/*conversionUnitée rad*/theta, 3,1);//odometry->getTheta(), 3,1);
Near32 47:4909e97570f6 364
Near32 47:4909e97570f6 365 //State : phi_l phi_r
Near32 47:4909e97570f6 366 z->set( (T)this->odometry->getPhileft(),4,1);
Near32 47:4909e97570f6 367 z->set( (T)this->odometry->getPhiright(),5,1);
Near32 47:4909e97570f6 368
Near32 47:4909e97570f6 369 //transpose(*z).afficherMblue();
Near32 43:87bdce65341f 370 }
Near32 43:87bdce65341f 371
Near32 43:87bdce65341f 372 Mat<T> getX()
Near32 43:87bdce65341f 373 {
Near32 43:87bdce65341f 374 return X;
Near32 43:87bdce65341f 375 }
Near32 43:87bdce65341f 376
Near32 43:87bdce65341f 377 T getPhiR()
Near32 43:87bdce65341f 378 {
Near32 43:87bdce65341f 379 return phi_r;
Near32 43:87bdce65341f 380 }
Near32 43:87bdce65341f 381
Near32 43:87bdce65341f 382 T getPhiL()
Near32 43:87bdce65341f 383 {
Near32 43:87bdce65341f 384 return phi_l;
Near32 43:87bdce65341f 385 }
Near32 43:87bdce65341f 386
Near32 43:87bdce65341f 387 T getPhiMax()
Near32 43:87bdce65341f 388 {
Near32 43:87bdce65341f 389 return phi_max;
Near32 43:87bdce65341f 390 }
Near32 43:87bdce65341f 391
Near32 43:87bdce65341f 392
Near32 43:87bdce65341f 393 };