Send a command to the car-like Cycab mobile robot.
#include <visp/vpConfig.h>
#include <iostream>
#include <cmath>
#include <limits>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#ifdef VISP_HAVE_CYCAB
#include <visp/vpRobotCycab.h>
#include <visp/vpMath.h>
#include <visp/vpTime.h>
bool bFinish = false;
bool end = false;
void sighdl(int n)
{
printf("Received signal %d\n",n);
bFinish=true;
end = true;
}
#define MAXV 1.5 // velocity in m/S
#define MAXPHI 20.0 // front steering angle in deg
#define MAX_ACC_V 6 // m/s^2
#define MAX_VEL_PHI 4 // rad/s
int main()
{
double v, phi;
double vm, phim;
int kv,kphi;
kv = kphi = 1;
v = 0.0;
phi = 0.0;
signal(SIGINT,sighdl);
signal(SIGTERM,sighdl);
signal(SIGPIPE,sighdl);
double tprev;
bool ctrc = false;
double timestamp;
while (!end) {
tprev = t1;
cycab->getOdometry(vm, phim, timestamp);
printf("State: t=%.1f s v=%f m/s and phi=%f deg\n\t",
if (1) {
v+=kv*0.002;if (fabs(v)>=MAXV) kv = -1 * kv;
phi+=kphi*0.002;
if (fabs(phi)>=
vpMath::rad(MAXPHI)) kphi = -1 * kphi;
}
else {
v=0.1;phi=0;
}
if (bFinish) {
std::cout << "Cycab stop requested" << std::endl;
double sign_v = 0;
if (std::fabs(vm) > std::numeric_limits<double>::epsilon())
sign_v = fabs(vm)/vm;
v = vm - MAX_ACC_V*(t1-tprev)/1000*sign_v;
if (fabs(v) < 0.1) v = 0;
double sign_phi = 0;
if (std::fabs(phim) > std::numeric_limits<double>::epsilon())
sign_phi = fabs(phim)/phim;
phi = phim - MAX_VEL_PHI*(t1-tprev)/1000*sign_phi;
}
printf(
"Send : v %f m/s and phi %f deg\n", v,
vpMath::deg(phi));
cycab->setCommand(v, phi);
if (end && (!ctrc)) { end = false; ctrc=true;}
}
std::cout << "The end" << std::endl;
return 0;
}
#else // VISP_HAVE_CYCAB
int main()
{
cout << "Sorry no acces to the cycab" << endl;
}
#endif //VISP_HAVE_CYCAB