diff --git a/lwrserv/Trajectroy.cpp b/lwrserv/Trajectroy.cpp new file mode 100644 index 0000000..b89a5f6 --- /dev/null +++ b/lwrserv/Trajectroy.cpp @@ -0,0 +1 @@ +#include "Trajectroy.h" diff --git a/lwrserv/global.cpp b/lwrserv/global.cpp index 2bba56b..31c618e 100644 --- a/lwrserv/global.cpp +++ b/lwrserv/global.cpp @@ -26,7 +26,7 @@ float USTarget[12]; float USApproach[12]; double VELOCITY = 20; double ACCELARATION = 10; -double maxVelJnt[] = {110.0,110.0,128.0,128.0,204.0,184.0,184.0}; +//double maxVelJnt[] = {110.0,110.0,128.0,128.0,204.0,184.0,184.0}; double maxAccJnt[] = {1.0,1.0,1.0,1.0,2.0,1.0,1.0}; double maxTrqJnt[] = {176.0,176.0,100.0,100.0,100.0,38.0,38.0}; double maxRangeJnt[] = {170.0,120.0,170.0,120.0,170.0,120.0,170.0}; diff --git a/lwrserv/include/global.h b/lwrserv/include/global.h index 3399f10..4a99459 100644 --- a/lwrserv/include/global.h +++ b/lwrserv/include/global.h @@ -22,12 +22,6 @@ extern double MSRMSRJACOBIAN[42]; extern double MSRMSRFTTCP[6]; extern double MSRCMDJNTPOS[7]; extern double MSRCMDPOSE[3][4]; -extern double VELOCITY; -extern double ACCELARATION; -extern double maxVelJnt[LBR_MNJ]; -extern double maxAccJnt[LBR_MNJ]; -extern double maxTrqJnt[LBR_MNJ]; -extern double maxRangeJnt[LBR_MNJ]; #ifndef SSSS #define SSSS diff --git a/lwrserv/include/mat.h b/lwrserv/include/mat.h index 221ebae..8f91c7d 100644 --- a/lwrserv/include/mat.h +++ b/lwrserv/include/mat.h @@ -145,6 +145,17 @@ public: buf(i,j) += m_aatData[i][a] * mat(a,j); return buf; } + Mat &operator = (const T aatData[SIZE*SIZE]) + { + for (unsigned int i=0; i class Vec; @@ -172,6 +173,65 @@ public: return vec; } + Vec celldivide (const Vec & vec) + { + Vec buff; + for (int i=0; i cellmultiply (const Vec & vec) + { + Vec buff; + for (int i=0; i abs () + { + Vec buff; + for (int i=0; i floor () + { + Vec buff; + for (int i=0; i ceil () + { + Vec buff; + for (int i=0; i m_atData[i]) + retval = m_atData[i]; + return retval; + } + T min () + { + T retval = m_atData[0]; + + // this * this + for (int i=0; i maxJointLocalVelocity; + Vec maxJointLocalAcceleration; + Vec delta; + Vec deltaAbs; + Vec dMaxSpeed; + Vec lMaxSpeed; + Vec dGesamt; + float sampleTime = 0.005f; - double currentInk[LBR_MNJ] = {0}; - double currentInkLast[LBR_MNJ] = {0}; - double currentDist [LBR_MNJ] = {0}; - double currentDistLast [LBR_MNJ] = {0}; - Vec maxVelocity = SvrData::getInstance()->getMaxVelocity(); - Vec maxAccelaration = SvrData::getInstance()->getMaxAcceleration(); + // get current robot constraints + Vec maxVelocityJoint = SvrData::getInstance()->getMaxVelocity(); + Vec maxAccelarationJoint = SvrData::getInstance()->getMaxAcceleration(); + Vec messuredJointPos = SvrData::getInstance()->getMessuredJointPos(); + Vec commandedJointPos = SvrData::getInstance()->getCommandedJointPos(); + + float velocity = SvrData::getInstance()->getRobotVelocity(); + float accelaration = SvrData::getInstance()->getRobotAcceleration(); // calculate delta positions of movement - for ( int i= 0; i < LBR_MNJ; i++) - { - delta[i] = MSRCMDJNTPOS[i]-(MSRMSRJNTPOS[i]*180/M_PI); - deltaAbs[i] = fabs(MSRCMDJNTPOS[i]-(MSRMSRJNTPOS[i]*180/M_PI)); - maxVelJntLocal[i] = maxVelJnt[i]*sampleTime*(VELOCITY/100.0); - maxAccJntLocal[i] = maxAccJnt[i]*sampleTime*(ACCELARATION/100.0); - } + delta = commandedJointPos - messuredJointPos; + deltaAbs = delta.abs(); + maxJointLocalVelocity = maxVelocityJoint * sampleTime * (velocity/100.0f); + maxJointLocalAcceleration = maxAccelarationJoint * sampleTime * (accelaration/100.0f); - // calculate movement steps + // calculate number of movement steps + dMaxSpeed = maxJointLocalVelocity.celldivide(maxJointLocalAcceleration); + lMaxSpeed = dMaxSpeed.cellmultiply(dMaxSpeed).cellmultiply(maxJointLocalAcceleration) * 0.5f; + for (int j=0; j deltaAbs[j]/(double)2.0) + if (lMaxSpeed(j) > deltaAbs(j)/(double)2.0) { - dGesamt[j] = sqrt(deltaAbs[j]/maxAccJntLocal[j])*2.0; + dGesamt(j) = sqrt(deltaAbs(j) / maxJointLocalAcceleration (j))*2.0; } else { - dGesamt[j] = dMaxSpeed[j]*2 + (deltaAbs[j]-lMaxSpeed[j]*2.0)/maxVelJntLocal[j]; + dGesamt(j) = dMaxSpeed(j)*2 + (deltaAbs(j)-lMaxSpeed(j)*2.0)/maxJointLocalVelocity(j); } } - int maxSteps =ceil(*max_element(dGesamt,(dGesamt+LBR_MNJ-1))); + int maxSteps = ceil(dGesamt.max()); + // there are atleast 2 steps otherwise it is no trajectory if (maxSteps == 0 || maxSteps == 1) goto end; for (int j=0; j currentInk; + Vec currentInkLast; + Vec currentDist; + Vec currentDistLast; + for (int i=0;i maxSteps-dMaxSpeed[j]) + for (int j=0;j maxSteps-dMaxSpeed(j)) + { + currentInk(j) = max(currentInkLast(j)-maxJointLocalAcceleration(j),0.0f); + }else + { + currentInk(j) = currentInkLast(j); + } + currentDist(j) = currentDistLast(j) + sgn(delta(j))*currentInk(j); + currentInkLast(j) = currentInk(j); + currentDistLast(j) = currentDist(j); + MSRMSRJNTPOS[j]+= sgn(delta(j))*currentInk(j)*(1./180*M_PI); } - currentDist[j] = currentDistLast[j] + sgn(delta[j])*currentInk[j]; - currentInkLast[j] = currentInk[j]; - currentDistLast[j] = currentDist[j]; - MSRMSRJNTPOS[j]+= sgn(delta[j])*currentInk[j]*(1./180*M_PI); + // set new position + friInst.doPositionControl(MSRMSRJNTPOS); } - friInst.doPositionControl(MSRMSRJNTPOS); } end: + // mark state to be done __MSRCMDJNTPOS = false; } else if (__CARTMOVE)