|
|
@ -16,7 +16,6 @@ public: |
|
|
|
Vec<float,SIZE> jointEnd |
|
|
|
) |
|
|
|
{ |
|
|
|
std::cout << "bang bang \n " ; |
|
|
|
float MStoSec = 1000.0f; |
|
|
|
float sampleTime = sampleTimeMs / MStoSec; |
|
|
|
// calculate maximum velocity and acceleration |
|
|
@ -35,19 +34,57 @@ public: |
|
|
|
// one joint has to reach maxvelocity the others are stepped down to |
|
|
|
// calculate time if acceleration is enouth to reach max speed |
|
|
|
Vec<float,SIZE> maxVeloReachable = (jointMovementAbs.celldivide(maxJointAcceleration)*2.0f).sqrt().cellmultiply(maxJointVelocity); |
|
|
|
|
|
|
|
maxJointLocalVelocity = (maxVeloReachable/sampleTime).cellmax(maxJointLocalVelocity); |
|
|
|
|
|
|
|
Vec<float,SIZE> accelerationPhaseTime = maxJointVelocity.celldivide(maxJointAcceleration)/sampleTime; |
|
|
|
Vec<float,SIZE> jointMovementRemaining = jointMovementAbs - maxJointVelocity.cellmultiply(maxJointVelocity).celldivide(maxJointAcceleration); |
|
|
|
Vec<float,SIZE> maxVelocityPhaseThime = jointMovementRemaining.celldivide(maxJointLocalVelocity); |
|
|
|
|
|
|
|
|
|
|
|
// v ^ |
|
|
|
// | |
|
|
|
// v_bang| /\ <- bang bang trajectory |
|
|
|
// | / \ |
|
|
|
// v_lspb| _____\___ <- lspb trajectory |
|
|
|
// | / . . |
|
|
|
// | / . . \ |
|
|
|
// | / . . \ |
|
|
|
// |/________.__.___\____> t |
|
|
|
// | t1| t2 | t3| |
|
|
|
// |tx| |
|
|
|
// |
|
|
|
// t1/t3 = acceleration phase |
|
|
|
// t2 = constant speed phase |
|
|
|
// |
|
|
|
// t = t1 + t2 +t3 |
|
|
|
// |
|
|
|
// v_lspb = percent * v_bang |
|
|
|
// |
|
|
|
// t = t_bang + t_x |
|
|
|
// t = t_bang + (v_bang - v_lspb)/a * 2 |
|
|
|
// |
|
|
|
// t = t_bang + (t_bang/2 * a - percent *t_bang/2*a) / a *2 |
|
|
|
// t = t_bang + (1- percent) * (t_bang/2 * a) / a *2 |
|
|
|
// t = t_bang + (1- percent) * t_bang |
|
|
|
// t = (2-percent) * t_bang |
|
|
|
|
|
|
|
Vec<float,SIZE> minStepsPerJoint = accelerationPhaseTime * 2.0f + maxVelocityPhaseThime; |
|
|
|
std::cout << minStepsPerJoint << "minStepsPerJoint \n"; |
|
|
|
std::cout << accelerationPhaseTime << "a time \n"; |
|
|
|
std::cout << jointMovementRemaining << "reimain movement\n"; |
|
|
|
std::cout << maxVelocityPhaseThime << "max time \n"; |
|
|
|
minStepsPerJoint = minStepsPerJoint.ceil(); |
|
|
|
// calculate time for bang bang |
|
|
|
Vec<float,SIZE> accelerationPhaseTime = maxJointVelocity.celldivide(maxJointAcceleration)/sampleTime; |
|
|
|
Vec<float,SIZE> timeMaxAcceleration = ((jointMovementAbs/2.0f).celldivide(maxJointAcceleration) * 2.0f).sqrt() * 2.0f / sampleTime; |
|
|
|
Vec<float,SIZE> timeMaxVelocity = ((jointMovementAbs/2.0f).celldivide(maxJointVelocity) * 2.0f)*2.0f / sampleTime; |
|
|
|
Vec<float,SIZE> timeBangBang = timeMaxAcceleration.cellmax(timeMaxVelocity); |
|
|
|
|
|
|
|
std::cout << timeBangBang << "timeBangBang\n"; |
|
|
|
float steps_bangbang = timeBangBang.ceil().max(); |
|
|
|
|
|
|
|
// calculate maxAcceleration for bangbang |
|
|
|
Vec<float,SIZE> currMaxAcceleration = (jointMovementAbs * 2.0f ).celldivide(steps_bangbang).celldivide(steps_bangbang)*2.0f; |
|
|
|
std::cout << "currMaxAcceleration : " << currMaxAcceleration << "\n"; |
|
|
|
|
|
|
|
float percentLSPB = 0.7f; |
|
|
|
Vec<float,SIZE> timeLSPB = timeBangBang * (1 + 0.25f * (1.0f - percentLSPB)); |
|
|
|
float timeBlend = ((timeBangBang /2.0f) * percentLSPB).ceil().max(); |
|
|
|
std::cout << timeBlend << "timeBlend \n"; |
|
|
|
|
|
|
|
std::cout << timeLSPB << "max time \n"; |
|
|
|
Vec<float,SIZE> minStepsPerJoint = timeLSPB.ceil(); |
|
|
|
|
|
|
|
this->steps = minStepsPerJoint.max(); |
|
|
|
if (this->steps == 0) |
|
|
@ -58,32 +95,25 @@ public: |
|
|
|
Vec<float,SIZE> jointLast = jointStart; |
|
|
|
Vec<float,SIZE> velocityLast(0.0f); |
|
|
|
|
|
|
|
// percentage of max velocity |
|
|
|
//Vec<float,SIZE> currJointMovementOfMax = minStepsPerJoint / minStepsPerJoint.max() ; |
|
|
|
// s = a* t^2 / 2 => a = s* 2 / t^2 |
|
|
|
Vec<float,SIZE> currMaxAcceleration = (maxJointLocalAcceleration).cellmultiply(minStepsPerJoint) / minStepsPerJoint.max(); |
|
|
|
Vec<float,SIZE> currMaxVelocity = (maxJointLocalVelocity ).cellmultiply(minStepsPerJoint) / minStepsPerJoint.max(); |
|
|
|
std::cout << "max velo curr : " << currMaxVelocity << "\n"; |
|
|
|
|
|
|
|
int count = 0; |
|
|
|
for( int i = 0 ; i < this->steps; ++i) |
|
|
|
{ |
|
|
|
for (int joint = 0 ; joint < SIZE; ++joint) |
|
|
|
if (i < timeBlend) |
|
|
|
{ |
|
|
|
count += 1; |
|
|
|
this->nodes[i].acceleration = currMaxAcceleration; |
|
|
|
}else if (i < this->steps - timeBlend ) |
|
|
|
{ |
|
|
|
this->nodes[i].acceleration = Vec<float,SIZE>(0.0f); |
|
|
|
}else |
|
|
|
{ |
|
|
|
if (i < accelerationPhaseTime(i)) |
|
|
|
{ |
|
|
|
this->nodes[i].acceleration(i) = currMaxAcceleration(i); |
|
|
|
}else if (i < accelerationPhaseTime(i) + jointMovementRemaining(i)) |
|
|
|
{ |
|
|
|
this->nodes[i].acceleration(i) = 0.0f; |
|
|
|
}else |
|
|
|
{ |
|
|
|
this->nodes[i].acceleration(i) = currMaxAcceleration(i)* -1.0f; |
|
|
|
} |
|
|
|
this->nodes[i].velocity(i) = velocityLast(i) + jointMovementSgn(i) * currMaxAcceleration(i); |
|
|
|
count -= 1; |
|
|
|
this->nodes[i].acceleration = currMaxAcceleration* -1.0f; |
|
|
|
} |
|
|
|
this->nodes[i].velocity = jointMovementSgn.cellmultiply(currMaxAcceleration) * count; |
|
|
|
this->nodes[i].jointPos = jointLast + this->nodes[i].velocity; |
|
|
|
|
|
|
|
//std::cout << i << this->nodes[i].velocity << this->nodes[i].jointPos <<"\n"; |
|
|
|
jointLast = this->nodes[i].jointPos; |
|
|
|
velocityLast = this->nodes[i].velocity; |
|
|
|
} |
|
|
|