Robot's source code

Dependencies:   mbed

Committer:
Near32
Date:
Tue Jan 20 14:38:23 2015 +0000
Revision:
26:54e1afed58b2
Parent:
24:3c0422e1ebd6
Child:
27:5f441ecda140
mise en commentaire des printf

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jagang 0:41149573d577 1 #include "mbed.h"
Jagang 0:41149573d577 2 #include "QEI.h"
Jagang 0:41149573d577 3 #include "Odometry.h"
Jagang 23:228317fe0457 4 #include "Map.h"
Jagang 0:41149573d577 5
Near32 3:573a0dc8383f 6 /*---------------------------------------------------------------------------------------------------------*/
Near32 3:573a0dc8383f 7 /*---------------------------------------------------------------------------------------------------------*/
Near32 3:573a0dc8383f 8 /*KalmanFilter*/
Near32 3:573a0dc8383f 9 #include "EKF.h"
Near32 17:f360e21d3307 10 Mat<double> motion_bicycle3( Mat<double> state, Mat<double> command, double dt = 0.5);
Near32 17:f360e21d3307 11 Mat<double> sensor_bicycle3( Mat<double> state, Mat<double> command, Mat<double> d_state, double dt = 0.5 );
Near32 17:f360e21d3307 12 Mat<double> jmotion_bicycle3( Mat<double> state, Mat<double> command, double dt = 0.5);
Near32 24:3c0422e1ebd6 13 Mat<double> jmotion_bicycle3_command(Mat<double> state, Mat<double> command, double dt = 0.5);
Near32 17:f360e21d3307 14 Mat<double> jsensor_bicycle3( Mat<double> state, Mat<double> command, Mat<double> d_state, double dt = 0.5);
Near32 3:573a0dc8383f 15 void measurementCallback( Mat<double>* z, Odometry* odometry);
Near32 17:f360e21d3307 16 bool setPWM(PwmOut *servo,float p);
Near32 3:573a0dc8383f 17
Near32 3:573a0dc8383f 18 Mat<double> bicycle(3,1);
Near32 17:f360e21d3307 19 int reduc = 16;
Near32 3:573a0dc8383f 20 /*---------------------------------------------------------------------------------------------------------*/
Near32 3:573a0dc8383f 21 /*---------------------------------------------------------------------------------------------------------*/
Near32 3:573a0dc8383f 22
Near32 17:f360e21d3307 23 /*----------------------------------------------------------------------------------------------*/
Near32 17:f360e21d3307 24 /*Serial*/
Near32 17:f360e21d3307 25 Serial pcs(USBTX, USBRX); // tx, rx
Near32 17:f360e21d3307 26 /*----------------------------------------------------------------------------------------------*/
Jagang 21:5443f93819db 27
Jagang 23:228317fe0457 28 /* --- Initialisation de la liste des obstable --- */
Jagang 23:228317fe0457 29 int Obstacle::lastId = 0;
Jagang 23:228317fe0457 30
Jagang 0:41149573d577 31 int main()
Jagang 0:41149573d577 32 {
Near32 24:3c0422e1ebd6 33 pcs.printf("demarrage");
Near32 24:3c0422e1ebd6 34 //mbed
Near32 24:3c0422e1ebd6 35 /*
Near32 17:f360e21d3307 36 PwmOut pw1(p22);
Near32 17:f360e21d3307 37 DigitalOut dir1(p21);
Near32 17:f360e21d3307 38 PwmOut pw2(p24);
Near32 17:f360e21d3307 39 DigitalOut dir2(p23);
Near32 24:3c0422e1ebd6 40 */
Near32 17:f360e21d3307 41
Near32 17:f360e21d3307 42 //mbuino
Near32 17:f360e21d3307 43 /*
Near32 17:f360e21d3307 44 PwmOut pw1(P0_17);
Near32 17:f360e21d3307 45 DigitalOut dir1(P0_18);
Near32 17:f360e21d3307 46 PwmOut pw2(P0_23);
Near32 17:f360e21d3307 47 DigitalOut dir2(P0_19);
Near32 17:f360e21d3307 48 */
Near32 17:f360e21d3307 49 /*
Near32 17:f360e21d3307 50 //nucleo
Near32 17:f360e21d3307 51 PwmOut pw1(PB_8);
Near32 17:f360e21d3307 52 DigitalOut dir1(D12);
Near32 17:f360e21d3307 53 PwmOut pw2(PB_9);
Near32 17:f360e21d3307 54 DigitalOut dir2(D13);
Near32 17:f360e21d3307 55 */
Near32 24:3c0422e1ebd6 56 //nucleo
Near32 24:3c0422e1ebd6 57 PwmOut pw1(PA_0);
Near32 24:3c0422e1ebd6 58 DigitalOut dir1(PB_8);
Near32 24:3c0422e1ebd6 59 PwmOut pw2(PA_1);
Near32 24:3c0422e1ebd6 60 DigitalOut dir2(PB_9);
Near32 17:f360e21d3307 61 pw1.period_us(10);
Near32 17:f360e21d3307 62 pw2.period_us(10);
Near32 17:f360e21d3307 63
Near32 17:f360e21d3307 64
Near32 17:f360e21d3307 65 dir1.write(0);
Near32 17:f360e21d3307 66 dir2.write(0);
Near32 24:3c0422e1ebd6 67
Near32 26:54e1afed58b2 68 pw1.write(0.0);
Near32 26:54e1afed58b2 69 pw2.write(0.0);
Near32 17:f360e21d3307 70 //setPWM(&pw1,0.9);
Near32 24:3c0422e1ebd6 71 pcs.printf("mise a jour des pwm.\n");
Near32 26:54e1afed58b2 72 Timer t;
Near32 24:3c0422e1ebd6 73
Near32 17:f360e21d3307 74 //while(1);
Near32 3:573a0dc8383f 75 /*----------------------------------------------------------------------------------------------*/
Near32 3:573a0dc8383f 76 /*Odometry*/
Near32 24:3c0422e1ebd6 77 //QEI qei_left(p15,p16,NC,1024*reduc,QEI::X4_ENCODING);
Near32 17:f360e21d3307 78 //QEI qei_left(P0_2,P0_7,NC,1024*reduc,QEI::X4_ENCODING);//mbuino
Near32 17:f360e21d3307 79 //QEI qei_left(PA_3,PA_2,NC,1024*reduc,QEI::X4_ENCODING);//nucleo
Near32 17:f360e21d3307 80
Near32 24:3c0422e1ebd6 81 //QEI qei_right(p17,p18,NC,1024*reduc,QEI::X4_ENCODING);
Near32 17:f360e21d3307 82 //QEI qei_right(P0_8,P0_20,NC,1024*reduc,QEI::X4_ENCODING);//mbuino
Near32 17:f360e21d3307 83 //QEI qei_right(PA_10,PB_3,NC,1024*reduc,QEI::X4_ENCODING);//nucleo
Near32 24:3c0422e1ebd6 84
Near32 24:3c0422e1ebd6 85 //Odometry odometry(&qei_left,&qei_right,0.07,0.07,0.26);
Near32 3:573a0dc8383f 86 /*----------------------------------------------------------------------------------------------*/
Jagang 0:41149573d577 87
Near32 3:573a0dc8383f 88
Near32 3:573a0dc8383f 89
Near32 3:573a0dc8383f 90 /*----------------------------------------------------------------------------------------------*/
Near32 3:573a0dc8383f 91 /*KalmanFilter*/
Near32 24:3c0422e1ebd6 92 //double phi_max = 100;
Near32 3:573a0dc8383f 93 /*en millimetres*/
Near32 26:54e1afed58b2 94 bicycle.set((double)36, 1,1); /*radius*/
Near32 26:54e1afed58b2 95 bicycle.set((double)36, 2,1);
Near32 26:54e1afed58b2 96 bicycle.set((double)220, 3,1); /*entre-roue*/
Near32 3:573a0dc8383f 97
Near32 3:573a0dc8383f 98 int nbrstate = 5;
Near32 3:573a0dc8383f 99 int nbrcontrol = 2;
Near32 17:f360e21d3307 100 int nbrobs = 5;
Near32 3:573a0dc8383f 101 double dt = (double)0.05;
Near32 8:1150a13f6967 102 double stdnoise = (double)0.05;
Near32 3:573a0dc8383f 103
Near32 3:573a0dc8383f 104 Mat<double> initX((double)0, nbrstate, 1);
Near32 3:573a0dc8383f 105 initX.set( (double)0, 3,1);
Near32 3:573a0dc8383f 106
Near32 3:573a0dc8383f 107 bool extended = true;
Near32 24:3c0422e1ebd6 108 bool filterOn = true;
Near32 24:3c0422e1ebd6 109 pcs.printf("mise a jour des pwm.\n");
Near32 24:3c0422e1ebd6 110 EKF<double> instance(nbrstate, nbrcontrol, nbrobs, dt, stdnoise, /*current state*/ initX, extended, filterOn);
Near32 3:573a0dc8383f 111
Near32 17:f360e21d3307 112 instance.initMotion(motion_bicycle3);
Near32 17:f360e21d3307 113 instance.initSensor(sensor_bicycle3);
Near32 17:f360e21d3307 114 instance.initJMotion(jmotion_bicycle3);
Near32 24:3c0422e1ebd6 115 //instance.initJMotionCommand(jmotion_bicycle3_command);
Near32 17:f360e21d3307 116 instance.initJSensor(jsensor_bicycle3);
Near32 3:573a0dc8383f 117
Near32 3:573a0dc8383f 118 /*desired State : (x y theta phiright phileft)*/
Near32 3:573a0dc8383f 119 Mat<double> dX((double)0, nbrstate, 1);
Near32 17:f360e21d3307 120 dX.set( (double)100, 1,1);
Near32 17:f360e21d3307 121 dX.set( (double)0, 2,1);
Near32 4:4025c071b207 122 dX.set( (double)0, 3,1);
Near32 3:573a0dc8383f 123 dX.set( (double)0, 4,1);
Near32 3:573a0dc8383f 124 dX.set( (double)0, 5,1);
Near32 3:573a0dc8383f 125
Near32 17:f360e21d3307 126 Mat<double> ki((double)0, nbrcontrol, nbrstate);
Near32 17:f360e21d3307 127 Mat<double> kp((double)0, nbrcontrol, nbrstate);
Near32 17:f360e21d3307 128 Mat<double> kd((double)0, nbrcontrol, nbrstate);
Near32 17:f360e21d3307 129 //Mat<double> kdd((double)0.0015, nbrcontrol, nbrstate);
Near32 17:f360e21d3307 130
Near32 17:f360e21d3307 131 for(int i=1;i<=nbrstate;i++)
Near32 17:f360e21d3307 132 {
Near32 17:f360e21d3307 133 kp.set( (double)0.01, i, i);
Near32 17:f360e21d3307 134 kd.set( (double)0.0001, i, i);
Near32 17:f360e21d3307 135 ki.set( (double)0.0001, i, i);
Near32 17:f360e21d3307 136 }
Near32 17:f360e21d3307 137
Near32 17:f360e21d3307 138 instance.setKi(ki);
Near32 17:f360e21d3307 139 instance.setKp(kp);
Near32 17:f360e21d3307 140 instance.setKd(kd);
Near32 17:f360e21d3307 141 //instance.setKdd(kdd);
Near32 17:f360e21d3307 142
Near32 3:573a0dc8383f 143 Mat<double> u(transpose( instance.getCommand()) );
Near32 3:573a0dc8383f 144
Near32 3:573a0dc8383f 145 /*Observations*/
Near32 17:f360e21d3307 146 /*il nous faut 5 observation :*/
Near32 17:f360e21d3307 147 Mat<double> z((double)0,5,1);
Near32 24:3c0422e1ebd6 148 //measurementCallback(&z, &odometry);
Near32 3:573a0dc8383f 149
Near32 3:573a0dc8383f 150 /*----------------------------------------------------------------------------------------------*/
Near32 3:573a0dc8383f 151
Near32 3:573a0dc8383f 152
Near32 24:3c0422e1ebd6 153 while(abs(instance.getX().get(1,1)-100) > 10)
Near32 26:54e1afed58b2 154 {
Near32 26:54e1afed58b2 155 t.start();
Near32 24:3c0422e1ebd6 156 //pcs.printf("%f : %f : %f\n", (double)odometry.getX()*100,(double)odometry.getY()*100,(double)odometry.getTheta()*180/3.14);
Near32 17:f360e21d3307 157
Near32 3:573a0dc8383f 158
Near32 3:573a0dc8383f 159 /*------------------------------------------------------------------------------------------*/
Near32 17:f360e21d3307 160 /*Asservissement*/
Near32 17:f360e21d3307 161
Near32 17:f360e21d3307 162 //measurementCallback(&z, &odometry);
Near32 17:f360e21d3307 163 instance.measurement_Callback( instance.getX(), dX, true );
Near32 17:f360e21d3307 164
Near32 3:573a0dc8383f 165 instance.state_Callback();
Near32 17:f360e21d3307 166
Near32 10:bca0274a007b 167 double phi_r = instance.getCommand().get(1,1);
Near32 10:bca0274a007b 168 double phi_l = instance.getCommand().get(2,1);
Near32 8:1150a13f6967 169
Near32 26:54e1afed58b2 170 double phi_max = 1.0;
Near32 3:573a0dc8383f 171
Near32 24:3c0422e1ebd6 172 instance.computeCommand(dX, (double)dt, -2);
Near32 26:54e1afed58b2 173 //pcs.printf("command : \n phi_r = %f \n phi_l = %f \n", ((double)phi_r/phi_max), ((double)phi_l/phi_max));
Near32 26:54e1afed58b2 174 //(instance.getCommand()).afficher();
Near32 26:54e1afed58b2 175 //(instance.getX()).afficher();
Near32 17:f360e21d3307 176
Near32 17:f360e21d3307 177
Near32 24:3c0422e1ebd6 178 if(phi_r >= 0)
Near32 24:3c0422e1ebd6 179 dir1.write(1);
Near32 24:3c0422e1ebd6 180 else
Near32 17:f360e21d3307 181 dir1.write(0);
Near32 17:f360e21d3307 182
Near32 17:f360e21d3307 183 if(phi_l <= 0)
Near32 17:f360e21d3307 184 dir2.write(0);
Near32 17:f360e21d3307 185 else
Near32 17:f360e21d3307 186 dir2.write(1);
Near32 17:f360e21d3307 187
Near32 17:f360e21d3307 188 if(abs(phi_r/phi_max) < 1.0)
Near32 26:54e1afed58b2 189 {
Near32 26:54e1afed58b2 190 //pcs.printf( "VALUE PWM 1 : %f \n", (float)abs((double)phi_r/phi_max)) ;
Near32 22:80fdb12c167f 191 setPWM(&pw1, (float)abs((double)phi_r/phi_max));
Near32 26:54e1afed58b2 192 }
Near32 17:f360e21d3307 193 else
Near32 24:3c0422e1ebd6 194 pcs.printf("P1...");
Near32 17:f360e21d3307 195
Near32 17:f360e21d3307 196 if(abs(phi_l/phi_max) < 1.0)
Near32 26:54e1afed58b2 197 {
Near32 26:54e1afed58b2 198 //pcs.printf( "VALUE PWM 2 : %f \n", (float)abs((double)phi_l/phi_max)) ;
Near32 22:80fdb12c167f 199 setPWM(&pw2,(float)abs((double)phi_l/phi_max));
Near32 26:54e1afed58b2 200 }
Near32 17:f360e21d3307 201 else
Near32 17:f360e21d3307 202 pcs.printf("P2...");
Near32 17:f360e21d3307 203
Near32 26:54e1afed58b2 204 //pcs.printf("\n\n----------------- Commande mise executee. ------------------ \n");
Near32 26:54e1afed58b2 205 t.stop();
Near32 26:54e1afed58b2 206 pcs.printf("%f s \n\r", t.read());
Near32 26:54e1afed58b2 207 t.reset();
Near32 26:54e1afed58b2 208
Near32 26:54e1afed58b2 209 }
Near32 3:573a0dc8383f 210
Near32 26:54e1afed58b2 211
Near32 26:54e1afed58b2 212 DigitalOut led(LED1);
Near32 26:54e1afed58b2 213 while(1)
Near32 26:54e1afed58b2 214 {
Near32 26:54e1afed58b2 215 //setPWM(&pw1,0.0);
Near32 26:54e1afed58b2 216 //setPWM(&pw2,0.0);
Near32 26:54e1afed58b2 217 pw1.write(0.0);
Near32 26:54e1afed58b2 218 pw2.write(0.0);
Near32 26:54e1afed58b2 219 led = !led;
Near32 26:54e1afed58b2 220 wait(1);
Jagang 0:41149573d577 221 }
Jagang 0:41149573d577 222 }
Near32 3:573a0dc8383f 223
Near32 3:573a0dc8383f 224 void measurementCallback( Mat<double>* z, Odometry* odometry)
Near32 3:573a0dc8383f 225 {
Near32 3:573a0dc8383f 226 z->set( (double)/*conversionUnitée mm */odometry->getX(), 1,1);
Near32 3:573a0dc8383f 227 z->set( (double)/*conversionUnitée mm*/odometry->getY(), 2,1);
Near32 3:573a0dc8383f 228 z->set( (double)/*conversionUnitée rad*/odometry->getTheta(), 3,1);
Near32 3:573a0dc8383f 229 }
Near32 3:573a0dc8383f 230
Near32 17:f360e21d3307 231 Mat<double> motion_bicycle3( Mat<double> state, Mat<double> command, double dt)
Near32 3:573a0dc8383f 232 {
Near32 3:573a0dc8383f 233 Mat<double> r(state);
Near32 24:3c0422e1ebd6 234 //double v = bicycle.get(1,1)/(2*bicycle.get(3,1))*(r.get(4,1)+r.get(5,1));
Near32 24:3c0422e1ebd6 235 //double w = bicycle.get(1,1)/(2*bicycle.get(3,1))*(r.get(4,1)-r.get(5,1));
Near32 24:3c0422e1ebd6 236 double v = state.get(4,1);
Near32 24:3c0422e1ebd6 237 double w = state.get(5,1);
Near32 3:573a0dc8383f 238
Near32 3:573a0dc8383f 239 r.set( r.get(1,1) + v*cos(r.get(3,1))*dt, 1,1);
Near32 3:573a0dc8383f 240 r.set( r.get(2,1) + v*sin(r.get(3,1))*dt, 2,1);
Near32 3:573a0dc8383f 241
Near32 17:f360e21d3307 242 double angle = (r.get(3,1) + dt*w);
Near32 3:573a0dc8383f 243 if( angle < -PI)
Near32 3:573a0dc8383f 244 {
Near32 3:573a0dc8383f 245 angle = angle - PI*ceil(angle/PI);
Near32 3:573a0dc8383f 246 }
Near32 3:573a0dc8383f 247 else if( angle > PI)
Near32 3:573a0dc8383f 248 {
Near32 3:573a0dc8383f 249 angle = angle - PI*floor(angle/PI);
Near32 3:573a0dc8383f 250 }
Near32 3:573a0dc8383f 251
Near32 17:f360e21d3307 252 r.set( atan21(sin(angle), cos(angle)), 3,1);
Near32 3:573a0dc8383f 253
Near32 17:f360e21d3307 254
Near32 17:f360e21d3307 255 /*----------------------------------------*/
Near32 17:f360e21d3307 256 /*Modele du moteur*/
Near32 17:f360e21d3307 257 /*----------------------------------------*/
Near32 24:3c0422e1ebd6 258 //double r1 = bicycle.get(3,1)/bicycle.get(1,1)*(command.get(1,1)/bicycle.get(3,1)+command.get(2,1));
Near32 24:3c0422e1ebd6 259 //double r2 = bicycle.get(3,1)/bicycle.get(1,1)*(command.get(1,1)/bicycle.get(3,1)-command.get(2,1));
Near32 24:3c0422e1ebd6 260 double r1 = bicycle.get(1,1)/2*(command.get(1,1)+command.get(2,1));
Near32 24:3c0422e1ebd6 261 double r2 = bicycle.get(1,1)/bicycle.get(3,1)*(command.get(1,1)-command.get(2,1));
Near32 17:f360e21d3307 262
Near32 17:f360e21d3307 263
Near32 17:f360e21d3307 264 r.set( r1, 4,1);
Near32 17:f360e21d3307 265 r.set( r2, 5,1);
Near32 17:f360e21d3307 266
Near32 17:f360e21d3307 267
Near32 17:f360e21d3307 268 /*----------------------------------------*/
Near32 17:f360e21d3307 269 /*----------------------------------------*/
Near32 3:573a0dc8383f 270
Near32 3:573a0dc8383f 271 return r;
Near32 3:573a0dc8383f 272 }
Near32 3:573a0dc8383f 273
Near32 3:573a0dc8383f 274
Near32 17:f360e21d3307 275 Mat<double> sensor_bicycle3( Mat<double> state, Mat<double> command, Mat<double> d_state, double dt)
Near32 17:f360e21d3307 276 {
Near32 17:f360e21d3307 277 return state;
Near32 3:573a0dc8383f 278 }
Near32 3:573a0dc8383f 279
Near32 17:f360e21d3307 280
Near32 17:f360e21d3307 281 Mat<double> jmotion_bicycle3( Mat<double> state, Mat<double> command, double dt)
Near32 3:573a0dc8383f 282 {
Near32 3:573a0dc8383f 283 double h = numeric_limits<double>::epsilon()*10e2;
Near32 3:573a0dc8383f 284 Mat<double> var( (double)0, state.getLine(), state.getColumn());
Near32 3:573a0dc8383f 285 var.set( h, 1,1);
Near32 17:f360e21d3307 286 Mat<double> G(motion_bicycle3(state, command, dt) - motion_bicycle3(state+var, command,dt));
Near32 3:573a0dc8383f 287
Near32 3:573a0dc8383f 288 for(int i=2;i<=state.getLine();i++)
Near32 3:573a0dc8383f 289 {
Near32 3:573a0dc8383f 290 var.set( (double)0, i-1,1);
Near32 3:573a0dc8383f 291 var.set( h, i,1);
Near32 17:f360e21d3307 292 G = operatorL(G, motion_bicycle3(state, command, dt) - motion_bicycle3(state+var, command,dt) );
Near32 3:573a0dc8383f 293 }
Near32 3:573a0dc8383f 294
Near32 3:573a0dc8383f 295
Near32 3:573a0dc8383f 296 return (1.0/h)*G;
Near32 3:573a0dc8383f 297 }
Near32 3:573a0dc8383f 298
Near32 24:3c0422e1ebd6 299 Mat<double> jmotion_bicycle3_command(Mat<double> state, Mat<double> command, double dt)
Near32 24:3c0422e1ebd6 300 {
Near32 24:3c0422e1ebd6 301 double h = numeric_limits<double>::epsilon()*10e2;
Near32 24:3c0422e1ebd6 302 Mat<double> var( (double)0, command.getLine(), command.getColumn());
Near32 24:3c0422e1ebd6 303 var.set( h, 1,1);
Near32 24:3c0422e1ebd6 304 Mat<double> G(motion_bicycle3(state, command+var, dt) - motion_bicycle3(state, command-var,dt));
Near32 24:3c0422e1ebd6 305
Near32 24:3c0422e1ebd6 306 for(int i=2;i<=command.getLine();i++)
Near32 24:3c0422e1ebd6 307 {
Near32 24:3c0422e1ebd6 308 var.set( (double)0, i-1,1);
Near32 24:3c0422e1ebd6 309 var.set( h, i,1);
Near32 24:3c0422e1ebd6 310 G = operatorL(G, motion_bicycle3(state, command+var, dt) - motion_bicycle3(state, command-var,dt) );
Near32 24:3c0422e1ebd6 311 }
Near32 24:3c0422e1ebd6 312
Near32 24:3c0422e1ebd6 313
Near32 24:3c0422e1ebd6 314 return (1.0/(2*h))*G;
Near32 24:3c0422e1ebd6 315 }
Near32 24:3c0422e1ebd6 316
Near32 17:f360e21d3307 317 Mat<double> jsensor_bicycle3( Mat<double> state, Mat<double> command, Mat<double> d_state, double dt)
Near32 3:573a0dc8383f 318 {
Near32 3:573a0dc8383f 319 double h = numeric_limits<double>::epsilon()*10e2;
Near32 3:573a0dc8383f 320 Mat<double> var((double)0, state.getLine(), state.getColumn());
Near32 3:573a0dc8383f 321 var.set( h, 1,1);
Near32 24:3c0422e1ebd6 322 Mat<double> H(sensor_bicycle3(state+var, command, d_state, dt) - sensor_bicycle3(state-var, command, d_state, dt));
Near32 3:573a0dc8383f 323
Near32 3:573a0dc8383f 324 for(int i=2;i<=state.getLine();i++)
Near32 24:3c0422e1ebd6 325 {
Near32 3:573a0dc8383f 326 var.set( (double)0, i-1,1);
Near32 3:573a0dc8383f 327 var.set( h, i,1);
Near32 24:3c0422e1ebd6 328 H = operatorL(H, sensor_bicycle3(state+var, command, d_state, dt) - sensor_bicycle3(state-var, command, d_state, dt) );
Near32 3:573a0dc8383f 329 }
Near32 3:573a0dc8383f 330
Near32 3:573a0dc8383f 331
Near32 24:3c0422e1ebd6 332 return (1.0/(2*h))*H;
Near32 17:f360e21d3307 333 }
Near32 17:f360e21d3307 334
Near32 17:f360e21d3307 335 bool setPWM(PwmOut *servo,float p)
Near32 17:f360e21d3307 336 {
Near32 17:f360e21d3307 337 if(p <= 1.0f && p >= 0.0f)
Near32 17:f360e21d3307 338 {
Near32 17:f360e21d3307 339 servo->write(p);
Near32 17:f360e21d3307 340 return true;
Near32 17:f360e21d3307 341 }
Near32 17:f360e21d3307 342
Near32 17:f360e21d3307 343 return false;
Near32 3:573a0dc8383f 344 }