Joint limits avoidance using a gradient projection approach.
#include <visp/vpConfig.h>
#include <visp/vpDebug.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <sstream>
#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;
#ifdef VISP_HAVE_X11
#elif defined(VISP_HAVE_OPENCV)
#elif defined(VISP_HAVE_GTK)
#endif
double rho = 0.15 ;
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);
}
for (unsigned int i= 6; i < 10; i++)
double beta = 1;
std::cout << " Give the parameters beta (1) : ";
std::cin >> beta ;
std::cout << "Click on a dot..." << std::endl;
std::cout << cVe <<std::endl ;
std::cout << std::endl ;
int iter = 0;
std::cout << "\nHit CTRL-C to stop the loop...\n" << std::flush;
for ( ; ; ) {
iter ++;
double h_s = 0 ;
{
de2dt = 0 ;
e2 = 0 ;
for (unsigned int i=0 ; i < 6 ; i++)
{
double S = 0 ;
if (q[i] > tQmax[i]) S = q[i] - tQmax[i] ;
if (q[i] < tQmin[i]) S = q[i] - tQmin[i] ;
double D = (Qmax[i]-Qmin[i]) ;
e2[i] = S/D ;
}
h_s = beta*h_s/2.0 ;
e2 *= beta ;
std::cout << "Cost function h_s: " << h_s << std::endl;
}
v = prim_task + sec_task;
{
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);
plot.
plot(1, 0, iter, h_s);
}
}
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