smoothPath.cpp
Go to the documentation of this file.
1 
10 #include <ctrl/smoothPath.hpp>
11 #include <iSeeML/rob/ArrayPaths.hpp>
12 
13 // Cf ReachingCtrl::setGoal(const State&)
14 void SmoothPathCtrl::setGoal(const State& goal) {
15  // motion model cannot change => static const data
16  static const double&
17  max_trans_vel = motion_model.maxTranslVel(),
18  norm_dist = max_trans_vel * max_trans_vel / 2,
19  acc_dist = norm_dist / motion_model.maxTranslAcc(),
20  dec_dist = - norm_dist / motion_model.minTranslAcc(),
21  max_curv = motion_model.maxRotVel() / max_trans_vel,
22  max_rot_acc = std::min( motion_model.maxRotAcc(),
24  max_curv_deriv = max_rot_acc / max_trans_vel;
25 
27  const iSeeML::rob::OrPtConfig start = state.configuration()
28  + iSeeML::rob::OrPtConfig(acc_dist, 0, 0),
29  end = getGoal().configuration()
30  + iSeeML::rob::OrPtConfig(- dec_dist, 0, 0);
31  path = iSeeML::rob::FscPath(start, end, max_curv, max_curv_deriv);
32  total_distance = acc_dist + path.length() + dec_dist;
33  distance = 0;
34  pathChanged(); // signal the path changed
35 } // end of SmoothPathCtrl::setGoal(const State&) --------------------
36 
37 // Get the path to the aimed oriented point.
38 // Return The path to the aimed oriented point.
39 const iSeeML::rob::Path& SmoothPathCtrl::getPath() const {
40  // motion model cannot change => static const data
41  static const double&
42  max_trans_vel = motion_model.maxTranslVel(),
43  norm_dist = max_trans_vel * max_trans_vel / 2,
44  acc_dist = norm_dist / motion_model.maxTranslAcc(),
45  dec_dist = - norm_dist / motion_model.minTranslAcc();
46  // the path is made of three paths
47  static iSeeML::rob::ArrayPaths globalPath(3);
48  // first one is a segment
49  const iSeeML::rob::OrPtConfig start = path.start() +
50  iSeeML::rob::OrPtConfig(- acc_dist, 0, 0);
51  globalPath.setPath( 0, true, new iSeeML::rob::LinCurvPath
52  ( iSeeML::rob::CurvConfig(start, 0),
53  0, acc_dist ) );
54  // second one is the saved path
55  globalPath.setPath( 1, false, (iSeeML::rob::Path*)( &path.clone() ) );
56  // third one is another segment
57  globalPath.setPath( 2, true, new iSeeML::rob::LinCurvPath
58  ( iSeeML::rob::CurvConfig(path.end(), 0),
59  0, dec_dist ) );
60 } // end of const iSeeML::rob::Path& SmoothPathCtrl::getPath() const -
61 
64 const std::list<State*>& SmoothPathCtrl::getAimedTrajectory() const {
65  // motion model cannot change => static const data
66  static const double&
67  max_trans_acc = motion_model.maxTranslAcc(),
68  max_trans_dec = motion_model.minTranslAcc(),
69  max_trans_vel = motion_model.maxTranslVel(),
70  norm_dist = max_trans_vel * max_trans_vel / 2,
71  acc_dist = norm_dist / max_trans_acc,
72  dec_dist = - norm_dist / max_trans_dec;
73  const double l = path.length(), dt2 = time_step / 2;
74  double t = 0, v = 0, om = 0, d = - acc_dist, tmp;
75  // this static variable remains defined until the end
76  static std::list<State*> traject;
77  // empty the list, to recompute it
78  while (! traject.empty() ) {
79  free( traject.front() );
80  traject.pop_front();
81  } // recompute the list
82  tmp = max_trans_acc * time_step;
83  while (d < 0) { // handle the first linear part
84  iSeeML::rob::OrPtConfig q = path.start() +
85  iSeeML::rob::OrPtConfig(d, 0, 0);
86  traject.push_back( new State(t, q, v, 0) );
87  // prepare the next one
88  t += time_step;
89  d += v * time_step + tmp * dt2;
90  v += tmp;
91  } // distance and velocity need correction
92  d -= (v - max_trans_vel) * dt2;
93  v = max_trans_vel;
94  tmp = v * time_step;
95  while (d < l) { // add the current state
96  iSeeML::rob::CurvConfig q = path[d];
97  traject.push_back( new State(t, q, v, q.curvature() * v) );
98  // prepare the next one
99  t += time_step;
100  d += tmp;
101  } // distance and velocity need correction
102  d -= l;
103  tmp = sqrt(-2 * d * max_trans_dec);
104  v -= tmp;
105  d -= tmp * dt2;
106  tmp = max_trans_dec * time_step;
107  while (v > 0) { // handle the last linear part
108  iSeeML::rob::OrPtConfig q = path.end() +
109  iSeeML::rob::OrPtConfig(d, 0, 0);
110  traject.push_back( new State(t, q, v, 0) );
111  // prepare the next one
112  t += time_step;
113  d += v * time_step + tmp * dt2;
114  v += tmp;
115  }
116  iSeeML::rob::OrPtConfig q = path.end() +
117  iSeeML::rob::OrPtConfig(dec_dist, 0, 0);
118  traject.push_back( new State(t, q, 0, 0) );
119  return traject;
120 } // end of const SmoothPathCtrl::getAimedTrajectory() const
121 
122 // Cf Controller::choose_velocities(double&, double&, ...)
123 void SmoothPathCtrl::chooseVelocities(double& trans_vel,
124  double& rot_vel,
125  std::ostream& log_str) {
126  static const double&
127  max_trans_acc = motion_model.maxTranslAcc(),
128  max_trans_dec = motion_model.minTranslAcc(),
129  max_trans_vel = motion_model.maxTranslVel(),
130  norm_dist = max_trans_vel * max_trans_vel / 2,
131  acc_dist = norm_dist / max_trans_acc,
132  dec_dist = - norm_dist / max_trans_dec,
133  max_rot_acc = motion_model.maxRotAcc(),
134  max_rot_dec = motion_model.minRotAcc(),
135  max_rot_vel = motion_model.maxRotVel();
136  static State last_state = state;
137  trans_vel = state.translationVelocity(); // current velocity
138  // update the covered distance
139  distance += ( trans_vel + last_state.translationVelocity() )
140  * ( state.date() - last_state.date() ) / 2;
141  /* ### 1st solution: compute the desired velocities; NOT GOOD ######
142  // === compute desired translation velocity ========================
143  // choose between accelerate, remain or brake
144  moving_velocity // desired velocity is the min between accelerate,
145  = std::min( std::min( trans_vel + max_trans_acc * time_step,
146  max_trans_vel), // maximum velocity and
147  // decelerate to stop at total distance
148  sqrt(2 * (distance - total_distance) * max_trans_dec)
149  );
150  // === compute desired rotation velocity ===========================
151  if ( (distance <= acc_dist)
152  || (distance >= total_distance - dec_dist) )
153  rot_vel = 0; // straight motion while accelerating or braking
154  else { // rotation velocity depends on the path
155  rot_vel = state.translationVelocity(); // current velocity
156  const double defl = // desired change of orientation
157  state.configuration().projection(path[distance - acc_dist])
158  .orientation();
159  // desired velocity should allow to reach deflection (line 1),
160  // remaining higher than reachable minimum velocity (l. 1 & 2)
161  // and smaller than reachable maximum velocity (l. 3 & 4)
162  turning_velocity
163  = std::min( std::max( std::max(defl / time_step, - max_rot_vel),
164  rot_vel + max_rot_dec * time_step),
165  std::min( max_rot_vel,
166  rot_vel + max_rot_acc * time_step) );
167  }
168  ### 2nd solution: compute the desired accelerations; better? #### */
169  if (distance <= acc_dist) // first part
171  max_trans_acc, 0, time_step);
172  else if (distance >= total_distance) // stop
173  stopMotion();
174  else if (distance >= total_distance - dec_dist) // last part
176  max_trans_dec, 0, time_step);
177  else { // path part
178  /* 3rd solution: get directly from path with anticipation
179  const double defl = // desired change of orientation
180  state.configuration().projection(path[distance - acc_dist])
181  .orientation(), // forgot next line in 1st solution
182  rot_acc = defl / time_step - state.translationVelocity();
183  motion_model.applyAccelerations(moving_velocity, turning_velocity,
184  0, rot_acc, time_step); */
185  const double lookahead = time_step * max_trans_vel,
186  arc_length = distance - acc_dist + lookahead;
187  // path's length is a little bit too much (seg. fault): - 10⁻⁶
188  double length = path.length() - 1E-6, s = arc_length > length
189  ? length : arc_length, curv = path[s].curvature();
190  // -=# recompute the path to improve it #=-
191  if (fabs(curv) < path.maxCurv() * 1E-3) // very small curvature
192  /* next constraint not strong enough!!!
193  && (arc_length < length * 2 / 3) ) { // and not too far
194  // recompute from here
195  path.connect( state.configuration(), path.end() );*/ {
196  iSeeML::rob::FscPath
197  new_path( state.configuration(), path.end(),
198  path.maxCurv(), path.maxCurvDeriv() );
199  // not much longer than what remains along older path
200  if (new_path.length() < 1.2 * (length - distance + acc_dist) ) {
201  path = new_path; // no long loop => copy
202  // change the considered distance (beginning of the path)
203  distance = acc_dist; // and the computed values
204  length = path.length() - 1E-6;
205  total_distance = acc_dist + length + dec_dist;
206  s = lookahead > length ? length : lookahead;
207  curv = path[s].curvature();
208  } } // -=# NOW WORKs: remains closer without loops #=-
209  moving_velocity = max_trans_vel;
210  turning_velocity = max_trans_vel * curv;
211  } /*
212  // === log for debug ===============================================
213  log_str << "Vel. @d = " << distance << " [" << acc_dist
214  << "|" << total_distance - dec_dist << "|" << total_distance
215  << "]: " << moving_velocity << ", " << turning_velocity; */
216  // === updates the parameters and send the update signal ===========
217  updateVelocities(trans_vel, rot_vel);
218  // === updates the last state variable =============================
219  last_state = state;
220 } // end of SmoothPathCtrl::chooseVelocities(double&, double&, ...)
const iSeeML::rob::Path & getPath() const
Get the path to the aimed oriented point.
Definition: smoothPath.cpp:39
void setGoal(const State &goal)
Set the state which is aimed.
Definition: smoothPath.cpp:14
void stopMotion()
Stops the robot (i.e. sets both velocities to zero).
Definition: controller.hpp:99
Oriented point reaching controller class using a smooth path generator.
const std::list< State * > & getAimedTrajectory() const
Transform the planned path into an aimed trajectory.
Definition: smoothPath.cpp:64
const double & maxTranslAcc() const
Descriptive method, giving the maximum translation acceleration.
Definition: motion.hpp:105
const State & getGoal() const
Get the state which is aimed.
Definition: reach.hpp:62
const double & maxRotVel() const
Descriptive method, giving the maximum rotation velocity.
Definition: motion.hpp:96
const double time_step
The time step of the controller.
Definition: controller.hpp:39
const iSeeML::rob::OrPtConfig & configuration() const
Gives the configuration of the state.
Definition: state.hpp:67
virtual void setGoal(const State &new_goal)
Set the state which is aimed.
Definition: reach.hpp:44
const double & minRotAcc() const
Descriptive method, giving the minimum rotation acceleration (or maximum rotation deceleration)...
Definition: motion.hpp:110
double distance
The distance already covered.
Definition: smoothPath.hpp:31
double moving_velocity
Translation velocity desired for the robot.
Definition: controller.hpp:45
State state
The state of the robot.
Definition: reach.hpp:31
const double & minTranslAcc() const
Descriptive method, giving the minimum translation acceleration (or maximum translation deceleration)...
Definition: motion.hpp:101
void updateVelocities(double &trans_vel, double &rot_vel)
Update the velocities from the fields and send the update signal.
Definition: controller.hpp:66
iSeeML::rob::FscPath path
The computed smooth path.
Definition: smoothPath.hpp:29
const MotionModel & motion_model
The model of the motion.
Definition: controller.hpp:36
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
const double & translationVelocity() const
Gives the translation velocity of the state.
Definition: state.hpp:74
void pathChanged()
Update the display of the path.
const double & date() const
Gives the configuration of the state.
Definition: state.hpp:61
This class defines a state, i.e. a configuration and its (translation and rotation) velocities...
Definition: state.hpp:22
const double & maxTranslVel() const
Descriptive method, giving the maximum translation velocity.
Definition: motion.hpp:92
double turning_velocity
Rotation velocity desired for the robot.
Definition: controller.hpp:47
void chooseVelocities(double &trans_vel, double &rot_vel, std::ostream &)
Computes new velocities for ROS node.
Definition: smoothPath.cpp:123
double total_distance
The distance to cover.
Definition: smoothPath.hpp:30
const double & maxRotAcc() const
Descriptive method, giving the maximum rotation acceleration.
Definition: motion.hpp:114


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