Joint limits avoidance by stopping the motion on axis near the joint limits.
#include <visp/vpConfig.h>
#include <visp/vpDebug.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <cmath>
#include <limits>
#if (defined (VISP_HAVE_VIPER850) && defined (VISP_HAVE_DC1394_2) && defined(VISP_HAVE_DISPLAY))
#include <visp/vp1394TwoGrabber.h>
#include <visp/vpImage.h>
#include <visp/vpDisplay.h>
#include <visp/vpDisplayX.h>
#include <visp/vpDisplayOpenCV.h>
#include <visp/vpDisplayGTK.h>
#include <visp/vpMath.h>
#include <visp/vpHomogeneousMatrix.h>
#include <visp/vpFeaturePoint.h>
#include <visp/vpPoint.h>
#include <visp/vpServo.h>
#include <visp/vpFeatureBuilder.h>
#include <visp/vpRobotViper850.h>
#include <visp/vpIoTools.h>
#include <visp/vpException.h>
#include <visp/vpMatrixException.h>
#include <visp/vpServoDisplay.h>
#include <visp/vpDot2.h>
#include <visp/vpPlot.h>
int
main()
{
try {
bool reset = false;
double Tloop = 1./60.f;
switch(fps) {
default: break;
}
std::cout << "Tloop: " << Tloop << std::endl;
#ifdef VISP_HAVE_X11
#elif defined(VISP_HAVE_OPENCV)
#elif defined(VISP_HAVE_GTK)
#endif
double rho = 0.25 ;
for (unsigned int i=0 ; i < 6 ; i++)
{
Qmin[i] = jointMin[i] + 0.5*rho*(jointMax[i]-jointMin[i]) ;
Qmax[i] = jointMax[i] - 0.5*rho*(jointMax[i]-jointMin[i]) ;
}
Qmiddle = (Qmin + Qmax) /2.;
double rho1 = 0.1 ;
for (unsigned int i=0 ; i < 6 ; i++) {
tQmin[i]=Qmin[i]+ 0.5*(rho1)*(Qmax[i]-Qmin[i]) ;
tQmax[i]=Qmax[i]- 0.5*(rho1)*(Qmax[i]-Qmin[i]) ;
}
char legend[10];
for (unsigned int i=0; i < 6; i++) {
sprintf(legend, "q%d", i+1);
sprintf(legend, "q%d", i+1);
}
for (unsigned int i= 6; i < 10; i++)
std::cout << "Click on a dot..." << std::endl;
std::cout << cVe <<std::endl ;
std::cout << std::endl ;
double lambda = 0.8;
int iter = 0;
dc1394video_frame_t *frame = NULL;
std::cout << "\nHit CTRL-C to stop the loop...\n" << std::flush;
for ( ; ; ) {
iter ++;
Tv = (double)(t_0 - t_1) / 1000.0;
std::cout << "Tv: " << Tv << std::endl;
t_1 = t_0;
qpre = q ;
qpre += -lambda*prim_task*(4*Tloop) ;
unsigned int npb =0 ;
for (unsigned int i=0 ; i < 6 ;i++) {
if (q[i] < tQmin[i])
if (fabs(Qmin[i]-q[i]) > fabs(Qmin[i]-qpre[i])) {
pb[i] = 1 ; npb++ ;
std::cout << "Joint " << i << " near limit " << std::endl ;
}
if (q[i]>tQmax[i]) {
if (fabs(Qmax[i]-q[i]) > fabs(Qmax[i]-qpre[i])) {
pb[i] = 1 ; npb++ ;
std::cout << "Joint " << i << " near limit " << std::endl ;
}
}
}
unsigned int dimKernelL = kernelJ1.
getCols() ;
if (npb != 0) {
unsigned int k=0 ;
for (unsigned int j=0 ; j < 6 ; j++)
if (std::fabs(pb[j]-1) <= std::numeric_limits<double>::epsilon()) {
for (unsigned int i=0 ; i < dimKernelL ; i++)
E[k][i] = kernelJ1[j][i] ;
S[k] = -prim_task[j] ;
k++ ;
}
Ep = E.
t()*(E*E.
t()).pseudoInverse() ;
a0 = Ep*S ;
e2 = (kernelJ1*a0) ;
}
else {
e2 = 0;
}
v = -lambda * (prim_task + e2);
{
for (unsigned int i=0 ; i < 6 ; i++) {
data[i] = (q[i] - Qmiddle[i]) ;
data[i] /= (Qmax[i] - Qmin[i]) ;
data[i]*=2 ;
}
unsigned int joint = 2;
data[6] = 2*(tQmin[joint]-Qmiddle[joint])/(Qmax[joint] - Qmin[joint]) ;
data[7] = 2*(tQmax[joint]-Qmiddle[joint])/(Qmax[joint] - Qmin[joint]) ;
data[8] = -1 ; data[9] = 1 ;
plot.
plot(0, iter, data);
}
}
return 0;
}
catch (...)
{
return 0;
}
}
#else
int
main()
{
vpERROR_TRACE(
"You do not have an afma6 robot or a firewire framegrabber connected to your computer...");
}
#endif