diff --git a/lwrserv/BangBangTrajectroy.cpp b/lwrserv/BangBangTrajectroy.cpp new file mode 100644 index 0000000..461a71a --- /dev/null +++ b/lwrserv/BangBangTrajectroy.cpp @@ -0,0 +1,32 @@ +#include +#include +#include "Trajectroy.h" +#include "BangBangTrajectroy.h" +#include "vec.h" +#include "SvrData.h" + +template +BangBangJointTrajectroy::BangBangJointTrajectroy( + unsigned int steps_, + float totalTime_, + Vec jointMovement, + Vec maxJointRange, + Vec maxJointVelocityPerStep, + Vec maxJointAccelarationPerStep + ) +{ + super(steps_, totalTime_, jointMovement, maxJointVelocityPerStep, maxJointAccelarationPerStep); + + //unused + (void) maxJointRange; + Vec currentInk(0.0f); + Vec currentInkLast(0.0f); + Vec currentDist(0.0f); + Vec currentDistLast(0.0f); + for (unsigned int currStep = 0 ; currStep < steps ; ++currStep) + { + for (unsigned int currJoint = 0 ; currJoint < joints ; currJoint++) + { + } + } +} diff --git a/lwrserv/LinearTrajectory.cpp b/lwrserv/LinearTrajectory.cpp new file mode 100644 index 0000000..ecaa926 --- /dev/null +++ b/lwrserv/LinearTrajectory.cpp @@ -0,0 +1,80 @@ +#include "LinearTrajectory.h" +#include "vec.h" +#include "stdlib.h" + +template +LinearJointTrajectory::LinearJointTrajectory( + unsigned int steps_, + float totalTime_, + Vec jointMovement, + Vec maxJointVelocityPerStep, + Vec maxJointAccelarationPerStep + ) +{ + Vec< float, SIZE> velocity = jointMovement / steps * 1.5f; + LinearJointTrajectory( + steps_, + totalTime_, + jointMovement, + maxJointVelocityPerStep, + maxJointAccelarationPerStep, + velocity); +} + +template +LinearJointTrajectory::LinearJointTrajectory( + unsigned int steps_, + float totalTime_, + Vec jointMovement, + Vec maxJointVelocityPerStep, + Vec maxJointAccelarationPerStep, + Vec velocity + ) +{ + super(steps_, totalTime_, jointMovement, maxJointVelocityPerStep, maxJointAccelarationPerStep); + + if ( velocity > jointMovement/totalTime) + { + std::cerr << "velocity is to small for Trajectory\n"; + } + + if ( velocity < (2.0f*jointMovement)/totalTime) + { + std::cerr << "velocity is to big for Trajectory\n"; + } + + for (unsigned int currJoint = 0 ; currJoint < joints ; currJoint++) + { + unsigned int timeBlend = (jointMovement(currJoint) + velocity(currJoint)*totalTime)/ velocity(currJoint); + float acceleration = velocity(currJoint) / timeBlend; + + for (unsigned int currStep = 0 ; currStep < steps ; ++currStep) + { + float currentTime = currStep * totalTime / steps; + if (currentTime <= timeBlend) + { + // speed up till blend time is reached + nodes[currStep].jointPos = acceleration/2.0f * currentTime * currentTime; + nodes[currStep].velocity = acceleration * currentTime; + nodes[currStep].acceleration = acceleration; + } else + if ( currentTime <= totalTime - timeBlend) + { + // constant velocity + nodes[currStep].jointPos = (jointMovement(currJoint) - velocity(currJoint) * totalTime)/2.0f + velocity(currJoint) * currentTime; + nodes[currStep].velocity = velocity(currJoint); + nodes[currStep].acceleration = 0.0f; + } + else + { + // slow down untill aim is reached + // speed up till blend time is reached + nodes[currStep].jointPos = jointMovement(currJoint) - acceleration/2*totalTime*totalTime + acceleration * totalTime * currentTime - acceleration/2.0f * currentTime *currentTime; + nodes[currStep].velocity = acceleration*timeBlend - acceleration * currentTime ; + nodes[currStep].acceleration = -acceleration; + } + // calculate carthesian positions + nodes[currStep].cartPos = 0; + } + } +} diff --git a/lwrserv/SvrData.cpp b/lwrserv/SvrData.cpp index 8dbd30c..aa45ea9 100644 --- a/lwrserv/SvrData.cpp +++ b/lwrserv/SvrData.cpp @@ -290,7 +290,7 @@ Vec SvrData::getMaxRange() pthread_mutex_lock(&dataLock); retval = robot.max.range; pthread_mutex_unlock(&dataLock); - return 0; + return retval; } int SvrData::setRobotVelocity(float newVelocity) diff --git a/lwrserv/Trajectroy.cpp b/lwrserv/Trajectroy.cpp index b89a5f6..9ae99e5 100644 --- a/lwrserv/Trajectroy.cpp +++ b/lwrserv/Trajectroy.cpp @@ -1 +1,29 @@ +#include #include "Trajectroy.h" +#include "vec.h" + +template +Trajectory::Trajectory( + unsigned int steps_, + float totalTime_, + Vec jointMovement, + Vec maxJointVelocityPerStep, + Vec maxJointAccelarationPerStep + ) +{ + steps = steps_; + joints = SIZE; + totalTime = totalTime_; + + nodes = (struct Trajectory::trajectoryNode* ) malloc(sizeof(struct Trajectory::trajectoryNode)*steps_); + + // unused + (void) jointMovement; + (void) maxJointVelocityPerStep; + (void) maxJointAccelarationPerStep; +} + +Trajectory::~Trajectory() +{ + free(nodes); +} diff --git a/lwrserv/include/BangBangTrajectroy.h b/lwrserv/include/BangBangTrajectroy.h index 04bb040..079d720 100644 --- a/lwrserv/include/BangBangTrajectroy.h +++ b/lwrserv/include/BangBangTrajectroy.h @@ -1,14 +1,21 @@ #ifndef _BANGBANGTRAJCETORY_H_ #define _BANGBANGTRAJCETORY_H_ #include "Trajectroy.h" +#include "vec.h" class Trajectory; class BangBangJointTrajectroy : public Trajectory { public: - BangBangJointTrajectroy(); - BangBangJointTrajectroy(unsigned int steps); - BangBangJointTrajectroy(unsigned int steps, unsigned int joints); + template + BangBangJointTrajectroy( + unsigned int steps_, + float totalTime_, + Vec jointMovement, + Vec maxJointRange, + Vec maxJointVelocityPerStep, + Vec maxJointAccelarationPerStep); + ~BangBangJointTrajectroy(); private: @@ -17,7 +24,6 @@ class BangBangJointTrajectroy : public Trajectory }; class BangBangCartTrajectory: public Trajectory { - }; #endif diff --git a/lwrserv/include/LinPolyTrajectory.h b/lwrserv/include/LinPolyTrajectory.h deleted file mode 100644 index 1e4cecc..0000000 --- a/lwrserv/include/LinPolyTrajectory.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef _LINPOLYTRAJECTORY_H_ -#define _LINPOLYTRAJECTORY_H_ -#include "Trajectroy.h" - -class LinPolyJointTrajectory: public Trajectory -{ - public: - LinPolyJointTrajectory(); - BangBangJointTrajectroy(unsigned int steps); - BangBangJointTrajectroy(unsigned int steps, unsigned int joints); - ~BangBangJointTrajectroy(); - private: - - protected: -}; -class LinPolyCartTrajectory: public Trajectory -{ -}; - - -#endif diff --git a/lwrserv/include/LinearTrajectory.h b/lwrserv/include/LinearTrajectory.h new file mode 100644 index 0000000..e42c4f3 --- /dev/null +++ b/lwrserv/include/LinearTrajectory.h @@ -0,0 +1,34 @@ +#ifndef _LINPOLYTRAJECTORY_H_ +#define _LINPOLYTRAJECTORY_H_ +#include "Trajectroy.h" + +class LinearJointTrajectory: public Trajectory +{ + public: + + template + LinearJointTrajectory( + unsigned int steps_, + float totalTime_, + Vec jointMovement, + Vec maxJointVelocityPerStep, + Vec maxJointAccelarationPerStep); + template + LinearJointTrajectory( + unsigned int steps_, + float totalTime_, + Vec jointMovement, + Vec maxJointVelocityPerStep, + Vec maxJointAccelarationPerStep, + Vec velocity); + ~LinearJointTrajectory(); + private: + + protected: +}; +class LinearCartTrajectory: public Trajectory +{ +}; + + +#endif diff --git a/lwrserv/include/Trajectroy.h b/lwrserv/include/Trajectroy.h index 6238a05..cc438eb 100644 --- a/lwrserv/include/Trajectroy.h +++ b/lwrserv/include/Trajectroy.h @@ -1,29 +1,46 @@ #ifndef _TRAJECTORY_H_ #define _TRAJECTORY_H_ +#include "vec.h" class Trajectory { public: - Trajectory(); - Trajectory(unsigned int steps); - Trajectory(unsigned int steps, unsigned int joints); + template + Trajectory ( + unsigned int steps_, + float totalTime_, + Vec jointMovement, + Vec maxJointVelocityPerStep, + Vec maxJointAccelarationPerStep + ); ~Trajectory(); - unsigned int update(); - unsigned int getSteps(); unsigned int getJoints(); - float getJointPos(unsigned int index, unsigned int joint); - float getCartPos(unsigned int index, unsigned int joint); - float getVelocity(unsigned int index, unsigned int joint); - float getAcceleration(unsigned int index, unsigned int joint); + /** + * + */ + template Vec getJointPos (unsigned int step); + template Vec getCartPos (unsigned int step); + template Vec getVelocity (unsigned int step); + template Vec getAcceleration(unsigned int step); + + struct trajectoryNode + { + float jointPos; + float cartPos; + float velocity; + float acceleration; + }; protected: static const unsigned int defaultSteps = 100; - static const unsigned int defaultJoints = 1; unsigned int steps; + float totalTime; unsigned int joints; + struct trajectoryNode* nodes; + }; #endif diff --git a/lwrserv/include/trajectory.h b/lwrserv/include/trajectory.h deleted file mode 100644 index 8b89859..0000000 --- a/lwrserv/include/trajectory.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef _TRAJECTORY_H_ -#define _TRAJECTORY_H_ - -#include "vec.h" - -class Trajectory -{ - public: - virtual unsigned int getSteps(); - - virtual Vec getJointValues(); - virtual Vec getJointVelocity(unsigned int jointID); - virtual Vec getJointAcceleration(unsigned int jointID); - - virtual Vec getCarthesianValues(); - virtual Vec getCarthesianVelocity(unsigned int jointID); - virtual Vec getCarthesianAcceleration(unsigned int jointID); -}; - -class TrajectoryBangBang :: Trajectory; -#endif diff --git a/lwrserv/include/vec.h b/lwrserv/include/vec.h index 6d0d028..a1b09b3 100644 --- a/lwrserv/include/vec.h +++ b/lwrserv/include/vec.h @@ -20,6 +20,13 @@ public: for (unsigned int i=0; i (const T tData) + { + for (unsigned int i=0; i (const T atData[SIZE]) diff --git a/lwrserv/program.cpp b/lwrserv/program.cpp index 7438fd1..8a046be 100644 --- a/lwrserv/program.cpp +++ b/lwrserv/program.cpp @@ -352,6 +352,7 @@ void *threadFriDataExchange(void *arg) for (int j=0; j currentInkLast; Vec currentDist; Vec currentDistLast; + // bang bang for (int i=0;i