|
|
@ -10,6 +10,7 @@ |
|
|
|
#include "SvrHandling.h"
|
|
|
|
#include "SvrData.h"
|
|
|
|
#include "Trajectroy.h"
|
|
|
|
#include <boost/thread/thread.hpp>
|
|
|
|
|
|
|
|
void printUsage(SocketObject& client) |
|
|
|
{ |
|
|
@ -46,7 +47,6 @@ void debugMat(Mat4f M) |
|
|
|
|
|
|
|
double* kukaBackwardCalc(double M_[12], float arg[3]) |
|
|
|
{ |
|
|
|
|
|
|
|
double* Joints = new double[7]; |
|
|
|
//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}; |
|
|
@ -460,6 +460,7 @@ void SvrHandling::handle(SocketObject& client) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
string SvrHandling::timestamp() |
|
|
|
{ |
|
|
|
time_t rawtime; |
|
|
@ -480,15 +481,18 @@ void SvrHandling::GetPositionJoints(SocketObject& client) |
|
|
|
string out = ""; |
|
|
|
stringstream ss (stringstream::in | stringstream::out); |
|
|
|
|
|
|
|
// get current joint positions from database
|
|
|
|
VecJoint jointPos = SvrData::getInstance()->getMessuredJointPos(); |
|
|
|
|
|
|
|
// disassemble command
|
|
|
|
// assemble command feadback
|
|
|
|
for (int i=0; i< JOINT_NUMBER; i++) |
|
|
|
{ |
|
|
|
ss.str(""); |
|
|
|
ss << (jointPos(i)*180/M_PI); |
|
|
|
out += ss.str() + " "; |
|
|
|
} |
|
|
|
|
|
|
|
// send msg to client
|
|
|
|
client.Send(out); |
|
|
|
} |
|
|
|
|
|
|
@ -497,17 +501,21 @@ void SvrHandling::GetPositionHomRowWise(SocketObject& client) |
|
|
|
string out = ""; |
|
|
|
stringstream ss (stringstream::in | stringstream::out); |
|
|
|
|
|
|
|
// get current Cartesianpositions from database
|
|
|
|
MatCarthesian cartPos = SvrData::getInstance()->getMessuredCartPos(); |
|
|
|
|
|
|
|
// assemble command feadback row wise
|
|
|
|
for (int i=0; i< FRI_CART_FRM_DIM; i++) |
|
|
|
{ |
|
|
|
int row = i / 4; |
|
|
|
int column = i % 4; |
|
|
|
int row = i % 4; |
|
|
|
int column = i / 4; |
|
|
|
|
|
|
|
ss.str(""); |
|
|
|
ss << (cartPos(row,column)); |
|
|
|
out += ss.str() + " "; |
|
|
|
} |
|
|
|
|
|
|
|
// send msg to client
|
|
|
|
client.Send(out); |
|
|
|
} |
|
|
|
|
|
|
@ -570,33 +578,20 @@ void SvrHandling::MovePTPJoints(SocketObject& client, string& args) |
|
|
|
VecJoint prevJointPos = SvrData::getInstance()->getCommandedJointPos(); |
|
|
|
class Trajectory<JOINT_NUMBER>* newTrajectory; |
|
|
|
|
|
|
|
// calculate number of movement steps
|
|
|
|
dMaxSpeed = maxJointLocalVelocity.celldivide(maxJointLocalAcceleration); |
|
|
|
lMaxSpeed = dMaxSpeed.cellmultiply(dMaxSpeed).cellmultiply(maxJointLocalAcceleration) * 0.5f; |
|
|
|
float sampleTimeMs = SvrData::getInstance()->getSampleTimeMs(); |
|
|
|
VecJoint maxJointVelocity = SvrData::getInstance()->getMaxVelocity(); |
|
|
|
VecJoint maxJointAcceleration = SvrData::getInstance()->getMaxAcceleration(); |
|
|
|
|
|
|
|
for (int j=0; j<JOINT_NUMBER; j++) |
|
|
|
{ |
|
|
|
if (lMaxSpeed(j) > deltaAbs(j)/(double)2.0) |
|
|
|
{ |
|
|
|
dGesamt(j) = sqrt(deltaAbs(j) / maxJointLocalAcceleration (j))*2.0; |
|
|
|
} else |
|
|
|
{ |
|
|
|
dGesamt(j) = dMaxSpeed(j)*2 + (deltaAbs(j)-lMaxSpeed(j)*2.0)/maxJointLocalVelocity(j); |
|
|
|
} |
|
|
|
} |
|
|
|
int maxSteps = ceil(dGesamt.max()); |
|
|
|
|
|
|
|
newTrajectory = new LinearJointTrajectory<JOINT_NUMBER>(steps, totalTime, newJointPos); |
|
|
|
newTrajectory = new LinearJointTrajectory<JOINT_NUMBER>(sampleTimeMs, maxJointVelocity, maxJointAcceleration, prevJointPos, newJointPos); |
|
|
|
|
|
|
|
__MSRCMDJNTPOS = true; |
|
|
|
|
|
|
|
//Wait to end of movement
|
|
|
|
while (1) |
|
|
|
{ |
|
|
|
if (!__MSRCMDJNTPOS) |
|
|
|
while (true) |
|
|
|
{ |
|
|
|
if (SvrData::getInstance()->getMovementDone() == true) |
|
|
|
break; |
|
|
|
} |
|
|
|
boost::this_thread::sleep( boost::posix_time::milliseconds(sampleTimeMs) ); |
|
|
|
} |
|
|
|
client.Send(SVR_TRUE_RSP); |
|
|
|
} |
|
|
@ -789,7 +784,8 @@ void SvrHandling::StopPotFieldMode(SocketObject& client, string& args) |
|
|
|
client.Send(SVR_TRUE_RSP); |
|
|
|
} |
|
|
|
|
|
|
|
void SvrHandling::SetPos(SocketObject& client, string& args){ |
|
|
|
void SvrHandling::SetPos(SocketObject& client, string& args) |
|
|
|
{ |
|
|
|
|
|
|
|
string buf; |
|
|
|
double temp[15]; |
|
|
@ -868,57 +864,55 @@ void SvrHandling::SetPos(SocketObject& client, string& args){ |
|
|
|
void SvrHandling::SetJoints(SocketObject& client, string& args) |
|
|
|
{ |
|
|
|
string buf; |
|
|
|
double temp[15]; |
|
|
|
VecJoint newJointPos(0.0f); |
|
|
|
stringstream ss(args); |
|
|
|
stringstream ss2f; |
|
|
|
vector<string> tokens; |
|
|
|
int i = 0; |
|
|
|
|
|
|
|
// convert to Joint vector
|
|
|
|
while (ss >> buf) |
|
|
|
{ |
|
|
|
if (i>LBR_MNJ-1) |
|
|
|
// to many input arguments or Joints
|
|
|
|
if (i>=JOINT_NUMBER) |
|
|
|
{ |
|
|
|
client.Send(SVR_FALSE_RSP); |
|
|
|
client.Send(SVR_INVALID_ARGUMENT_COUNT); |
|
|
|
return; |
|
|
|
} |
|
|
|
tokens.push_back(buf); |
|
|
|
|
|
|
|
// convert string to float
|
|
|
|
ss2f.flush(); |
|
|
|
ss2f.clear(); |
|
|
|
ss2f << buf; |
|
|
|
ss2f >> temp[i]; |
|
|
|
ss2f >> newJointPos(i); |
|
|
|
i++; |
|
|
|
} |
|
|
|
if (i<LBR_MNJ-1) |
|
|
|
|
|
|
|
// to less joint values
|
|
|
|
if (i != JOINT_NUMBER) |
|
|
|
{ |
|
|
|
client.Send(SVR_FALSE_RSP); |
|
|
|
client.Send(SVR_INVALID_ARGUMENT_COUNT); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
//Check for Joint Range
|
|
|
|
if (!checkJntRange(temp)) |
|
|
|
if (!checkJntRange(newJointPos)) |
|
|
|
{ |
|
|
|
string out = "Error: Joints out of Range!"; |
|
|
|
client.Send(out); |
|
|
|
client.Send(SVR_OUT_OF_RANGE); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// Set global Position
|
|
|
|
__MSRSETPOS = true; |
|
|
|
globi = 1; |
|
|
|
for (int i=0 ;i<LBR_MNJ; i++) |
|
|
|
{ |
|
|
|
MSRCMDJNTPOS[i]=temp[i]; |
|
|
|
} |
|
|
|
__MSRSETPOS = false; |
|
|
|
sleep(5); |
|
|
|
globi = 0; |
|
|
|
//__MSRCMDJNTPOS = true;
|
|
|
|
// calculate trajectory from last commanded joint position
|
|
|
|
VecJoint currentComandedJoint = SvrData::getInstance()->getCommandedJointPos(); |
|
|
|
|
|
|
|
////Wait to end of movement
|
|
|
|
//while (1){
|
|
|
|
// if (!__MSRCMDJNTPOS){
|
|
|
|
// break;}
|
|
|
|
//}
|
|
|
|
// set new trajectory
|
|
|
|
|
|
|
|
// Set new target Position and also calculate cart pos
|
|
|
|
SvrData::getInstance()->setCommandedJointPos(newJointPos); |
|
|
|
// TODO calculate and calculate position in Cartesian coordinates
|
|
|
|
|
|
|
|
// wait till position is reached
|
|
|
|
|
|
|
|
// return positiv response to client
|
|
|
|
client.Send(SVR_TRUE_RSP); |
|
|
|
} |
|
|
|
|
|
|
|