|
|
@ -24,13 +24,13 @@ |
|
|
|
friRemote.cpp |
|
|
|
|
|
|
|
NOTE: This sample, as the corresponding FRI (Fast Research inteface) is subject to radical change |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[FH]}} |
|
|
|
*/ |
|
|
|
/**
|
|
|
|
\addtogroup friRemoteLib |
|
|
|
\brief Library for FRI (FastResearchInterface) |
|
|
|
\addtogroup friRemoteLib |
|
|
|
\brief Library for FRI (FastResearchInterface) |
|
|
|
*/ |
|
|
|
/* @{ */ |
|
|
|
|
|
|
@ -47,32 +47,32 @@ |
|
|
|
|
|
|
|
friRemote::friRemote(int port,char *hintToRemoteHost):remote(port,hintToRemoteHost) |
|
|
|
{ |
|
|
|
//std::cout << __FUNCTION__ << " " <<port <<std::endl;
|
|
|
|
//std::cout << "FRI Version " << FRI_MAJOR_VERSION << "." << FRI_SUB_VERSION << "." <<FRI_DATAGRAM_ID_CMD << "." <<FRI_DATAGRAM_ID_MSR << std::endl;
|
|
|
|
memset((void*)(& msr),0x0,sizeof(msr)); |
|
|
|
memset((void*)(& cmd), 0x0,sizeof(cmd)); |
|
|
|
{ |
|
|
|
// do checks, whether the interface - and the host meets the requirements
|
|
|
|
FRI_PREPARE_CHECK_BYTE_ORDER; |
|
|
|
if (!FRI_CHECK_BYTE_ORDER_OK) |
|
|
|
{ |
|
|
|
std::cerr << __FUNCTION__<<"Byte order on your system is not appropriate - expect deep trouble" << std::endl; |
|
|
|
} |
|
|
|
if (!FRI_CHECK_SIZES_OK) |
|
|
|
{ |
|
|
|
std::cout << __FUNCTION__<<"Sizes of datastructures not appropriate - expect even deeper trouble" << std::endl; |
|
|
|
} |
|
|
|
} |
|
|
|
//std::cout << __FUNCTION__ << " " <<port <<std::endl;
|
|
|
|
//std::cout << "FRI Version " << FRI_MAJOR_VERSION << "." << FRI_SUB_VERSION << "." <<FRI_DATAGRAM_ID_CMD << "." <<FRI_DATAGRAM_ID_MSR << std::endl;
|
|
|
|
memset((void*)(& msr),0x0,sizeof(msr)); |
|
|
|
memset((void*)(& cmd), 0x0,sizeof(cmd)); |
|
|
|
{ |
|
|
|
// do checks, whether the interface - and the host meets the requirements
|
|
|
|
FRI_PREPARE_CHECK_BYTE_ORDER; |
|
|
|
if (!FRI_CHECK_BYTE_ORDER_OK) |
|
|
|
{ |
|
|
|
std::cerr << __FUNCTION__<<"Byte order on your system is not appropriate - expect deep trouble" << std::endl; |
|
|
|
} |
|
|
|
if (!FRI_CHECK_SIZES_OK) |
|
|
|
{ |
|
|
|
std::cout << __FUNCTION__<<"Sizes of datastructures not appropriate - expect even deeper trouble" << std::endl; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
friRemote::~friRemote() |
|
|
|
{ |
|
|
|
std::cout << __FUNCTION__ << " bye for now " << std::endl; |
|
|
|
std::cout << __FUNCTION__ << " bye for now " << std::endl; |
|
|
|
} |
|
|
|
|
|
|
|
int friRemote::doReceiveData() |
|
|
|
{ |
|
|
|
return remote.Recv(&msr); |
|
|
|
return remote.Recv(&msr); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -94,41 +94,41 @@ int friRemote::doSendData() |
|
|
|
*/ |
|
|
|
int friRemote::doDataExchange() |
|
|
|
{ |
|
|
|
doSendData(); |
|
|
|
return doReceiveData(); |
|
|
|
doSendData(); |
|
|
|
return doReceiveData(); |
|
|
|
} |
|
|
|
|
|
|
|
/** automatically do data exchange, if not otherwise specified */ |
|
|
|
int friRemote::doPositionControl(float newJntPosition[LBR_MNJ], bool flagDataExchange) |
|
|
|
{ |
|
|
|
// Helper, if not properly initialized or the like...
|
|
|
|
|
|
|
|
cmd.cmd.cmdFlags=FRI_CMD_JNTPOS; |
|
|
|
// Note:: If the interface is not in Command mode,
|
|
|
|
// The commands have to be "mirrored" to get in sync
|
|
|
|
// Note:: If the interface is not in Command mode,
|
|
|
|
// The commands have to be "mirrored" to get in sync
|
|
|
|
if ((getState() != FRI_STATE_CMD) || (!isPowerOn())) |
|
|
|
{ |
|
|
|
for (int i = 0; i < LBR_MNJ; i++) |
|
|
|
{ |
|
|
|
cmd.cmd.jntPos[i]=msr.data.cmdJntPos[i]+msr.data.cmdJntPosFriOffset[i]; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
// compute new values here ...
|
|
|
|
for (int i = 0; i < LBR_MNJ; i++) |
|
|
|
{ |
|
|
|
cmd.cmd.jntPos[i]=newJntPosition[i]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (flagDataExchange) |
|
|
|
{ |
|
|
|
return doDataExchange(); |
|
|
|
} |
|
|
|
return 1; |
|
|
|
// Helper, if not properly initialized or the like...
|
|
|
|
|
|
|
|
cmd.cmd.cmdFlags=FRI_CMD_JNTPOS; |
|
|
|
// Note:: If the interface is not in Command mode,
|
|
|
|
// The commands have to be "mirrored" to get in sync
|
|
|
|
// Note:: If the interface is not in Command mode,
|
|
|
|
// The commands have to be "mirrored" to get in sync
|
|
|
|
if ((getState() != FRI_STATE_CMD) || (!isPowerOn())) |
|
|
|
{ |
|
|
|
for (int i = 0; i < LBR_MNJ; i++) |
|
|
|
{ |
|
|
|
cmd.cmd.jntPos[i]=msr.data.cmdJntPos[i]+msr.data.cmdJntPosFriOffset[i]; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
// compute new values here ...
|
|
|
|
for (int i = 0; i < LBR_MNJ; i++) |
|
|
|
{ |
|
|
|
cmd.cmd.jntPos[i]=newJntPosition[i]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (flagDataExchange) |
|
|
|
{ |
|
|
|
return doDataExchange(); |
|
|
|
} |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -136,147 +136,144 @@ int friRemote::doPositionControl(float newJntPosition[LBR_MNJ], bool flagDataExc |
|
|
|
if flagDataExchange is set to false, call doDataExchange() |
|
|
|
or doReceiveData()/doSendData() on your own |
|
|
|
IN: newJntPosition - joint positions |
|
|
|
newJntStiff - joint stiffness (Spring factor) |
|
|
|
newJntDamp - joint damping (Damping factor) |
|
|
|
newJntAddTorque - additional torque |
|
|
|
newJntStiff - joint stiffness (Spring factor) |
|
|
|
newJntDamp - joint damping (Damping factor) |
|
|
|
newJntAddTorque - additional torque |
|
|
|
|
|
|
|
Note: If any of the pointers (newJntPosition, newJntStiff, newJntDamp, newJntAddTorque) is NULL, the |
|
|
|
value is ignored -> the respective cmd.cmd.cmdFlags field is set properly |
|
|
|
value is ignored -> the respective cmd.cmd.cmdFlags field is set properly |
|
|
|
Note: It is possible to change cmd.cmd.cmdFlags in monitor mode only !! |
|
|
|
*/ |
|
|
|
int friRemote::doJntImpedanceControl(const float newJntPosition[LBR_MNJ], |
|
|
|
const float newJntStiff[LBR_MNJ], |
|
|
|
const float newJntDamp[LBR_MNJ], |
|
|
|
const float newJntAddTorque[LBR_MNJ], |
|
|
|
bool flagDataExchange) |
|
|
|
const float newJntStiff[LBR_MNJ], |
|
|
|
const float newJntDamp[LBR_MNJ], |
|
|
|
const float newJntAddTorque[LBR_MNJ], |
|
|
|
bool flagDataExchange) |
|
|
|
|
|
|
|
{ |
|
|
|
// Helper, if not properly initialized or the like...
|
|
|
|
cmd.cmd.cmdFlags=0; |
|
|
|
if (newJntPosition) |
|
|
|
{ |
|
|
|
cmd.cmd.cmdFlags|=FRI_CMD_JNTPOS; |
|
|
|
// Note:: If the interface is not in Command mode,
|
|
|
|
// The commands have to be "mirrored" to get in sync
|
|
|
|
if ((getState() != FRI_STATE_CMD) || (!isPowerOn())) |
|
|
|
{ |
|
|
|
for (int i = 0; i < LBR_MNJ; i++) |
|
|
|
{ |
|
|
|
cmd.cmd.jntPos[i]=msr.data.cmdJntPos[i]+msr.data.cmdJntPosFriOffset[i]; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
// compute new values here ...
|
|
|
|
for (int i = 0; i < LBR_MNJ; i++) |
|
|
|
cmd.cmd.jntPos[i]=newJntPosition[i]; |
|
|
|
} |
|
|
|
} |
|
|
|
if (newJntStiff) |
|
|
|
{ |
|
|
|
cmd.cmd.cmdFlags|=FRI_CMD_JNTSTIFF; |
|
|
|
for (int i = 0; i < LBR_MNJ; i++) |
|
|
|
cmd.cmd.jntStiffness[i]=newJntStiff[i]; |
|
|
|
} |
|
|
|
if (newJntDamp) |
|
|
|
{ |
|
|
|
cmd.cmd.cmdFlags|=FRI_CMD_JNTDAMP; |
|
|
|
for (int i = 0; i < LBR_MNJ; i++) |
|
|
|
cmd.cmd.jntDamping[i]=newJntDamp[i]; |
|
|
|
} |
|
|
|
if (newJntAddTorque) |
|
|
|
{ |
|
|
|
cmd.cmd.cmdFlags|=FRI_CMD_JNTTRQ; |
|
|
|
for (int i = 0; i < LBR_MNJ; i++) |
|
|
|
cmd.cmd.addJntTrq[i]=newJntAddTorque[i]; |
|
|
|
} |
|
|
|
|
|
|
|
if (flagDataExchange) |
|
|
|
{ |
|
|
|
return doDataExchange(); |
|
|
|
} |
|
|
|
return 1; |
|
|
|
// Helper, if not properly initialized or the like...
|
|
|
|
cmd.cmd.cmdFlags=0; |
|
|
|
if (newJntPosition) |
|
|
|
{ |
|
|
|
cmd.cmd.cmdFlags|=FRI_CMD_JNTPOS; |
|
|
|
// Note:: If the interface is not in Command mode,
|
|
|
|
// The commands have to be "mirrored" to get in sync
|
|
|
|
if ((getState() != FRI_STATE_CMD) || (!isPowerOn())) |
|
|
|
{ |
|
|
|
for (int i = 0; i < LBR_MNJ; i++) |
|
|
|
{ |
|
|
|
cmd.cmd.jntPos[i]=msr.data.cmdJntPos[i]+msr.data.cmdJntPosFriOffset[i]; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
// compute new values here ...
|
|
|
|
for (int i = 0; i < LBR_MNJ; i++) |
|
|
|
cmd.cmd.jntPos[i]=newJntPosition[i]; |
|
|
|
} |
|
|
|
} |
|
|
|
if (newJntStiff) |
|
|
|
{ |
|
|
|
cmd.cmd.cmdFlags|=FRI_CMD_JNTSTIFF; |
|
|
|
for (int i = 0; i < LBR_MNJ; i++) |
|
|
|
cmd.cmd.jntStiffness[i]=newJntStiff[i]; |
|
|
|
} |
|
|
|
if (newJntDamp) |
|
|
|
{ |
|
|
|
cmd.cmd.cmdFlags|=FRI_CMD_JNTDAMP; |
|
|
|
for (int i = 0; i < LBR_MNJ; i++) |
|
|
|
cmd.cmd.jntDamping[i]=newJntDamp[i]; |
|
|
|
} |
|
|
|
if (newJntAddTorque) |
|
|
|
{ |
|
|
|
cmd.cmd.cmdFlags|=FRI_CMD_JNTTRQ; |
|
|
|
for (int i = 0; i < LBR_MNJ; i++) |
|
|
|
cmd.cmd.addJntTrq[i]=newJntAddTorque[i]; |
|
|
|
} |
|
|
|
|
|
|
|
if (flagDataExchange) |
|
|
|
{ |
|
|
|
return doDataExchange(); |
|
|
|
} |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
/** automatically do data exchange, if not otherwise specified
|
|
|
|
if flagDataExchange is set to false, call doDataExchange() |
|
|
|
or doReceiveData()/doSendData() on your own |
|
|
|
IN: newJntPosition - joint positions |
|
|
|
newJntStiff - joint stiffness (Spring factor) |
|
|
|
newJntDamp - joint damping (Damping factor) |
|
|
|
newJntAddTorque - additional torque |
|
|
|
|
|
|
|
Note: If any of the pointers (newJntPosition, newJntStiff, newJntDamp, newJntAddTorque) is NULL, the |
|
|
|
value is ignored -> the respective cmd.cmd.cmdFlags field is set properly |
|
|
|
Note: It is possible to change cmd.cmd.cmdFlags in monitor mode only !! |
|
|
|
*/ |
|
|
|
/** automatically do data exchange, if not otherwise specified
|
|
|
|
if flagDataExchange is set to false, call doDataExchange() |
|
|
|
or doReceiveData()/doSendData() on your own |
|
|
|
IN: newJntPosition - joint positions |
|
|
|
newJntStiff - joint stiffness (Spring factor) |
|
|
|
newJntDamp - joint damping (Damping factor) |
|
|
|
newJntAddTorque - additional torque |
|
|
|
|
|
|
|
Note: If any of the pointers (newJntPosition, newJntStiff, newJntDamp, newJntAddTorque) is NULL, the |
|
|
|
value is ignored -> the respective cmd.cmd.cmdFlags field is set properly |
|
|
|
Note: It is possible to change cmd.cmd.cmdFlags in monitor mode only !! |
|
|
|
*/ |
|
|
|
int friRemote::doCartesianImpedanceControl(const float newCartPosition[FRI_CART_FRM_DIM], |
|
|
|
const float newCartStiff[FRI_CART_VEC], |
|
|
|
const float newCartDamp[FRI_CART_VEC], |
|
|
|
const float newAddTcpFT[FRI_CART_VEC], |
|
|
|
const float newJntNullspace[LBR_MNJ], |
|
|
|
bool flagDataExchange) |
|
|
|
const float newCartStiff[FRI_CART_VEC], |
|
|
|
const float newCartDamp[FRI_CART_VEC], |
|
|
|
const float newAddTcpFT[FRI_CART_VEC], |
|
|
|
const float newJntNullspace[LBR_MNJ], |
|
|
|
bool flagDataExchange) |
|
|
|
{ |
|
|
|
|
|
|
|
// Helper, if not properly initialized or the like...
|
|
|
|
cmd.cmd.cmdFlags=0; |
|
|
|
if ( newCartPosition ) |
|
|
|
{ |
|
|
|
cmd.cmd.cmdFlags|=FRI_CMD_CARTPOS; |
|
|
|
for ( int i = 0; i < FRI_CART_FRM_DIM; i++) |
|
|
|
{ |
|
|
|
cmd.cmd.cartPos[i]=newCartPosition[i]; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if ( newCartStiff) |
|
|
|
{ |
|
|
|
cmd.cmd.cmdFlags|=FRI_CMD_CARTSTIFF; |
|
|
|
for ( int i = 0; i < FRI_CART_VEC; i++) |
|
|
|
{ |
|
|
|
cmd.cmd.cartStiffness[i]=newCartStiff[i]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
if ( newCartDamp) |
|
|
|
{ |
|
|
|
cmd.cmd.cmdFlags|=FRI_CMD_CARTDAMP; |
|
|
|
; |
|
|
|
for ( int i = 0; i < FRI_CART_VEC; i++) |
|
|
|
{ |
|
|
|
cmd.cmd.cartDamping[i]=newCartDamp[i]; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if ( newAddTcpFT) |
|
|
|
{ |
|
|
|
cmd.cmd.cmdFlags|=FRI_CMD_TCPFT; |
|
|
|
; |
|
|
|
for ( int i = 0; i < FRI_CART_VEC; i++) |
|
|
|
{ |
|
|
|
cmd.cmd.addTcpFT[i]=newAddTcpFT[i]; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (newJntNullspace) |
|
|
|
{ |
|
|
|
cmd.cmd.cmdFlags|=FRI_CMD_JNTPOS; |
|
|
|
// Note:: If the interface is not in Command mode,
|
|
|
|
// The commands have to be "mirrored" to get in sync
|
|
|
|
|
|
|
|
// compute new values here ...
|
|
|
|
for (int i = 0; i < LBR_MNJ; i++) |
|
|
|
cmd.cmd.jntPos[i]=newJntNullspace[i]; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (flagDataExchange) |
|
|
|
{ |
|
|
|
return doDataExchange(); |
|
|
|
} |
|
|
|
return 1; |
|
|
|
// Helper, if not properly initialized or the like...
|
|
|
|
cmd.cmd.cmdFlags=0; |
|
|
|
if ( newCartPosition ) |
|
|
|
{ |
|
|
|
cmd.cmd.cmdFlags|=FRI_CMD_CARTPOS; |
|
|
|
for ( int i = 0; i < FRI_CART_FRM_DIM; i++) |
|
|
|
{ |
|
|
|
cmd.cmd.cartPos[i]=newCartPosition[i]; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if ( newCartStiff) |
|
|
|
{ |
|
|
|
cmd.cmd.cmdFlags|=FRI_CMD_CARTSTIFF; |
|
|
|
for ( int i = 0; i < FRI_CART_VEC; i++) |
|
|
|
{ |
|
|
|
cmd.cmd.cartStiffness[i]=newCartStiff[i]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
if ( newCartDamp) |
|
|
|
{ |
|
|
|
cmd.cmd.cmdFlags|=FRI_CMD_CARTDAMP; |
|
|
|
for ( int i = 0; i < FRI_CART_VEC; i++) |
|
|
|
{ |
|
|
|
cmd.cmd.cartDamping[i]=newCartDamp[i]; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if ( newAddTcpFT) |
|
|
|
{ |
|
|
|
cmd.cmd.cmdFlags|=FRI_CMD_TCPFT; |
|
|
|
for ( int i = 0; i < FRI_CART_VEC; i++) |
|
|
|
{ |
|
|
|
cmd.cmd.addTcpFT[i]=newAddTcpFT[i]; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (newJntNullspace) |
|
|
|
{ |
|
|
|
cmd.cmd.cmdFlags|=FRI_CMD_JNTPOS; |
|
|
|
// Note:: If the interface is not in Command mode,
|
|
|
|
// The commands have to be "mirrored" to get in sync
|
|
|
|
|
|
|
|
// compute new values here ...
|
|
|
|
for (int i = 0; i < LBR_MNJ; i++) |
|
|
|
cmd.cmd.jntPos[i]=newJntNullspace[i]; |
|
|
|
} |
|
|
|
|
|
|
|
if (flagDataExchange) |
|
|
|
{ |
|
|
|
return doDataExchange(); |
|
|
|
} |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|