Test Haption Virtuose SDK wrapper to constrain movements inside a cube of pre-determined side. Hard springs are applied to rotations (only translations are allowed).
#include <visp3/core/vpTime.h>
#include <visp3/robot/vpVirtuose.h>
#if defined(VISP_HAVE_VIRTUOSE)
#ifdef ENABLE_VISP_NAMESPACE
#endif
void CallBackVirtuose(VirtContext VC, void *ptr)
{
(void)VC;
static bool firstIteration = true;
int force_limit = 15;
int force_increase_rate = 500;
float cube_size = 0.05f;
double virtualStiffnessAng = 20;
double virtualDamperAng = 0.182;
double virtualDamperAng2 = 0.0456;
double alpha;
if (firstIteration) {
localPosition0 = localPosition;
firstIteration = false;
}
pee = localPosition;
zd[0] = pee[0];
zd[1] = pee[1];
xd[2] = 1;
Qd[0][0] = xd[0];
Qd[1][0] = xd[1];
Qd[2][0] = xd[2];
Qd[0][1] = yd[0];
Qd[1][1] = yd[1];
Qd[2][1] = yd[2];
Qd[0][2] = zd[0];
Qd[1][2] = zd[1];
Qd[2][2] = zd[2];
veed = dVMb * vee;
omegad[0] = veed[3];
omegad[1] = veed[4];
omegad[2] = veed[5];
zYZ[1] = zeed[1];
zYZ[2] = zeed[2];
zXZ[0] = zeed[0];
zXZ[2] = zeed[2];
vpColVector forceStiff1 = virtualStiffnessAng * rotzYZ;
for (unsigned int i = 0; i < 3; i++)
torque1[i] = forceStiff1[i] - forceDamp1[i];
vpColVector forceStiff2 = virtualStiffnessAng * rotzXZ;
for (unsigned int i = 0; i < 3; i++)
torque2[i] = forceStiff2[i] - forceDamp2[i];
xXY[0] = xeed[0];
xXY[1] = xeed[1];
xdd[0] = 1;
zdd[2] = 1;
alpha = asin(rotxXY[2]);
vpColVector forceStiff3 = virtualStiffnessAng * alpha * zdd;
vpColVector forceDamp3 = virtualDamperAng2 * (omegad * zdd) * zdd;
for (unsigned int i = 0; i < 3; i++)
torque3[i] = forceStiff3[i] - forceDamp3[i];
for (unsigned int j = 0; j < 3; j++)
forceEe[j + 3] = torque1[j] + torque2[j] + torque3[j];
forceEe = dFMb * forceEe;
for (unsigned int i = 0; i < 3; i++) {
p_min[i] = localPosition0[i] - cube_size / 2;
p_max[i] = localPosition0[i] + cube_size / 2;
}
for (int i = 0; i < 3; i++) {
if ((p_min[i] >= localPosition[i])) {
forceFeedback[i] = (p_min[i] - localPosition[i]) * force_increase_rate;
if (forceFeedback[i] >= force_limit)
forceFeedback[i] = force_limit;
}
else if ((p_max[i] <= localPosition[i])) {
forceFeedback[i] = (p_max[i] - localPosition[i]) * force_increase_rate;
if (forceFeedback[i] <= -force_limit)
forceFeedback[i] = -force_limit;
}
else
forceFeedback[i] = 0;
}
for (unsigned int j = 0; j < 6; j++)
finalForce[j] = forceFeedback[j] + forceEe[j];
return;
}
int main(int argc, char **argv)
{
std::string opt_ip = "localhost";
int opt_port = 5000;
for (int i = 0; i < argc; i++) {
if (std::string(argv[i]) == "--ip")
opt_ip = std::string(argv[i + 1]);
else if (std::string(argv[i]) == "--port")
opt_port = std::atoi(argv[i + 1]);
else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
std::cout << "\nUsage: " << argv[0]
<< " [--ip <localhost>] [--port <port>]"
" [--help] [-h]\n"
<< std::endl
<< "Description: " << std::endl
<< " --ip <localhost>" << std::endl
<< "\tHost IP address. Default value: \"localhost\"." << std::endl
<< std::endl
<< " --port <port>" << std::endl
<< "\tCommunication port. Default value: 5000." << std::endl
<< "\tSuggested values: " << std::endl
<< "\t- 5000 to communicate with the Virtuose." << std::endl
<< "\t- 53210 to communicate with the Virtuose equipped with the Glove." << std::endl
<< std::endl;
return EXIT_SUCCESS;
}
}
try {
std::cout << "Try to connect to " << opt_ip << " port " << opt_port << std::endl;
int counter = 0;
bool swtch = true;
while (swtch) {
if (counter >= 10) {
swtch = false;
}
counter++;
}
std::cout << "The end" << std::endl;
}
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
#else
int main()
{
std::cout << "You should install pthread and/or Virtuose API to use this "
"binary..."
<< std::endl;
return EXIT_SUCCESS;
}
#endif
Implementation of column vector and the associated operations.
vpColVector & normalize()
static vpMatrix skew(const vpColVector &v)
error that can be emitted by ViSP classes.
const std::string & getStringMessage() const
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpHomogeneousMatrix inverse() const
Implementation of a pose vector and operations on poses.
void extract(vpRotationMatrix &R) const
Implementation of a rotation matrix and operations on such kind of matrices.
vpColVector getCol(unsigned int j) const
vpRotationMatrix inverse() const
Class that consider the case of a translation vector.
void setIpAddressAndPort(const std::string &ip, int port)
void setForce(const vpColVector &force)
vpPoseVector getPhysicalPosition() const
void setPeriodicFunction(VirtPeriodicFunction CallBackVirt)
void stopPeriodicFunction()
void setVerbose(bool mode)
void startPeriodicFunction()
vpColVector getPhysicalVelocity() const
VISP_EXPORT void sleepMs(double t)