Skip to content

Commit dbb1b9a

Browse files
author
Ruben Smits
committed
Merge pull request orocos#39 from rethink-forrest/master
Check that the maxvel is obtainable in a half trapezoidal velocity profile
2 parents a929f7d + b5ad5da commit dbb1b9a

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

orocos_kdl/src/path_composite.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ namespace KDL {
5353
// you propably want to use the cached_index variable
5454
double Path_Composite::Lookup(double s) const
5555
{
56-
assert(s>=0);
57-
assert(s<=pathlength);
56+
assert(s>=-1e-12);
57+
assert(s<=pathlength+1e-12);
5858
if ( (cached_starts <=s) && ( s <= cached_ends) ) {
5959
return s - cached_starts;
6060
}

orocos_kdl/src/velocityprofile_traphalf.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ void VelocityProfile_TrapHalf::PlanProfile1(double v,double a) {
5858
a3 = 0;
5959
a2 = 0;
6060
a1 = startpos;
61-
b3 = a/2;
61+
b3 = a/2.0;
6262
b2 = -a*t1;
63-
b1 = startpos + a*t1*t1/2;
63+
b1 = startpos + a*t1*t1/2.0;
6464
c3 = 0;
6565
c2 = v;
6666
c1 = endpos - v*duration;
@@ -70,9 +70,9 @@ void VelocityProfile_TrapHalf::PlanProfile2(double v,double a) {
7070
a3 = 0;
7171
a2 = v;
7272
a1 = startpos;
73-
b3 = -a/2;
73+
b3 = -a/2.0;
7474
b2 = a*t2;
75-
b1 = endpos - a*t2*t2/2;
75+
b1 = endpos - a*t2*t2/2.0;
7676
c3 = 0;
7777
c2 = 0;
7878
c1 = endpos;
@@ -82,15 +82,17 @@ void VelocityProfile_TrapHalf::SetProfile(double pos1,double pos2) {
8282
startpos = pos1;
8383
endpos = pos2;
8484
double s = sign(endpos-startpos);
85-
duration = s*(endpos-startpos)/maxvel+maxvel/maxacc/2.0;
85+
// check that the maxvel is obtainable
86+
double vel = std::min(maxvel, sqrt(2.0*s*(endpos-startpos)*maxacc));
87+
duration = s*(endpos-startpos)/vel+vel/maxacc/2.0;
8688
if (starting) {
8789
t1 = 0;
88-
t2 = maxvel/maxacc;
89-
PlanProfile1(maxvel*s,maxacc*s);
90+
t2 = vel/maxacc;
91+
PlanProfile1(vel*s,maxacc*s);
9092
} else {
91-
t1 = duration-maxvel/maxacc;
93+
t1 = duration-vel/maxacc;
9294
t2 = duration;
93-
PlanProfile2(s*maxvel,s*maxacc);
95+
PlanProfile2(s*vel,s*maxacc);
9496
}
9597
}
9698

orocos_kdl/src/velocityprofile_traphalf.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,16 @@ class VelocityProfile_TrapHalf : public VelocityProfile
8989
*/
9090
VelocityProfile_TrapHalf(double _maxvel=0,double _maxacc=0,bool _starting=true);
9191

92-
void SetMax(double _maxvel,double _maxacc, bool _starting );
92+
void SetMax(double _maxvel,double _maxacc,bool _starting);
9393

9494
/**
95+
* Plans a 'Half' Trapezoidal VelocityProfile between pos1 and pos2.
96+
* If the distance is too short betweeen pos1 and pos2,
97+
* only the acceleration phase is set and the max velocity is not reached.
98+
*
99+
* \param pos1 Starting position
100+
* \param pos2 Ending position
101+
*
95102
* Can throw a Error_MotionPlanning_Not_Feasible
96103
*/
97104
virtual void SetProfile(double pos1,double pos2);

0 commit comments

Comments
 (0)