#ifndef _LINEAR_TRAJECTORY_H_ #define _LINEAR_TRAJECTORY_H_ #include "vec.h" #include "Trajectroy.h" #include "stdlib.h" template class LinearJointTrajectory : public Trajectory { public: LinearJointTrajectory( float sampleTimeMs, Vec maxJointVelocity, Vec maxJointAcceleration, Vec jointStart, Vec jointEnd ) { std::cout << "linear \n " ; float MStoSec = 1000.0f; // calculate maximum velocity and acceleration Vec maxJointLocalVelocity = maxJointVelocity * (sampleTimeMs / MStoSec); Vec maxJointLocalAcceleration = maxJointAcceleration * (sampleTimeMs / MStoSec); std::cout << "max : " << maxJointLocalVelocity << "\n"; // calculate delta movement Vec jointMovement = jointEnd - jointStart; Vec jointMovementAbs = jointMovement.abs(); // calculate sample count // calculate number of movement steps Vec minStepsPerJoint = jointMovementAbs.celldivide(maxJointLocalVelocity); std::cout << "minsteps : " << minStepsPerJoint << "\n"; std::cout << "steps : " << minStepsPerJoint.max() << "\n"; this->steps = ceil(minStepsPerJoint.max()); std::cout << "steps : " << this->steps << "\n"; if (this->steps == 0) this->steps +=1; 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); } private: protected: }; template class LinearCartTrajectory : public Trajectory { }; #endif