1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
/***************************************************************************
tag: Erwin Aertbelien Mon May 10 19:10:36 CEST 2004 velocityprofile_traphalf.cxx
velocityprofile_traphalf.cxx - description
-------------------
begin : Mon May 10 2004
copyright : (C) 2004 Erwin Aertbelien
email : erwin.aertbelien@mech.kuleuven.ac.be
***************************************************************************
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307 USA *
* *
***************************************************************************/
/*****************************************************************************
* \author
* Erwin Aertbelien, Div. PMA, Dep. of Mech. Eng., K.U.Leuven
*
* \version
* ORO_Geometry V0.2
*
* \par History
* - $log$
*
* \par Release
* $Id: velocityprofile_traphalf.cpp,v 1.1.1.1.2.5 2003/07/24 13:26:15 psoetens Exp $
* $Name: $
****************************************************************************/
//#include "error.h"
#include "velocityprofile_traphalf.hpp"
namespace KDL {
VelocityProfile_TrapHalf::VelocityProfile_TrapHalf(double _maxvel,double _maxacc,bool _starting):
maxvel(_maxvel),maxacc(_maxacc),starting(_starting) {}
void VelocityProfile_TrapHalf::SetMax(double _maxvel,double _maxacc, bool _starting)
{
maxvel = _maxvel; maxacc = _maxacc; starting = _starting;
}
void VelocityProfile_TrapHalf::PlanProfile1(double v,double a) {
a3 = 0;
a2 = 0;
a1 = startpos;
b3 = a/2;
b2 = -a*t1;
b1 = startpos + a2*t1*t1/2;
c3 = 0;
c2 = v;
c1 = endpos - v*duration;
}
void VelocityProfile_TrapHalf::PlanProfile2(double v,double a) {
a3 = 0;
a2 = v;
a1 = startpos;
b3 = -a/2;
b2 = a*t2;
b1 = endpos - a*t2*t2/2;
c3 = 0;
c2 = 0;
c1 = endpos;
}
void VelocityProfile_TrapHalf::SetProfile(double pos1,double pos2) {
startpos = pos1;
endpos = pos2;
double s = sign(endpos-startpos);
duration = s*(endpos-startpos)/maxvel+maxvel/maxacc/2.0;
if (starting) {
t1 = 0;
t2 = maxvel/maxacc;
PlanProfile1(maxvel*s,maxacc*s);
} else {
t1 = duration-maxvel/maxacc;
t2 = duration;
PlanProfile2(s*maxvel,s*maxacc);
}
}
void VelocityProfile_TrapHalf::SetProfileDuration(
double pos1,double pos2,double newduration)
{
SetProfile(pos1,pos2);
double factor = duration/newduration;
if ( factor > 1 )
return;
double s = sign(endpos-startpos);
double tmp = 2.0*s*(endpos-startpos)/maxvel;
double v = s*maxvel;
duration = newduration;
if (starting) {
if (tmp > duration) {
t1 = 0;
double a = v*v/2.0/(v*duration-(endpos-startpos));
t2 = v/a;
PlanProfile1(v,a);
} else {
t2 = duration;
double a = v*v/2.0/(endpos-startpos);
t1 = t2-v/a;
PlanProfile1(v,a);
}
} else {
if (tmp > duration) {
t2 = duration;
double a = v*v/2.0/(v*duration-(endpos-startpos));
t1 = t2-v/a;
PlanProfile2(v,a);
} else {
double a = v*v/2.0/(endpos-startpos);
t1 = 0;
t2 = v/a;
PlanProfile2(v,a);
}
}
}
double VelocityProfile_TrapHalf::Duration() const {
return duration;
}
double VelocityProfile_TrapHalf::Pos(double time) const {
if (time < 0) {
return startpos;
} else if (time<t1) {
return a1+time*(a2+a3*time);
} else if (time<t2) {
return b1+time*(b2+b3*time);
} else if (time<=duration) {
return c1+time*(c2+c3*time);
} else {
return endpos;
}
}
double VelocityProfile_TrapHalf::Vel(double time) const {
if (time < 0) {
return 0;
} else if (time<t1) {
return a2+2*a3*time;
} else if (time<t2) {
return b2+2*b3*time;
} else if (time<=duration) {
return c2+2*c3*time;
} else {
return 0;
}
}
double VelocityProfile_TrapHalf::Acc(double time) const {
if (time < 0) {
return 0;
} else if (time<t1) {
return 2*a3;
} else if (time<t2) {
return 2*b3;
} else if (time<=duration) {
return 2*c3;
} else {
return 0;
}
}
VelocityProfile* VelocityProfile_TrapHalf::Clone() const {
VelocityProfile_TrapHalf* res = new VelocityProfile_TrapHalf(maxvel,maxacc, starting);
res->SetProfileDuration( this->startpos, this->endpos, this->duration );
return res;
}
VelocityProfile_TrapHalf::~VelocityProfile_TrapHalf() {}
void VelocityProfile_TrapHalf::Write(std::ostream& os) const {
os << "TRAPEZOIDALHALF[" << maxvel << "," << maxacc << "," << starting << "]";
}
}
|