diff --git a/lwrserv/SvrData.cpp b/lwrserv/SvrData.cpp index 64812e5..e4763df 100644 --- a/lwrserv/SvrData.cpp +++ b/lwrserv/SvrData.cpp @@ -1,4 +1,9 @@ +#include +#include +#include +#include #include "SvrData.h" + bool SvrData::instanceFlag = false; SvrData* SvrData::single = 0; @@ -26,7 +31,12 @@ SvrData::SvrData(void) robot.max.torque[i] = maxTrqJnt[i]; robot.max.range[i] = maxRangeJnt[i]; } + + // init mutex for database + if (pthread_mutex_init(&dataLock, NULL) != 0) + printf("mutex init failed\n"); } + SvrData::~SvrData() { if (robot.max.velocity != 0) @@ -45,6 +55,7 @@ SvrData::~SvrData() robot.max.accelaration = 0; robot.max.torque = 0; robot.max.range = 0; + pthread_mutex_destroy(&dataLock); } SvrData* SvrData::getInstance () @@ -56,3 +67,165 @@ SvrData* SvrData::getInstance () instanceFlag = true; return single; } + + +void SvrData::lock() +{ + pthread_mutex_lock(&dataLock); +} + +void SvrData::unlock() +{ + pthread_mutex_unlock(&dataLock); +} + +int SvrData::getMessuredJointPos(float* data, size_t size) +{ + if (data == NULL) + return -EINVAL; + if (size != sizeof(messured.jointPos)) + return -EINVAL; + + pthread_mutex_lock(&dataLock); + memcpy(data,messured.jointPos,size); + pthread_mutex_unlock(&dataLock); +} + +int SvrData::getMessuredCartPos (float* data, size_t size) +{ + if (data == NULL) + return -EINVAL; + if (size != sizeof(messured.cartPos)) + return -EINVAL; + + pthread_mutex_lock(&dataLock); + memcpy(data,messured.cartPos,size); + pthread_mutex_unlock(&dataLock); +} + +int SvrData::getMessuredJacobian(float* data, size_t size) +{ + if (data == NULL) + return -EINVAL; + if (size != sizeof(messured.jacobian)) + return -EINVAL; + + pthread_mutex_lock(&dataLock); + memcpy(data,messured.jacobian,size); + pthread_mutex_unlock(&dataLock); +} + +int SvrData::getMessuredForceTorque(float* data, size_t size) +{ + if (data == NULL) + return -EINVAL; + if (size != sizeof(messured.forceAndTorque)) + return -EINVAL; + + pthread_mutex_lock(&dataLock); + memcpy(data,messured.forceAndTorque,size); + pthread_mutex_unlock(&dataLock); +} + +int SvrData::getCommandedJointPos(float* data, size_t size) +{ + if (data == NULL) + return -EINVAL; + if (size != sizeof(commanded.jointPos)) + return -EINVAL; + + pthread_mutex_lock(&dataLock); + memcpy(data,commanded.jointPos,size); + pthread_mutex_unlock(&dataLock); +} + +int SvrData::getCommandedCartPos (float* data, size_t size) +{ + if (data == NULL) + return -EINVAL; + if (size != sizeof(commanded.cartPos)) + return -EINVAL; + + pthread_mutex_lock(&dataLock); + memcpy(data,commanded.cartPos,size); + pthread_mutex_unlock(&dataLock); +} + +float SvrData::getMaxTorque(unsigned int pos) +{ + float retval = -1.0f; + if (pos >= robot.joints) + return retval; + + pthread_mutex_lock(&dataLock); + retval = robot.max.torque[pos-1]; + pthread_mutex_unlock(&dataLock); +} + +int SvrData::getMaxTorque(float* data, size_t size) +{ + if (data == NULL) + return -EINVAL; + if (size != sizeof(float)* robot.joints) + return -EINVAL; + + pthread_mutex_lock(&dataLock); + memcpy(data,robot.max.torque,size); + pthread_mutex_unlock(&dataLock); +} + +float SvrData::getMaxAccelaration(unsigned int pos) +{ + float retval = -1.0f; + if (pos >= robot.joints) + return retval; + + pthread_mutex_lock(&dataLock); + retval = robot.max.accelaration[pos-1]; + pthread_mutex_unlock(&dataLock); +} +int SvrData::getMaxAccelaration(float* data, size_t size) +{ + if (data == NULL) + return -EINVAL; + if (size != sizeof(float)* robot.joints) + return -EINVAL; + + pthread_mutex_lock(&dataLock); + memcpy(data,robot.max.accelaration,size); + pthread_mutex_unlock(&dataLock); +} + +float SvrData::getMaxRange(unsigned int pos) +{ + float retval = -1.0f; + if (pos >= robot.joints) + return retval; + + pthread_mutex_lock(&dataLock); + retval = robot.max.range[pos-1]; + pthread_mutex_unlock(&dataLock); +} + +int SvrData::getMaxRange(float* data, size_t size) +{ + if (data == NULL) + return -EINVAL; + if (size != sizeof(float)* robot.joints) + return -EINVAL; + + pthread_mutex_lock(&dataLock); + memcpy(data,robot.max.range,size); + pthread_mutex_unlock(&dataLock); +} + +unsigned int SvrData::getJoints() +{ + unsigned int retval = 0; + + pthread_mutex_lock(&dataLock); + retval = robot.joints; + pthread_mutex_unlock(&dataLock); + return retval; +} + diff --git a/lwrserv/SvrHandling.cpp b/lwrserv/SvrHandling.cpp index 1244f22..b280f30 100755 --- a/lwrserv/SvrHandling.cpp +++ b/lwrserv/SvrHandling.cpp @@ -7,6 +7,9 @@ #include #include +#include "SvrHandling.h" +#include "SvrData.h" + void mattoabc(float M[3][4], float &a, float &b, float &c) { float norm; @@ -31,19 +34,7 @@ void mattoabc(float M[3][4], float &a, float &b, float &c) void debugMat(Mat4f M) { -#if 0 - for (int i=0;igetMessuredJointPos(pos,sizeof(pos))) + client.Send("ERROR could not get joint pos"); + for (int i=0; i< LBR_MNJ; i++) { ss.str(""); - ss << (MSRMSRJNTPOS[i]*180/M_PI); + ss << (pos[i]*180/M_PI); out += ss.str() + " "; } client.Send(out); @@ -502,10 +501,15 @@ void SvrHandling::GetPositionHomRowWise(SocketObject& client) { string out = ""; stringstream ss (stringstream::in | stringstream::out); - for (int i=0; i< 12; i++) + + float pos[FRI_CART_FRM_DIM]; + if( 0 != SvrData::getInstance()->getMessuredCartPos(pos,sizeof(pos))) + client.Send("ERROR could not get cart pos"); + + for (int i=0; i< FRI_CART_FRM_DIM; i++) { ss.str(""); - ss << (MSRMSRCARTPOS[i]); + ss << (pos[i]); out += ss.str() + " "; } client.Send(out); @@ -515,10 +519,14 @@ void SvrHandling::GetForceTorqueTcp(SocketObject& client) { string out = ""; stringstream ss (stringstream::in | stringstream::out); - for (int i=0; i< 6; i++) + + float torque[FRI_CART_VEC]; + if( 0 != SvrData::getInstance()->getMessuredForceTorque(torque,sizeof(torque))) + client.Send("ERROR could not get force and torque"); + for (int i=0; i< FRI_CART_VEC; i++) { ss.str(""); - ss << (MSRMSRFTTCP[i]); + ss << torque[i]; out += ss.str() + " "; } client.Send(out); @@ -576,7 +584,6 @@ void SvrHandling::MovePTPJoints(SocketObject& client, string& args) } } client.Send(SVR_TRUE_RSP); - } void SvrHandling::MoveHomRowWiseStatus(SocketObject& client, string& args) @@ -958,10 +965,6 @@ void SvrHandling::MoveCartesian(SocketObject& client, string& args) client.Send(SVR_TRUE_RSP); __DOUS2 = true; - - - - } void SvrHandling::quit(SocketObject& client) diff --git a/lwrserv/include/Singleton.h b/lwrserv/include/Singleton.h index f87ffa4..0576f58 100644 --- a/lwrserv/include/Singleton.h +++ b/lwrserv/include/Singleton.h @@ -1,7 +1,7 @@ class Singleton { public: - Singleton* getInstance(void); + static Singleton* getInstance(void); Singleton() {}; ~Singleton() {}; private: diff --git a/lwrserv/include/SvrData.h b/lwrserv/include/SvrData.h index 08316f8..9b0aeed 100644 --- a/lwrserv/include/SvrData.h +++ b/lwrserv/include/SvrData.h @@ -1,4 +1,3 @@ - #ifndef _SVRDATA_H_ #define _SVRDATA_H_ @@ -38,7 +37,7 @@ private: unsigned int joints; } robot; - pthread_mutex_t mutexsum; + pthread_mutex_t dataLock; /// private constructor, because the database is a singleton SvrData(); @@ -48,7 +47,18 @@ private: public: ~SvrData(void); - SvrData* getInstance(); + static SvrData* getInstance(); + + void lock(); + void unlock(); + + int getMessuredJointPos(float* data, size_t size); + int getMessuredCartPos (float* data, size_t size); + int getMessuredJacobian(float* data, size_t size); + int getMessuredForceTorque(float* data, size_t size); + + int getCommandedJointPos(float* data, size_t size); + int getCommandedCartPos (float* data, size_t size); float getMaxTorque(unsigned int pos); int getMaxTorque(float* data, size_t size); diff --git a/lwrserv/include/mat.h b/lwrserv/include/mat.h index d39cd10..d2bd9d6 100644 --- a/lwrserv/include/mat.h +++ b/lwrserv/include/mat.h @@ -70,6 +70,39 @@ public: // CMatrixoperator - (const Matrix &mat) // ... + Mat operator + (const T &scalar) + { + Mat buf; + for (unsigned int i=0; i operator - (const T &scalar) + { + Mat buf; + for (unsigned int i=0; i operator * (const T &scalar) + { + Mat buf; + for (unsigned int i=0; i operator / (const T &scalar) + { + Mat buf; + for (unsigned int i=0; i operator * (const Mat &mat) { Mat buf; @@ -80,7 +113,8 @@ public: return buf; } - Vec operator * (const Vec &vec) +#if 0 + Mat operator * (const Vec &vec) { Vec buf; for (unsigned int j=0; j determinant() + { + T buf; + + for (unsigned int j=0; j norm() + { + T buf; + for (unsigned int i=0; i transpose() + { + Mat buf; + for (unsigned int i=0; i inv() { Mat invOut;