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)
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];
for (unsigned int i=0; i<3; i++)
torque1[i] = forceStiff1[i] - forceDamp1[i];
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()
{
try {
int counter = 0;
bool swtch = true;
while(swtch) {
if (counter>=10)
{
swtch = false;
}
counter++;
}
std::cout << "The end" << std::endl;
}
}
}
#else
int main()
{
std::cout << "You should install pthread and/or Virtuose API to use this binary..." << std::endl;
}
#endif