|
@ -10,6 +10,7 @@ |
|
|
#include "SvrHandling.h"
|
|
|
#include "SvrHandling.h"
|
|
|
#include "SvrData.h"
|
|
|
#include "SvrData.h"
|
|
|
#include "Trajectroy.h"
|
|
|
#include "Trajectroy.h"
|
|
|
|
|
|
#include "LinearTrajectory.h"
|
|
|
#include <boost/thread/thread.hpp>
|
|
|
#include <boost/thread/thread.hpp>
|
|
|
|
|
|
|
|
|
void printUsage(SocketObject& client) |
|
|
void printUsage(SocketObject& client) |
|
@ -45,9 +46,9 @@ void debugMat(Mat4f M) |
|
|
cout << M << "\n\r" << endl; |
|
|
cout << M << "\n\r" << endl; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
double* kukaBackwardCalc(double M_[12], float arg[3]) |
|
|
|
|
|
|
|
|
VecJoint kukaBackwardCalc(double M_[12], float arg[3]) |
|
|
{ |
|
|
{ |
|
|
double* Joints = new double[7]; |
|
|
|
|
|
|
|
|
VecJoint Joints(0.0f); |
|
|
//DH-Parameter
|
|
|
//DH-Parameter
|
|
|
float alp[7] = {-M_PI/2.0f, M_PI/2.0f, -M_PI/2.0f, M_PI/2.0f, -M_PI/2.0f, M_PI/2.0f, 0.0f}; |
|
|
float alp[7] = {-M_PI/2.0f, M_PI/2.0f, -M_PI/2.0f, M_PI/2.0f, -M_PI/2.0f, M_PI/2.0f, 0.0f}; |
|
|
float d[7] = {310.4f/1000.0f, 0.0f, 400.1f/1000.0f, 0.0f, 390.0f/1000.0f, 0.0f, 78.0f/1000.0f}; |
|
|
float d[7] = {310.4f/1000.0f, 0.0f, 400.1f/1000.0f, 0.0f, 390.0f/1000.0f, 0.0f, 78.0f/1000.0f}; |
|
@ -95,19 +96,19 @@ double* kukaBackwardCalc(double M_[12], float arg[3]) |
|
|
M06=M*Inv; |
|
|
M06=M*Inv; |
|
|
|
|
|
|
|
|
//Joint 1 including given offset
|
|
|
//Joint 1 including given offset
|
|
|
Joints[0] = atan2(M06(1,3),M06(0,3))+J1os; |
|
|
|
|
|
|
|
|
Joints(0) = atan2(M06(1,3),M06(0,3))+J1os; |
|
|
|
|
|
|
|
|
//Calculating M16
|
|
|
//Calculating M16
|
|
|
Mat4f R01; |
|
|
Mat4f R01; |
|
|
i = 0; |
|
|
i = 0; |
|
|
R01(0,0) = cos(Joints[i]); |
|
|
|
|
|
R01(0,1) = -sin(Joints[i])*cos(alp[i]); |
|
|
|
|
|
R01(0,2) = sin(Joints[i])*sin(alp[i]); |
|
|
|
|
|
|
|
|
R01(0,0) = cos(Joints(i)); |
|
|
|
|
|
R01(0,1) = -sin(Joints(i))*cos(alp[i]); |
|
|
|
|
|
R01(0,2) = sin(Joints(i))*sin(alp[i]); |
|
|
R01(0,3) = 0; |
|
|
R01(0,3) = 0; |
|
|
|
|
|
|
|
|
R01(1,0) = sin(Joints[i]); |
|
|
|
|
|
R01(1,1) = cos(Joints[i])*cos(alp[i]); |
|
|
|
|
|
R01(1,2) = -cos(Joints[i])*sin(alp[i]); |
|
|
|
|
|
|
|
|
R01(1,0) = sin(Joints(i)); |
|
|
|
|
|
R01(1,1) = cos(Joints(i))*cos(alp[i]); |
|
|
|
|
|
R01(1,2) = -cos(Joints(i))*sin(alp[i]); |
|
|
R01(1,3) = 0; |
|
|
R01(1,3) = 0; |
|
|
|
|
|
|
|
|
R01(2,0) = 0; |
|
|
R01(2,0) = 0; |
|
@ -146,20 +147,20 @@ double* kukaBackwardCalc(double M_[12], float arg[3]) |
|
|
-2*m14*m14*d3*d3*m34*m34+2*m14*m14*d5*d5*m34*m34+2*m14*m14*d5*d5*d3*d3 |
|
|
-2*m14*m14*d3*d3*m34*m34+2*m14*m14*d5*d5*m34*m34+2*m14*m14*d5*d5*d3*d3 |
|
|
+2*m24*m24*d5*d5*m14*m14)))/((m24*m24+m14*m14)*d3); |
|
|
+2*m24*m24*d5*d5*m14*m14)))/((m24*m24+m14*m14)*d3); |
|
|
|
|
|
|
|
|
Joints[1] = atan2(arg1,arg2); |
|
|
|
|
|
|
|
|
Joints(1) = atan2(arg1,arg2); |
|
|
|
|
|
|
|
|
//Calculating M26
|
|
|
//Calculating M26
|
|
|
Mat4f R12; |
|
|
Mat4f R12; |
|
|
i = 1; |
|
|
i = 1; |
|
|
|
|
|
|
|
|
R12(0,0) = cos(Joints[i]); |
|
|
|
|
|
R12(0,1) = -sin(Joints[i])*cos(alp[i]); |
|
|
|
|
|
R12(0,2) = sin(Joints[i])*sin(alp[i]); |
|
|
|
|
|
|
|
|
R12(0,0) = cos(Joints(i)); |
|
|
|
|
|
R12(0,1) = -sin(Joints(i))*cos(alp[i]); |
|
|
|
|
|
R12(0,2) = sin(Joints(i))*sin(alp[i]); |
|
|
R12(0,3) = 0; |
|
|
R12(0,3) = 0; |
|
|
|
|
|
|
|
|
R12(1,0) = sin(Joints[i]); |
|
|
|
|
|
R12(1,1) = cos(Joints[i])*cos(alp[i]); |
|
|
|
|
|
R12(1,2) = -cos(Joints[i])*sin(alp[i]); |
|
|
|
|
|
|
|
|
R12(1,0) = sin(Joints(i)); |
|
|
|
|
|
R12(1,1) = cos(Joints(i))*cos(alp[i]); |
|
|
|
|
|
R12(1,2) = -cos(Joints(i))*sin(alp[i]); |
|
|
R12(1,3) = 0; |
|
|
R12(1,3) = 0; |
|
|
|
|
|
|
|
|
R12(2,0) = 0; |
|
|
R12(2,0) = 0; |
|
@ -179,20 +180,20 @@ double* kukaBackwardCalc(double M_[12], float arg[3]) |
|
|
M26 = Inv*M06; |
|
|
M26 = Inv*M06; |
|
|
|
|
|
|
|
|
//Joint 3
|
|
|
//Joint 3
|
|
|
Joints[2] = atan2(ELBOW*M26(1,3),ELBOW*M26(0,3)); |
|
|
|
|
|
|
|
|
Joints(2) = atan2(ELBOW*M26(1,3),ELBOW*M26(0,3)); |
|
|
|
|
|
|
|
|
//Calculating M36
|
|
|
//Calculating M36
|
|
|
Mat4f R23; |
|
|
Mat4f R23; |
|
|
i = 2; |
|
|
i = 2; |
|
|
|
|
|
|
|
|
R23(0,0) = cos(Joints[i]); |
|
|
|
|
|
R23(0,1) = -sin(Joints[i])*cos(alp[i]); |
|
|
|
|
|
R23(0,2) = sin(Joints[i])*sin(alp[i]); |
|
|
|
|
|
|
|
|
R23(0,0) = cos(Joints(i)); |
|
|
|
|
|
R23(0,1) = -sin(Joints(i))*cos(alp[i]); |
|
|
|
|
|
R23(0,2) = sin(Joints(i))*sin(alp[i]); |
|
|
R23(0,3) = 0; |
|
|
R23(0,3) = 0; |
|
|
|
|
|
|
|
|
R23(1,0) = sin(Joints[i]); |
|
|
|
|
|
R23(1,1) = cos(Joints[i])*cos(alp[i]); |
|
|
|
|
|
R23(1,2) = -cos(Joints[i])*sin(alp[i]); |
|
|
|
|
|
|
|
|
R23(1,0) = sin(Joints(i)); |
|
|
|
|
|
R23(1,1) = cos(Joints(i))*cos(alp[i]); |
|
|
|
|
|
R23(1,2) = -cos(Joints(i))*sin(alp[i]); |
|
|
R23(1,3) = 0; |
|
|
R23(1,3) = 0; |
|
|
|
|
|
|
|
|
R23(2,0) = 0; |
|
|
R23(2,0) = 0; |
|
@ -212,19 +213,19 @@ double* kukaBackwardCalc(double M_[12], float arg[3]) |
|
|
M36 = Inv*M06; |
|
|
M36 = Inv*M06; |
|
|
|
|
|
|
|
|
//Joint 4
|
|
|
//Joint 4
|
|
|
Joints[3] = atan2(M36(0,3),-M36(1,3)); |
|
|
|
|
|
|
|
|
Joints(3) = atan2(M36(0,3),-M36(1,3)); |
|
|
|
|
|
|
|
|
//Calculating M47
|
|
|
//Calculating M47
|
|
|
Mat4f R34; |
|
|
Mat4f R34; |
|
|
i = 3; |
|
|
i = 3; |
|
|
R34(0,0) = cos(Joints[i]); |
|
|
|
|
|
R34(0,1) = -sin(Joints[i])*cos(alp[i]); |
|
|
|
|
|
R34(0,2) = sin(Joints[i])*sin(alp[i]); |
|
|
|
|
|
|
|
|
R34(0,0) = cos(Joints(i)); |
|
|
|
|
|
R34(0,1) = -sin(Joints(i))*cos(alp[i]); |
|
|
|
|
|
R34(0,2) = sin(Joints(i))*sin(alp[i]); |
|
|
R34(0,3) = 0; |
|
|
R34(0,3) = 0; |
|
|
|
|
|
|
|
|
R34(1,0) = sin(Joints[i]); |
|
|
|
|
|
R34(1,1) = cos(Joints[i])*cos(alp[i]); |
|
|
|
|
|
R34(1,2) = -cos(Joints[i])*sin(alp[i]); |
|
|
|
|
|
|
|
|
R34(1,0) = sin(Joints(i)); |
|
|
|
|
|
R34(1,1) = cos(Joints(i))*cos(alp[i]); |
|
|
|
|
|
R34(1,2) = -cos(Joints(i))*sin(alp[i]); |
|
|
R34(1,3) = 0; |
|
|
R34(1,3) = 0; |
|
|
|
|
|
|
|
|
R34(2,0) = 0; |
|
|
R34(2,0) = 0; |
|
@ -246,28 +247,28 @@ double* kukaBackwardCalc(double M_[12], float arg[3]) |
|
|
//Joint 5
|
|
|
//Joint 5
|
|
|
float th = 0.0001; |
|
|
float th = 0.0001; |
|
|
if (abs(M47(1,2))<th && abs(M47(0,2))<th) |
|
|
if (abs(M47(1,2))<th && abs(M47(0,2))<th) |
|
|
Joints[4] = 0; |
|
|
|
|
|
|
|
|
Joints(4) = 0; |
|
|
else |
|
|
else |
|
|
Joints[4] = atan2(FLIP*M47(1,2),FLIP*M47(0,2)); |
|
|
|
|
|
|
|
|
Joints(4) = atan2(FLIP*M47(1,2),FLIP*M47(0,2)); |
|
|
|
|
|
|
|
|
//Joint 6
|
|
|
//Joint 6
|
|
|
Joints[5] = atan2(FLIP*sqrt(1-M47(2,2)*M47(2,2)),M47(2,2)); |
|
|
|
|
|
|
|
|
Joints(5) = atan2(FLIP*sqrt(1-M47(2,2)*M47(2,2)),M47(2,2)); |
|
|
|
|
|
|
|
|
//Joint 7
|
|
|
//Joint 7
|
|
|
if (abs(M47(2,1))<th && abs(M47(2,0))<th) |
|
|
if (abs(M47(2,1))<th && abs(M47(2,0))<th) |
|
|
Joints[6] = 0; |
|
|
|
|
|
|
|
|
Joints(6) = 0; |
|
|
else |
|
|
else |
|
|
Joints[6] = atan2(FLIP*M47(2,1),FLIP*-M47(2,0)); |
|
|
|
|
|
|
|
|
Joints(6) = atan2(FLIP*M47(2,1),FLIP*-M47(2,0)); |
|
|
|
|
|
|
|
|
for (int i = 0; i<7; i++) |
|
|
for (int i = 0; i<7; i++) |
|
|
{ |
|
|
{ |
|
|
Joints[i] = Joints[i]*180.0/M_PI; |
|
|
|
|
|
|
|
|
Joints(i) = Joints(i)*180.0/M_PI; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//Kuka Joints
|
|
|
//Kuka Joints
|
|
|
//Joints[3] = -Joints[3];
|
|
|
//Joints[3] = -Joints[3];
|
|
|
Joints[1] = -Joints[1]; |
|
|
|
|
|
Joints[5] = -Joints[5]; |
|
|
|
|
|
|
|
|
Joints(1) = -Joints(1); |
|
|
|
|
|
Joints(5) = -Joints(5); |
|
|
|
|
|
|
|
|
return Joints; |
|
|
return Joints; |
|
|
} |
|
|
} |
|
@ -346,7 +347,7 @@ void SvrHandling::run(int port) |
|
|
cout << timestamp() + "Client accepted!\n"; |
|
|
cout << timestamp() + "Client accepted!\n"; |
|
|
if (handshakeAccepted(*client)) |
|
|
if (handshakeAccepted(*client)) |
|
|
{ |
|
|
{ |
|
|
handle(*client); |
|
|
|
|
|
|
|
|
clientCommandLoop(*client); |
|
|
} |
|
|
} |
|
|
client->Disconnect(); |
|
|
client->Disconnect(); |
|
|
cout << timestamp() + "Client disconnected.\n"; |
|
|
cout << timestamp() + "Client disconnected.\n"; |
|
@ -382,7 +383,7 @@ bool SvrHandling::handshakeAccepted(SocketObject& client) |
|
|
return(c_state == accepted); |
|
|
return(c_state == accepted); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void SvrHandling::handle(SocketObject& client) |
|
|
|
|
|
|
|
|
void SvrHandling::clientCommandLoop(SocketObject& client) |
|
|
{ |
|
|
{ |
|
|
string message, cmd, arg; |
|
|
string message, cmd, arg; |
|
|
while (c_state == accepted) |
|
|
while (c_state == accepted) |
|
@ -582,14 +583,15 @@ void SvrHandling::MovePTPJoints(SocketObject& client, string& args) |
|
|
VecJoint maxJointVelocity = SvrData::getInstance()->getMaxVelocity(); |
|
|
VecJoint maxJointVelocity = SvrData::getInstance()->getMaxVelocity(); |
|
|
VecJoint maxJointAcceleration = SvrData::getInstance()->getMaxAcceleration(); |
|
|
VecJoint maxJointAcceleration = SvrData::getInstance()->getMaxAcceleration(); |
|
|
|
|
|
|
|
|
newTrajectory = new LinearJointTrajectory<JOINT_NUMBER>(sampleTimeMs, maxJointVelocity, maxJointAcceleration, prevJointPos, newJointPos); |
|
|
|
|
|
|
|
|
newTrajectory = (class Trajectory<JOINT_NUMBER>*) new LinearJointTrajectory<JOINT_NUMBER>(sampleTimeMs, maxJointVelocity, maxJointAcceleration, prevJointPos, newJointPos); |
|
|
|
|
|
|
|
|
__MSRCMDJNTPOS = true; |
|
|
|
|
|
|
|
|
// add trajectory to queue for sender thread
|
|
|
|
|
|
SvrData::getInstance()->pushTrajectory(newTrajectory); |
|
|
|
|
|
|
|
|
//Wait to end of movement
|
|
|
//Wait to end of movement
|
|
|
while (true) |
|
|
while (true) |
|
|
{ |
|
|
{ |
|
|
if (SvrData::getInstance()->getMovementDone() == true) |
|
|
|
|
|
|
|
|
if (SvrData::getInstance()->getTrajectoryDone() == true) |
|
|
break; |
|
|
break; |
|
|
boost::this_thread::sleep( boost::posix_time::milliseconds(sampleTimeMs) ); |
|
|
boost::this_thread::sleep( boost::posix_time::milliseconds(sampleTimeMs) ); |
|
|
} |
|
|
} |
|
@ -598,39 +600,47 @@ void SvrHandling::MovePTPJoints(SocketObject& client, string& args) |
|
|
|
|
|
|
|
|
void SvrHandling::MoveHomRowWiseStatus(SocketObject& client, string& args) |
|
|
void SvrHandling::MoveHomRowWiseStatus(SocketObject& client, string& args) |
|
|
{ |
|
|
{ |
|
|
__SVR_CURRENT_JOB = true; |
|
|
|
|
|
string buf; |
|
|
string buf; |
|
|
double temp[15]; |
|
|
double temp[15]; |
|
|
stringstream ss(args); |
|
|
stringstream ss(args); |
|
|
stringstream ss2f; |
|
|
stringstream ss2f; |
|
|
vector<string> tokens; |
|
|
|
|
|
int i = 0; |
|
|
|
|
|
|
|
|
int argc = 0; |
|
|
|
|
|
|
|
|
|
|
|
// convert position parameters from string to float
|
|
|
while (ss >> buf) |
|
|
while (ss >> buf) |
|
|
{ |
|
|
{ |
|
|
if (i>15-1) |
|
|
|
|
|
|
|
|
// only need 15 parameters not more
|
|
|
|
|
|
if (argc>15-1) |
|
|
{ |
|
|
{ |
|
|
client.Send(SVR_FALSE_RSP); |
|
|
client.Send(SVR_FALSE_RSP); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
tokens.push_back(buf); |
|
|
|
|
|
|
|
|
|
|
|
ss2f.flush(); |
|
|
ss2f.flush(); |
|
|
ss2f.clear(); |
|
|
ss2f.clear(); |
|
|
ss2f << buf; |
|
|
ss2f << buf; |
|
|
ss2f >> temp[i]; |
|
|
|
|
|
i++; |
|
|
|
|
|
|
|
|
ss2f >> temp[argc]; |
|
|
|
|
|
argc++; |
|
|
} |
|
|
} |
|
|
if (i<15-1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// check for exactly 15 parameters
|
|
|
|
|
|
if (argc != 15) |
|
|
{ |
|
|
{ |
|
|
client.Send(SVR_FALSE_RSP); |
|
|
client.Send(SVR_FALSE_RSP); |
|
|
return ; |
|
|
return ; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// first part is homegenous position koordinates
|
|
|
|
|
|
MatCarthesian newCartPos(0.0f, 1.0f); |
|
|
for (int i=0 ;i<3; i++) |
|
|
for (int i=0 ;i<3; i++) |
|
|
{ |
|
|
{ |
|
|
for (int j=0;j<4;j++) |
|
|
for (int j=0;j<4;j++) |
|
|
{ |
|
|
{ |
|
|
MSRCMDPOSE[i][j]=temp[i*4+j]; |
|
|
|
|
|
|
|
|
newCartPos(i,j)=temp[i*4+j]; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// extract elbow flip and hand parameter
|
|
|
float arg[3]; |
|
|
float arg[3]; |
|
|
for (int i=0;i<3;i++) |
|
|
for (int i=0;i<3;i++) |
|
|
{ |
|
|
{ |
|
@ -638,120 +648,137 @@ void SvrHandling::MoveHomRowWiseStatus(SocketObject& client, string& args) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//Backward Calculation
|
|
|
//Backward Calculation
|
|
|
|
|
|
VecJoint newJointPos = kukaBackwardCalc(temp, arg); |
|
|
|
|
|
|
|
|
double* CalcJoints=NULL; |
|
|
|
|
|
CalcJoints = kukaBackwardCalc(temp, arg); |
|
|
|
|
|
|
|
|
|
|
|
//Check for Joint Range
|
|
|
//Check for Joint Range
|
|
|
if (!checkJntRange(CalcJoints)) |
|
|
|
|
|
|
|
|
if (!SvrData::getInstance()->checkJointRange(newJointPos)) |
|
|
{ |
|
|
{ |
|
|
string out = "Error: Joints out of Range!"; |
|
|
string out = "Error: Joints out of Range!"; |
|
|
client.Send(out); |
|
|
client.Send(out); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Jmove
|
|
|
|
|
|
for (int i=0 ;i<LBR_MNJ; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
MSRCMDJNTPOS[i]=CalcJoints[i]; |
|
|
|
|
|
} |
|
|
|
|
|
__MSRCMDJNTPOS = true; |
|
|
|
|
|
|
|
|
// calculate trajectory
|
|
|
|
|
|
VecJoint prevJointPos = SvrData::getInstance()->getCommandedJointPos(); |
|
|
|
|
|
float sampleTimeMs = SvrData::getInstance()->getSampleTimeMs(); |
|
|
|
|
|
VecJoint maxJointVelocity = SvrData::getInstance()->getMaxVelocity(); |
|
|
|
|
|
VecJoint maxJointAcceleration = SvrData::getInstance()->getMaxAcceleration(); |
|
|
|
|
|
|
|
|
|
|
|
class Trajectory<JOINT_NUMBER>* newTrajectory = new LinearJointTrajectory<JOINT_NUMBER>(sampleTimeMs, maxJointVelocity, maxJointAcceleration, prevJointPos, newJointPos); |
|
|
|
|
|
|
|
|
|
|
|
// set new commanded position for next trajectory
|
|
|
|
|
|
SvrData::getInstance()->setCommandedJointPos(newJointPos); |
|
|
|
|
|
|
|
|
|
|
|
// add new trajectory to position
|
|
|
|
|
|
SvrData::getInstance()->pushTrajectory(newTrajectory); |
|
|
|
|
|
|
|
|
//Wait to end of movement
|
|
|
//Wait to end of movement
|
|
|
while (1) |
|
|
|
|
|
{ |
|
|
|
|
|
if (!__MSRCMDJNTPOS) |
|
|
|
|
|
|
|
|
while (true) |
|
|
{ |
|
|
{ |
|
|
|
|
|
if (SvrData::getInstance()->getTrajectoryDone() == true) |
|
|
break; |
|
|
break; |
|
|
|
|
|
boost::this_thread::sleep( boost::posix_time::milliseconds(sampleTimeMs) ); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
client.Send(SVR_TRUE_RSP); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// send a positive client feedback
|
|
|
|
|
|
client.Send(SVR_TRUE_RSP); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void SvrHandling::SetSpeed(SocketObject& client, string& args) |
|
|
void SvrHandling::SetSpeed(SocketObject& client, string& args) |
|
|
{ |
|
|
{ |
|
|
__SETVELOCITY = true; |
|
|
|
|
|
__SVR_CURRENT_JOB = true; |
|
|
|
|
|
//SvrData::getInstance()->setState(SVR_STATE_SET_VELOCITY);
|
|
|
|
|
|
string buf; |
|
|
string buf; |
|
|
float newVelocity; |
|
|
|
|
|
|
|
|
float newVelocityPercentage; |
|
|
|
|
|
int argc = 0; |
|
|
stringstream ss(args); |
|
|
stringstream ss(args); |
|
|
stringstream ss2f; |
|
|
stringstream ss2f; |
|
|
vector<string> tokens; |
|
|
vector<string> tokens; |
|
|
int i = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// no speed argument
|
|
|
if (args == "") |
|
|
if (args == "") |
|
|
{ |
|
|
{ |
|
|
client.Send(SVR_FALSE_RSP); |
|
|
client.Send(SVR_FALSE_RSP); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// convert speed argument to float
|
|
|
while (ss >> buf) |
|
|
while (ss >> buf) |
|
|
{ |
|
|
{ |
|
|
if (i>0) |
|
|
|
|
|
|
|
|
// only need one speed argument
|
|
|
|
|
|
if (argc>0) |
|
|
{ |
|
|
{ |
|
|
client.Send(SVR_FALSE_RSP); |
|
|
client.Send(SVR_FALSE_RSP); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
tokens.push_back(buf); |
|
|
|
|
|
ss2f.flush(); |
|
|
ss2f.flush(); |
|
|
ss2f.clear(); |
|
|
ss2f.clear(); |
|
|
ss2f << buf; |
|
|
ss2f << buf; |
|
|
ss2f >> newVelocity; |
|
|
|
|
|
i++; |
|
|
|
|
|
|
|
|
ss2f >> newVelocityPercentage; |
|
|
|
|
|
argc++; |
|
|
} |
|
|
} |
|
|
if ((newVelocity < 1.0f)||(newVelocity >1000.0)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// check for a valid range for the new Velocity
|
|
|
|
|
|
if ((newVelocityPercentage <= 0.0f)||(newVelocityPercentage >100.0f)) |
|
|
{ |
|
|
{ |
|
|
client.Send(SVR_FALSE_RSP); |
|
|
client.Send(SVR_FALSE_RSP); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
SvrData::getInstance()->setRobotVelocity(newVelocity); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// save new velocity into the database
|
|
|
|
|
|
SvrData::getInstance()->setRobotVelocityPercentage(newVelocityPercentage); |
|
|
|
|
|
|
|
|
|
|
|
// signal a positive feedback to the client side
|
|
|
client.Send(SVR_TRUE_RSP); |
|
|
client.Send(SVR_TRUE_RSP); |
|
|
//SvrData::getInstance()->setState(SVR_STATE_RUNNING);
|
|
|
|
|
|
__SVR_CURRENT_JOB = false; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void SvrHandling::SetAccel(SocketObject& client, string& args) |
|
|
void SvrHandling::SetAccel(SocketObject& client, string& args) |
|
|
{ |
|
|
{ |
|
|
__SETACCEL = true; |
|
|
|
|
|
__SVR_CURRENT_JOB = true; |
|
|
|
|
|
string buf; |
|
|
string buf; |
|
|
float newAcceleration; |
|
|
|
|
|
|
|
|
float newAccelerationPercentage; |
|
|
stringstream ss(args); |
|
|
stringstream ss(args); |
|
|
stringstream ss2f; |
|
|
stringstream ss2f; |
|
|
vector<string> tokens; |
|
|
|
|
|
int i = 0; |
|
|
|
|
|
|
|
|
int argc = 0; |
|
|
|
|
|
|
|
|
|
|
|
// need at least one argument
|
|
|
if (args == "") |
|
|
if (args == "") |
|
|
{ |
|
|
{ |
|
|
client.Send(SVR_FALSE_RSP); |
|
|
client.Send(SVR_FALSE_RSP); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// convert acceleration string into float
|
|
|
while (ss >> buf) |
|
|
while (ss >> buf) |
|
|
{ |
|
|
{ |
|
|
if (i>0) |
|
|
|
|
|
|
|
|
// only one argument is necessary
|
|
|
|
|
|
if (argc>0) |
|
|
{ |
|
|
{ |
|
|
client.Send(SVR_FALSE_RSP); |
|
|
client.Send(SVR_FALSE_RSP); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
tokens.push_back(buf); |
|
|
|
|
|
ss2f.flush(); |
|
|
ss2f.flush(); |
|
|
ss2f.clear(); |
|
|
ss2f.clear(); |
|
|
ss2f << buf; |
|
|
ss2f << buf; |
|
|
ss2f >> newAcceleration; |
|
|
|
|
|
i++; |
|
|
|
|
|
|
|
|
ss2f >> newAccelerationPercentage; |
|
|
|
|
|
argc++; |
|
|
} |
|
|
} |
|
|
if ((newAcceleration < 1.0f)||(newAcceleration >100.0f)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// check for a valid rang for the robot acceleration
|
|
|
|
|
|
if ((newAccelerationPercentage < 1.0f)||(newAccelerationPercentage >100.0f)) |
|
|
{ |
|
|
{ |
|
|
client.Send(SVR_FALSE_RSP); |
|
|
client.Send(SVR_FALSE_RSP); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
SvrData::getInstance()->setRobotAcceleration(newAcceleration); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// save new acceleration
|
|
|
|
|
|
SvrData::getInstance()->setRobotAccelerationPercentage(newAccelerationPercentage); |
|
|
|
|
|
|
|
|
|
|
|
// signal a positive client feedback
|
|
|
client.Send(SVR_TRUE_RSP); |
|
|
client.Send(SVR_TRUE_RSP); |
|
|
__SVR_CURRENT_JOB = false; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void SvrHandling::StartPotFieldMode(SocketObject& client, string& args) |
|
|
void SvrHandling::StartPotFieldMode(SocketObject& client, string& args) |
|
|
{ |
|
|
{ |
|
|
|
|
|
#if 0
|
|
|
__MSRSTARTPOTFIELD = false; |
|
|
__MSRSTARTPOTFIELD = false; |
|
|
__MSRSTOPPOTFIELD = false; |
|
|
__MSRSTOPPOTFIELD = false; |
|
|
//Set current Joint Vals
|
|
|
//Set current Joint Vals
|
|
@ -767,11 +794,13 @@ void SvrHandling::StartPotFieldMode(SocketObject& client, string& args) |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
#endif
|
|
|
client.Send(SVR_TRUE_RSP); |
|
|
client.Send(SVR_TRUE_RSP); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void SvrHandling::StopPotFieldMode(SocketObject& client, string& args) |
|
|
void SvrHandling::StopPotFieldMode(SocketObject& client, string& args) |
|
|
{ |
|
|
{ |
|
|
|
|
|
#if 0
|
|
|
__POTFIELDMODE = false; |
|
|
__POTFIELDMODE = false; |
|
|
|
|
|
|
|
|
while (1) |
|
|
while (1) |
|
@ -781,83 +810,78 @@ void SvrHandling::StopPotFieldMode(SocketObject& client, string& args) |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
#endif
|
|
|
client.Send(SVR_TRUE_RSP); |
|
|
client.Send(SVR_TRUE_RSP); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void SvrHandling::SetPos(SocketObject& client, string& args) |
|
|
void SvrHandling::SetPos(SocketObject& client, string& args) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
string buf; |
|
|
string buf; |
|
|
double temp[15]; |
|
|
double temp[15]; |
|
|
stringstream ss(args); |
|
|
stringstream ss(args); |
|
|
stringstream ss2f; |
|
|
stringstream ss2f; |
|
|
vector<string> tokens; |
|
|
|
|
|
int i = 0; |
|
|
|
|
|
|
|
|
int argc = 0; |
|
|
|
|
|
|
|
|
|
|
|
// convert position arguments from string to float
|
|
|
while (ss >> buf) |
|
|
while (ss >> buf) |
|
|
{ |
|
|
{ |
|
|
if (i>15-1) |
|
|
|
|
|
|
|
|
// only 15 parameters are necessary
|
|
|
|
|
|
if (argc>=15) |
|
|
{ |
|
|
{ |
|
|
client.Send(SVR_FALSE_RSP); |
|
|
client.Send(SVR_FALSE_RSP); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
tokens.push_back(buf); |
|
|
|
|
|
|
|
|
|
|
|
ss2f.flush(); |
|
|
ss2f.flush(); |
|
|
ss2f.clear(); |
|
|
ss2f.clear(); |
|
|
ss2f << buf; |
|
|
ss2f << buf; |
|
|
ss2f >> temp[i]; |
|
|
|
|
|
i++; |
|
|
|
|
|
|
|
|
ss2f >> temp[argc]; |
|
|
|
|
|
argc++; |
|
|
} |
|
|
} |
|
|
if (i<15-1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// check for exactly 15 parameters
|
|
|
|
|
|
if (argc!=15) |
|
|
{ |
|
|
{ |
|
|
client.Send(SVR_FALSE_RSP); |
|
|
client.Send(SVR_FALSE_RSP); |
|
|
return ; |
|
|
return ; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// the position is saved in the first parameter part
|
|
|
|
|
|
MatCarthesian newCartPos(0.0f,1.0f); |
|
|
for (int i=0 ;i<3; i++) |
|
|
for (int i=0 ;i<3; i++) |
|
|
{ |
|
|
{ |
|
|
for (int j=0;j<4;j++) |
|
|
for (int j=0;j<4;j++) |
|
|
{ |
|
|
{ |
|
|
MSRCMDPOSE[i][j]=temp[i*4+j]; |
|
|
|
|
|
|
|
|
newCartPos(i,j)=temp[i*4+j]; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// extract elbow flip and hand parameter
|
|
|
float arg[3]; |
|
|
float arg[3]; |
|
|
for (int i=0;i<3;i++) |
|
|
for (int i=0;i<3;i++) |
|
|
{ |
|
|
{ |
|
|
arg[i] = temp[12+i]; |
|
|
arg[i] = temp[12+i]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//Backward Calculation
|
|
|
|
|
|
|
|
|
|
|
|
double* CalcJoints=NULL; |
|
|
|
|
|
CalcJoints = kukaBackwardCalc(temp, arg); |
|
|
|
|
|
|
|
|
//Backward Calculation of the position
|
|
|
|
|
|
VecJoint CalcJoints = kukaBackwardCalc(temp, arg); |
|
|
|
|
|
|
|
|
//Check for Joint Range
|
|
|
|
|
|
if (!checkJntRange(CalcJoints)) |
|
|
|
|
|
|
|
|
//Check for a valid joint range
|
|
|
|
|
|
if (!SvrData::getInstance()->checkJointRange(CalcJoints)) |
|
|
{ |
|
|
{ |
|
|
string out = "Error: Joints out of Range!"; |
|
|
|
|
|
client.Send(out); |
|
|
|
|
|
|
|
|
client.Send(SVR_OUT_OF_RANGE); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Set global Position
|
|
|
|
|
|
__MSRSETPOS = true; |
|
|
|
|
|
globi = 1; |
|
|
|
|
|
for (int i=0 ;i<LBR_MNJ; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
MSRCMDJNTPOS[i]=CalcJoints[i]; |
|
|
|
|
|
} |
|
|
|
|
|
__MSRSETPOS = false; |
|
|
|
|
|
sleep(5); |
|
|
|
|
|
globi = 0; |
|
|
|
|
|
//__MSRCMDJNTPOS = true;
|
|
|
|
|
|
|
|
|
// calculate new trajectory for next position
|
|
|
|
|
|
|
|
|
////Wait to end of movement
|
|
|
|
|
|
//while (1)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// if (!__MSRCMDJNTPOS)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// break;
|
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
// set new commanded Position for next Trajectory
|
|
|
|
|
|
SvrData::getInstance()->setCommandedJointPos(CalcJoints); |
|
|
|
|
|
|
|
|
|
|
|
//Wait to end of movement
|
|
|
|
|
|
|
|
|
|
|
|
// send positive client feedback
|
|
|
client.Send(SVR_TRUE_RSP); |
|
|
client.Send(SVR_TRUE_RSP); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -895,7 +919,7 @@ void SvrHandling::SetJoints(SocketObject& client, string& args) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//Check for Joint Range
|
|
|
//Check for Joint Range
|
|
|
if (!checkJntRange(newJointPos)) |
|
|
|
|
|
|
|
|
if (!SvrData::getInstance()->checkJointRange(newJointPos)) |
|
|
{ |
|
|
{ |
|
|
client.Send(SVR_OUT_OF_RANGE); |
|
|
client.Send(SVR_OUT_OF_RANGE); |
|
|
return; |
|
|
return; |
|
@ -906,28 +930,29 @@ void SvrHandling::SetJoints(SocketObject& client, string& args) |
|
|
|
|
|
|
|
|
// set new trajectory
|
|
|
// set new trajectory
|
|
|
|
|
|
|
|
|
// Set new target Position and also calculate cart pos
|
|
|
|
|
|
|
|
|
// Set new target Position and also calculate Cartesian position
|
|
|
SvrData::getInstance()->setCommandedJointPos(newJointPos); |
|
|
SvrData::getInstance()->setCommandedJointPos(newJointPos); |
|
|
// TODO calculate and calculate position in Cartesian coordinates
|
|
|
// TODO calculate and calculate position in Cartesian coordinates
|
|
|
|
|
|
|
|
|
// wait till position is reached
|
|
|
// wait till position is reached
|
|
|
|
|
|
|
|
|
// return positiv response to client
|
|
|
|
|
|
|
|
|
// return positive response to client
|
|
|
client.Send(SVR_TRUE_RSP); |
|
|
client.Send(SVR_TRUE_RSP); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void SvrHandling::MoveCartesian(SocketObject& client, string& args) |
|
|
void SvrHandling::MoveCartesian(SocketObject& client, string& args) |
|
|
{ |
|
|
{ |
|
|
__SVR_CURRENT_JOB = true; |
|
|
|
|
|
string buf; |
|
|
string buf; |
|
|
float temp[15]; |
|
|
float temp[15]; |
|
|
stringstream ss(args); |
|
|
stringstream ss(args); |
|
|
stringstream ss2f; |
|
|
stringstream ss2f; |
|
|
int i = 0; |
|
|
|
|
|
|
|
|
int argc = 0; |
|
|
|
|
|
|
|
|
|
|
|
// convert Cartesian coordinates from string into float
|
|
|
while (ss >> buf) |
|
|
while (ss >> buf) |
|
|
{ |
|
|
{ |
|
|
if (i>15-1) |
|
|
|
|
|
|
|
|
// only need maximum 16 coordinates for a homogeneous matrix
|
|
|
|
|
|
if (argc>=15) |
|
|
{ |
|
|
{ |
|
|
client.Send(SVR_FALSE_RSP); |
|
|
client.Send(SVR_FALSE_RSP); |
|
|
return; |
|
|
return; |
|
@ -935,10 +960,12 @@ void SvrHandling::MoveCartesian(SocketObject& client, string& args) |
|
|
ss2f.flush(); |
|
|
ss2f.flush(); |
|
|
ss2f.clear(); |
|
|
ss2f.clear(); |
|
|
ss2f << buf; |
|
|
ss2f << buf; |
|
|
ss2f >> temp[i]; |
|
|
|
|
|
i++; |
|
|
|
|
|
|
|
|
ss2f >> temp[argc]; |
|
|
|
|
|
argc++; |
|
|
} |
|
|
} |
|
|
if (i<15-1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// check for exactly 15 coordinates
|
|
|
|
|
|
if (argc != 15) |
|
|
{ |
|
|
{ |
|
|
client.Send(SVR_FALSE_RSP); |
|
|
client.Send(SVR_FALSE_RSP); |
|
|
return ; |
|
|
return ; |
|
@ -968,8 +995,8 @@ void SvrHandling::MoveCartesian(SocketObject& client, string& args) |
|
|
tempVec = matToVec(TRobot); |
|
|
tempVec = matToVec(TRobot); |
|
|
//tempVec = matToVec(ApRobot);
|
|
|
//tempVec = matToVec(ApRobot);
|
|
|
|
|
|
|
|
|
|
|
|
// send a positive client feedback
|
|
|
client.Send(SVR_TRUE_RSP); |
|
|
client.Send(SVR_TRUE_RSP); |
|
|
__DOUS2 = true; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void SvrHandling::quit(SocketObject& client) |
|
|
void SvrHandling::quit(SocketObject& client) |
|
@ -981,8 +1008,6 @@ void SvrHandling::quit(SocketObject& client) |
|
|
void SvrHandling::debug(SocketObject& client) |
|
|
void SvrHandling::debug(SocketObject& client) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
__DEBUG = true; |
|
|
|
|
|
|
|
|
|
|
|
//check = true;
|
|
|
//check = true;
|
|
|
//float temp[7];
|
|
|
//float temp[7];
|
|
|
//while (1){
|
|
|
//while (1){
|
|
|