motion.cpp
Go to the documentation of this file.
1 
9 #include <math.h> // to get fabs() declaration
10 #include <model/motion.hpp>
11 
12 
13 // Descriptive method, giving the limit acceleration which ensure
14 // to avoid reaching limit distance for a given distance, velocity
15 // and leader velocity.
16 // Parameter lim_dist the limit (minimum) distance allowed,
17 // dist the current distance to the leader,
18 // vel the current velocity of the robot,
19 // ldr_vel the current velocity of the leader,
20 // time_step the time step of the motion.
21 double MotionModel::limAcc(const double& lim_dist, const double& dist,
22  const double& vel, const double& ldr_vel,
23  const double& time_step) const {
24  const double ts2 = time_step * time_step,
25  min_acc = limits[aMin], max_acc = limits[aMax],
26  delta_acc = (min_acc - max_acc),
27  // worst case evaluation of next time step values
28  next_dist = dist + (ldr_vel - vel) * time_step
29  + delta_acc * ts2 / 2,
30  next_ldr_vel = ldr_vel + min_acc * time_step,
31  next_vel = vel + max_acc * time_step,
32  next_vel_inc = next_vel - min_acc * time_step / 2,
33  next_vel_mod = next_vel_inc + max_acc * time_step,
34  next_crit = next_dist - lim_dist
35  + (next_vel * next_vel - next_ldr_vel * next_ldr_vel)
36  / (2 * min_acc),
37  // worst case evaluation of 2 time step later value
38  next_next_crit = std::max(0., next_crit - delta_acc
39  * (next_vel + max_acc * time_step / 2)
40  / min_acc - delta_acc * ts2);
41 
42  return std::min( min_acc + 2 * (next_dist - lim_dist
43  + (next_ldr_vel - next_vel)
44  * time_step) / (3 * ts2),
45  std::min( sqrt( next_vel_inc * next_vel_inc
46  - 2 * min_acc * next_crit
47  - next_vel_inc
48  + min_acc * time_step) / time_step,
49  ( sqrt( next_vel_mod * next_vel_mod
50  - 2 * min_acc * next_next_crit )
51  - next_vel) / time_step + delta_acc
52  + min_acc / 2 ) );
53 } // end of double MotionModel::limAcc(const double&, ...) -----------
54 
55 /* Modify translation and rotation given velocities, applying
56  * the extremal accelerations multiplied by the given factors
57  * during the given time step.
58  *
59  * A factor of the same sign than the velocity is multiplied
60  * by the maximum acceleration to improve the velocity
61  * in absolute value, while a factor whose sign is the opposite
62  * of the velocity's is multiplied by the maximum deceleration
63  * to reduce the velocity in absolute value.
64  * Extrema of the velocity are taken into account, as well as
65  * a possible change of sign of the velocity during the change
66  * (it changes the applied acceleration for the remaining time).
67  *
68  * Parameter trans_vel the translation velocity, to update,
69  * rot_vel the rotation velocity, to update,
70  * trans_fact the translation factor, multiplied by one
71  * of the translation acceleration extrema,
72  * rot_fact the rotation factor, multiplied by one
73  * of the rotation acceleration extrema,
74  * time_step the duration of the accelerations.
75  */
77 (double& trans_vel, double& rot_vel, const double& trans_fact,
78  const double& rot_fact, const double& time_step) const {
79  static const int nbVal = 2; // two velocities:
80  // similar computations, using a for(){} with arrays
81  static const double min_vel[nbVal] = {limits[vMin], -limits[omMax]},
82  max_vel[nbVal] = {limits[vMax], limits[omMax]},
83  acc[nbVal] = {limits[aMax], limits[gmMax]},
84  dec[nbVal] = {limits[aMin], limits[gmMin]};
85  const double fact[nbVal] = {trans_fact, rot_fact};
86  double *vel[nbVal] = {&trans_vel, &rot_vel};
87 
88  for(int id = 0; id < nbVal; id++) {
89  double delta_t = time_step;
90  do { // two passes may be needed (if deccelerating)
91  // is acceleration or deceleration applied?
92  const bool isAcc = (*vel[id] * fact[id] >= 0);
93  const double& delta_a
94  = fact[id] * ( isAcc ? acc[id] : fabs(dec[id]) );
95  *vel[id] += delta_a * delta_t;
96  delta_t = 0; // remaining time
97  if (isAcc) // acceleration: is max/min velocity respected?
98  if (fact[id] >= 0) {
99  if (*vel[id] > max_vel[id]) *vel[id] = max_vel[id];
100  } else {
101  if (*vel[id] < min_vel[id]) *vel[id] = min_vel[id];
102  }
103  else // deceleration: did velocity change of sign?
104  if (*vel[id] * fact[id] > 0) { // it did! Second pass needed!
105  *vel[id] -= delta_a * delta_t; // restore velocity
106  // remaining time after change of sign (vel[id] / acc < 0)
107  delta_t = time_step + *vel[id] / delta_a; // delta_t > 0
108  *vel[id] = 0;
109  } // end of if (Second pass needed, with the other acc!)
110  } while (delta_t > 0);
111  } // end of for (each velocity)
112 } // end of void MotionModel::applyAccelerationFactors(...) ----------
113 
114 /* Modify translation and rotation given velocities, applying
115  * the given accelerations during the given time step.
116  *
117  * Extrema of the velocity and of the acceleration are taken
118  * into account, as well as a possible change of sign of
119  * the velocity during the change (it changes the acceleration
120  * extrema for the remaining time).
121  *
122  * Parameter trans_vel the translation velocity, to update,
123  * rot_vel the rotation velocity, to update,
124  * trans_acc the translation acceleration,
125  * rot_acc the rotation acceleration,
126  * time_step the duration of the accelerations.
127  */
129 (double& trans_vel, double& rot_vel, const double& trans_acc,
130  const double& rot_acc, const double& time_step) const {
131  static const int nbVal = 2; // two velocities:
132  // similar computations, using a for(){} with arrays
133  static const double min_vel[nbVal] = {limits[vMin], -limits[omMax]},
134  max_vel[nbVal] = {limits[vMax], limits[omMax]},
135  max_acc[nbVal] = {limits[aMax], limits[gmMax]},
136  max_dec[nbVal] = {limits[aMin], limits[gmMin]};
137  const double acc[nbVal] = {trans_acc, rot_acc};
138  double *vel[nbVal] = {&trans_vel, &rot_vel};
139 
140  for(int id = 0; id < nbVal; id++) {
141  double delta_t = time_step;
142  do { // two passes may be needed (if decelerating)
143  // is acceleration or deceleration applied?
144  const bool isAcc = (*vel[id] * acc[id] >= 0);
145  const double
146  sgnAcc = (acc[id] < 0 ? -1 : 1), absAcc = sgnAcc * acc[id],
147  &delta_a = sgnAcc *
148  ( isAcc ? (absAcc > max_acc[id] ? max_acc[id] : absAcc)
149  : (absAcc > - max_dec[id] ? - max_dec[id] : absAcc) );
150  *vel[id] += delta_a * delta_t;
151  delta_t = 0; // remaining time
152  if (isAcc) // acceleration: is max/min velocity respected?
153  if (delta_a >= 0) {
154  if (*vel[id] > max_vel[id]) *vel[id] = max_vel[id];
155  } else {
156  if (*vel[id] < min_vel[id]) *vel[id] = min_vel[id];
157  }
158  else // deceleration: did velocity change of sign?
159  if (*vel[id] * sgnAcc > 0) { // it did! Second pass needed!
160  *vel[id] -= delta_a * delta_t; // restore velocity
161  // remaining time after change of sign (vel[id] / acc < 0)
162  delta_t = time_step + *vel[id] / delta_a; // delta_t > 0
163  *vel[id] = 0;
164  } // end of if (Second pass needed, with the other acc!)
165  } while (delta_t > 0);
166  } // end of for (each velocity)
167 } // end of void MotionModel::applyAccelerations(...) ----------------
double limits[nbLimits]
The array of limits.
Definition: motion.hpp:44
Index of the maximum translation deceleration.
Definition: motion.hpp:36
void applyAccelerationFactors(double &trans_vel, double &rot_vel, const double &trans_fact, const double &rot_fact, const double &time_step) const
Modify translation and rotation given velocities, applying the extremal accelerations multiplied by t...
Definition: motion.cpp:77
void applyAccelerations(double &trans_vel, double &rot_vel, const double &trans_acc, const double &rot_acc, const double &time_step) const
Modify translation and rotation given velocities, applying the given accelerations during the given t...
Definition: motion.cpp:129
Index of the minimum translation velocity.
Definition: motion.hpp:33
Index of the maximum rotation deceleration.
Definition: motion.hpp:38
Index of the maximum translation acceleration.
Definition: motion.hpp:37
Motion model for qt_ctrl.
Index of the maximum rotation acceleration.
Definition: motion.hpp:39
Index of the maximum rotation velocity.
Definition: motion.hpp:35
Index of the maximum translation velocity.
Definition: motion.hpp:34
double limAcc(const double &lim_dist, const double &dist, const double &vel, const double &ldr_vel, const double &time_step) const
Descriptive method, giving the limit acceleration which ensure to avoid reaching limit distance for a...
Definition: motion.cpp:21


qt_ctrl
Author(s): Alexis Scheuer
autogenerated on Wed Dec 16 2020 15:51:32