71 double p,
double v,
double lam,
double acon)
73 double lam2 = lam*lam;
79 a = - 2.0*lam*v - sqrt(8.0*acon*(+lam2*p-acon)) + acon;
81 dadp = - lam2 * sqrt(2.0*acon/(+lam2*p-acon));
83 else if (lam2*p > -3*acon)
86 a = - 2.0*lam*v - lam2*p;
93 a = - 2.0*lam*v + sqrt(8.0*acon*(-lam2*p-acon)) - acon;
95 dadp = - lam2 * sqrt(2.0*acon/(-lam2*p-acon));
125 double v,
double lam,
double )
158 double pos_act,
double vel_act,
double dt)
162 double mass = abs(
mass_);
163 double Kd = abs(
Kd_);
164 double Kp = abs(
Kp_);
165 double Ki = abs(
Ki_);
166 double Ficl = abs(
Ficl_);
180 double dt2 = dt * dt;
181 double dt3 = dt * dt * dt;
222 vnom = last_vel_pxy + dt/2 * (last_acc_pxy + 0.0 );
223 pnom = last_pos_pxy + dt/2 * (last_vel_pxy + vnom);
233 acc_pxy = (acc_des + anom) / (1.0 - dadv*dt/2 - dadp*dt2/4);
243 if (pmax - pmin > 0.0)
247 acc_hi = anom / (1.0 - dadv*dt/2 - dadp*dt2/4);
251 acc_lo = anom / (1.0 - dadv*dt/2 - dadp*dt2/4);
254 acc_pxy = std::min(std::max(acc_pxy, acc_lo), acc_hi);
267 acc_hi = anom / (1.0 - dadv*dt/2);
271 acc_lo = anom / (1.0 - dadv*dt/2);
274 acc_pxy = std::min(std::max(acc_pxy, acc_lo), acc_hi);
285 vel_pxy = last_vel_pxy + dt/2 * (last_acc_pxy + acc_pxy);
286 pos_pxy = last_pos_pxy + dt/2 * (last_vel_pxy + vel_pxy);
302 vel_err = vel_act - vel_pxy;
303 pos_err = pos_act - pos_pxy;
304 int_err = last_int_err + dt/2 * (last_pos_err + pos_err);
310 force = mass*acc_pxy - Kd*vel_err - Kp*pos_err - std::min(std::max(Ki*int_err, -Ficl), Ficl);
325 force = std::min(std::max(force, -Flim), Flim);
329 Fpd = mass*acc_pxy - Kd*vel_err - Kp*pos_err;
340 da = (force - Fpd - Fi) / (mass + Kd*dt/2 + Kp*dt2/4 + Ki*dt3/8);
347 if (Fi+da*Ki*dt3/8 > Ficl) da=(force-Fpd-Ficl)/(mass+Kd*dt/2+Kp*dt2/4);
348 else if (Fi+da*Ki*dt3/8 < -Ficl) da=(force-Fpd+Ficl)/(mass+Kd*dt/2+Kp*dt2/4);
353 vel_pxy += da * dt/2;
354 pos_pxy += da * dt2/4;
356 vel_err -= da * dt/2;
357 pos_err -= da * dt2/4;
358 int_err -= da * dt3/8;
369 dv = (force - Fpd - Fi) / (Kd + Kp*dt/2 + Ki*dt2/4);
376 if (Fi+dv*Ki*dt2/4 > Ficl) dv=(force-Fpd-Ficl)/(Kd+Kp*dt/2);
377 else if (Fi+dv*Ki*dt2/4 < -Ficl) dv=(force-Fpd+Ficl)/(Kd+Kp*dt/2);
382 pos_pxy += dv * dt/2;
385 pos_err -= dv * dt/2;
386 int_err -= dv * dt2/4;
398 dp = (force - Fpd - Fi) / (Kp + Ki*dt/2);
405 if (Fi+dp*Ki*dt/2 > Ficl) dp=(force-Fpd-Ficl)/(Kp);
406 else if (Fi+dp*Ki*dt/2 < -Ficl) dp=(force-Fpd+Ficl)/(Kp);
413 int_err -= dp * dt/2;
424 if (Ki * int_err > Ficl) int_err = Ficl / Ki;
425 else if (Ki * int_err < -Ficl) int_err = -Ficl / Ki;