diff --git a/lwrserv/include/BangBangTrajectroy.h b/lwrserv/include/BangBangTrajectroy.h index a6eb9b0..11083f7 100644 --- a/lwrserv/include/BangBangTrajectroy.h +++ b/lwrserv/include/BangBangTrajectroy.h @@ -8,10 +8,45 @@ class BangBangJointTrajectroy : public Trajectory { public: BangBangJointTrajectroy( - unsigned int steps_, - float totalTime_, - Vec jointMovement); + float sampleTimeMs, + Vec maxJointVelocity, + Vec maxJointAcceleration, + Vec jointStart, + Vec jointEnd + ) + { + float MStoSec = 1000.0f; + // calculate maximum velocity and acceleration + Vec maxJointLocalVelocity = maxJointVelocity * (sampleTimeMs / MStoSec); + Vec maxJointLocalAcceleration = maxJointAcceleration * (sampleTimeMs / MStoSec); + // calculate delta movement + Vec jointMovement = jointEnd - jointStart; + Vec jointMovementAbs = jointMovement.abs(); + + // calculate number of movement steps + Vec minStepsPerJoint = jointMovementAbs.celldivide(maxJointLocalVelocity); + this->steps = ceil(minStepsPerJoint.max()); + if (this->steps == 0) + this->steps +=1; + + std::cout << "steps : " << this->steps << minStepsPerJoint<< "\n"; + + this->nodes = (struct Trajectory::trajectoryNode* ) calloc(sizeof(struct Trajectory::trajectoryNode),this->steps); + + Vec jointLast = jointStart; + for( int i = 0 ; i < this->steps; ++i) + { + jointLast = jointLast + jointMovement.celldivide((float) this->steps ); + this->nodes[i].jointPos = jointLast; + this->nodes[i].velocity = maxJointLocalVelocity; + this->nodes[i].acceleration = Vec(0.0f); + } + // last step myth be to wide so cut it to the wanted position + this->nodes[this->steps-1].jointPos = jointEnd; + this->nodes[this->steps-1].velocity = maxJointLocalVelocity; // TODO this is not the truth + this->nodes[this->steps-1].acceleration = Vec(0.0f); + } ~BangBangJointTrajectroy(); private: diff --git a/lwrserv/include/LinearTrajectory.h b/lwrserv/include/LinearTrajectory.h index 5eef713..8acba6c 100644 --- a/lwrserv/include/LinearTrajectory.h +++ b/lwrserv/include/LinearTrajectory.h @@ -23,7 +23,6 @@ class LinearJointTrajectory : public Trajectory Vec maxJointLocalVelocity = maxJointVelocity * (sampleTimeMs / MStoSec); Vec maxJointLocalAcceleration = maxJointAcceleration * (sampleTimeMs / MStoSec); - std::cout << "maxv : " << maxJointLocalVelocity << "\n"; // calculate delta movement Vec jointMovement = jointEnd - jointStart; Vec jointMovementAbs = jointMovement.abs(); @@ -36,8 +35,6 @@ class LinearJointTrajectory : public Trajectory if (this->steps == 0) this->steps +=1; - std::cout << "steps : " << this->steps << minStepsPerJoint<< "\n"; - this->nodes = (struct Trajectory::trajectoryNode* ) calloc(sizeof(struct Trajectory::trajectoryNode),this->steps); Vec jointLast = jointStart;