38 #include <visp3/core/vpConfig.h>
40 #ifdef VISP_HAVE_AFMA4
44 #include <sys/types.h>
47 #include <visp3/robot/vpRobotException.h>
48 #include <visp3/core/vpExponentialMap.h>
49 #include <visp3/core/vpDebug.h>
50 #include <visp3/core/vpVelocityTwistMatrix.h>
51 #include <visp3/core/vpThetaUVector.h>
52 #include <visp3/robot/vpRobotAfma4.h>
58 bool vpRobotAfma4::robotAlreadyCreated =
false;
81 void emergencyStopAfma4(
int signo)
83 std::cout <<
"Stop the Afma4 application by signal ("
84 << signo <<
"): " << (char)7 ;
88 std::cout <<
"SIGINT (stop by ^C) " << std::endl ; break ;
90 std::cout <<
"SIGBUS (stop due to a bus error) " << std::endl ; break ;
92 std::cout <<
"SIGSEGV (stop due to a segmentation fault) " << std::endl ; break ;
94 std::cout <<
"SIGKILL (stop by CTRL \\) " << std::endl ; break ;
96 std::cout <<
"SIGQUIT " << std::endl ; break ;
98 std::cout << signo << std::endl ;
102 PrimitiveSTOP_Afma4();
103 std::cout <<
"Robot was stopped\n";
108 fprintf(stdout,
"Application ");
110 kill(getpid(), SIGKILL);
130 vpRobotAfma4::vpRobotAfma4 (
bool verbose)
155 signal(SIGINT, emergencyStopAfma4);
156 signal(SIGBUS, emergencyStopAfma4) ;
157 signal(SIGSEGV, emergencyStopAfma4) ;
158 signal(SIGKILL, emergencyStopAfma4);
159 signal(SIGQUIT, emergencyStopAfma4);
163 std::cout <<
"Open communication with MotionBlox.\n";
174 vpRobotAfma4::robotAlreadyCreated =
true;
201 time_prev_getvel = 0;
202 first_time_getvel =
true;
207 first_time_getdis =
true;
210 Try( stt = InitializeConnection(
verbose_) );
212 if (stt != SUCCESS) {
213 vpERROR_TRACE (
"Cannot open connexion with the motionblox.");
215 "Cannot open connexion with the motionblox");
219 Try( stt = InitializeNode_Afma4() );
221 if (stt != SUCCESS) {
222 vpERROR_TRACE (
"Cannot open connexion with the motionblox.");
224 "Cannot open connexion with the motionblox");
226 Try( PrimitiveRESET_Afma4() );
229 UInt32 HIPowerStatus;
231 Try( PrimitiveSTATUS_Afma4(NULL, NULL, &EStopStatus, NULL, NULL, NULL,
237 std::cout <<
"Robot status: ";
238 switch(EStopStatus) {
241 if (HIPowerStatus == 0)
242 std::cout <<
"Power is OFF" << std::endl;
244 std::cout <<
"Power is ON" << std::endl;
246 case ESTOP_ACTIVATED:
247 std::cout <<
"Emergency stop is activated" << std::endl;
250 std::cout <<
"Sorry there is an error on the emergency chain." << std::endl;
251 std::cout <<
"You have to call Adept for maintenance..." << std::endl;
254 std::cout << std::endl;
267 if (TryStt == -20001)
268 printf(
"No connection detected. Check if the robot is powered on \n"
269 "and if the firewire link exist between the MotionBlox and this computer.\n");
270 else if (TryStt == -675)
271 printf(
" Timeout enabling power...\n");
275 PrimitivePOWEROFF_Afma4();
277 ShutDownConnection();
279 std::cout <<
"Cannot open connexion with the motionblox..." << std::endl;
281 "Cannot open connexion with the motionblox");
304 UInt32 HIPowerStatus;
305 Try( PrimitiveSTATUS_Afma4(NULL, NULL, NULL, NULL, NULL, NULL,
317 ShutDownConnection();
319 vpRobotAfma4::robotAlreadyCreated =
false;
343 Try( PrimitiveSTOP_Afma4() );
349 std::cout <<
"Change the control mode from velocity to position control.\n";
350 Try( PrimitiveSTOP_Afma4() );
360 std::cout <<
"Change the control mode from stop to velocity control.\n";
389 Try( PrimitiveSTOP_Afma4() );
396 "Cannot stop robot motion.");
416 UInt32 HIPowerStatus;
418 bool firsttime =
true;
419 unsigned int nitermax = 10;
421 for (
unsigned int i=0; i<nitermax; i++) {
422 Try( PrimitiveSTATUS_Afma4(NULL, NULL, &EStopStatus, NULL, NULL, NULL,
424 if (EStopStatus == ESTOP_AUTO) {
427 else if (EStopStatus == ESTOP_MANUAL) {
430 else if (EStopStatus == ESTOP_ACTIVATED) {
432 std::cout <<
"Emergency stop is activated! \n"
433 <<
"Check the emergency stop button and push the yellow button before continuing." << std::endl;
436 fprintf(stdout,
"Remaining time %ds \r", nitermax-i);
441 std::cout <<
"Sorry there is an error on the emergency chain." << std::endl;
442 std::cout <<
"You have to call Adept for maintenance..." << std::endl;
444 ShutDownConnection();
449 if (EStopStatus == ESTOP_ACTIVATED)
450 std::cout << std::endl;
452 if (EStopStatus == ESTOP_ACTIVATED) {
453 std::cout <<
"Sorry, cannot power on the robot." << std::endl;
455 "Cannot power on the robot.");
458 if (HIPowerStatus == 0) {
459 fprintf(stdout,
"Power ON the Afma4 robot\n");
462 Try( PrimitivePOWERON_Afma4() );
469 "Cannot power off the robot.");
488 UInt32 HIPowerStatus;
489 Try( PrimitiveSTATUS_Afma4(NULL, NULL, NULL, NULL, NULL, NULL,
493 if (HIPowerStatus == 1) {
494 fprintf(stdout,
"Power OFF the Afma4 robot\n");
497 Try( PrimitivePOWEROFF_Afma4() );
504 "Cannot power off the robot.");
525 UInt32 HIPowerStatus;
526 Try( PrimitiveSTATUS_Afma4(NULL, NULL, NULL, NULL, NULL, NULL,
530 if (HIPowerStatus == 1) {
538 "Cannot get the power status.");
573 double position[this->
njoint];
577 Try( PrimitiveACQ_POS_Afma4(position, ×tamp) );
581 for (
unsigned int i=0; i <
njoint; i++)
624 double position[this->
njoint];
628 Try( PrimitiveACQ_POS_Afma4(position, ×tamp) );
632 for (
unsigned int i=0; i <
njoint; i++)
664 Try( PrimitiveACQ_POS_Afma4(position, ×tamp) );
668 for (
unsigned int i=0; i <
njoint; i++)
710 positioningVelocity = velocity;
721 return positioningVelocity;
803 "Modification of the robot state");
811 vpERROR_TRACE (
"Positionning error. Reference frame not implemented");
813 "Positionning error: "
814 "Reference frame not implemented.");
817 vpERROR_TRACE (
"Positionning error. Camera frame not implemented");
819 "Positionning error: "
820 "Camera frame not implemented.");
823 vpERROR_TRACE (
"Positionning error. Mixt frame not implemented");
825 "Positionning error: "
826 "Mixt frame not implemented.");
837 "Positionning error: bad vector dimension.");
842 Try( PrimitiveMOVE_Afma4(position.
data, positioningVelocity) );
843 Try( WaitState_Afma4(ETAT_ATTENTE_AFMA4, 1000) );
846 if (TryStt == InvalidPosition || TryStt == -1023)
847 std::cout <<
" : Position out of range.\n";
849 std::cout <<
" : Unknown error (see Fabien).\n";
850 else if (error == -1)
851 std::cout <<
"Position out of range.\n";
853 if (TryStt < 0 || error < 0) {
856 "Position out of range.");
976 "Bad position in filename.");
988 PrimitiveACQ_TIME_Afma4(×tamp);
1067 Try( PrimitiveACQ_POS_Afma4(_q, ×tamp) );
1068 for (
unsigned int i=0; i < this->
njoint; i ++) {
1069 position[i] = _q[i];
1076 Try( PrimitiveACQ_POS_Afma4(_q, ×tamp) );
1079 for (
unsigned int i=0; i < this->
njoint; i++)
1092 for (
unsigned int i=0; i < 3; i++) {
1093 position[i] = fMc[i][3];
1094 position[i+3] = rxyz[i];
1099 vpERROR_TRACE (
"Cannot get position in mixt frame: not implemented");
1101 "Cannot get position in mixt frame: "
1111 "Cannot get position.");
1187 "use setRobotState(vpRobot::STATE_VELOCITY_CONTROL) first) ");
1189 "Cannot send a velocity to the robot "
1190 "use setRobotState(vpRobot::STATE_VELOCITY_CONTROL) first) ");
1199 vpERROR_TRACE (
"Bad dimension of the velocity vector in camera frame");
1201 "Bad dimension of the velocity vector "
1208 vpERROR_TRACE (
"Bad dimension of the articular velocity vector");
1210 "Bad dimension of the articular "
1211 "velocity vector ");
1217 "in the reference frame: "
1218 "functionality not implemented");
1220 "Cannot send a velocity to the robot "
1221 "in the reference frame:"
1222 "functionality not implemented");
1227 "in the mixt frame: "
1228 "functionality not implemented");
1230 "Cannot send a velocity to the robot "
1231 "in the mixt frame:"
1232 "functionality not implemented");
1237 "Case not taken in account.");
1239 "Cannot send a velocity to the robot ");
1253 for (
unsigned int i=0; i<3; i++) {
1266 joint_vel = eJe * velocity;
1280 vpMatrix eJe_inverse = fJe_inverse * fVe;
1285 joint_vel = eJe_inverse * eVc * velocity;
1307 Try( PrimitiveMOVESPEED_Afma4(joint_vel.
data) );
1311 if (TryStt == VelStopOnJoint) {
1312 UInt32 axisInJoint[
njoint];
1313 PrimitiveSTATUS_Afma4(NULL, NULL, NULL, NULL, NULL, axisInJoint, NULL);
1314 for (
unsigned int i=0; i <
njoint; i ++) {
1316 std::cout <<
"\nWarning: Velocity control stopped: axis "
1317 << i+1 <<
" on joint limit!" <<std::endl;
1321 printf(
"\n%s(%d): Error %d", __FUNCTION__, TryLine, TryStt);
1322 if (TryString != NULL) {
1324 printf(
" Error sentence %s\n", TryString);
1410 Try( PrimitiveACQ_POS_Afma4(q, ×tamp) );
1411 time_cur = timestamp;
1413 for (
unsigned int i=0; i < this->
njoint; i ++) {
1420 if ( ! first_time_getvel ) {
1425 cMc = fMc_prev_getvel.
inverse() * fMc_cur;
1434 velocity = (q_cur - q_prev_getvel) / (time_cur - time_prev_getvel);
1440 cMc = fMc_prev_getvel.
inverse() * fMc_cur;
1455 "functionality not implemented");
1457 "Cannot get a displacement in the mixt frame:"
1458 "functionality not implemented");
1465 first_time_getvel =
false;
1469 fMc_prev_getvel = fMc_cur;
1472 q_prev_getvel = q_cur;
1475 time_prev_getvel = time_cur;
1482 "Cannot get velocity.");
1623 fd = fopen(filename,
"r") ;
1627 char line[FILENAME_MAX];
1628 char dummy[FILENAME_MAX];
1630 bool sortie =
false;
1634 if (fgets (line, FILENAME_MAX, fd) != NULL) {
1635 if ( strncmp (line,
"#", 1) != 0) {
1637 if ( strncmp (line, head,
sizeof(head)-1) == 0) {
1649 while ( sortie !=
true );
1653 sscanf(line,
"%s %lf %lf %lf %lf",
1655 &q[0], &q[1], &q[2], &q[3]);
1695 fd = fopen(filename,
"w") ;
1700 #AFMA4 - Position - Version 2.01\n\
1703 # Joint position: X : rotation of the turret in degrees (joint 1)\n\
1704 # Y : vertical translation in meters (joint 2)\n\
1705 # A : pan rotation of the camera in degrees (joint 4)\n\
1706 # B : tilt rotation of the camera in degrees (joint 5)\n\
1710 fprintf(fd,
"R: %lf %lf %lf %lf\n",
1755 vpRobotAfma4::getCameraDisplacement(
vpColVector &displacement)
1771 vpRobotAfma4::getArticularDisplacement(
vpColVector &displacement)
1810 Try( PrimitiveACQ_POS_Afma4(q, ×tamp) );
1811 for (
unsigned int i=0; i <
njoint; i ++) {
1815 if ( ! first_time_getdis ) {
1818 std::cout <<
"getDisplacement() CAMERA_FRAME not implemented\n";
1824 displacement = q_cur - q_prev_getdis;
1829 std::cout <<
"getDisplacement() REFERENCE_FRAME not implemented\n";
1835 std::cout <<
"getDisplacement() MIXT_FRAME not implemented\n";
1842 first_time_getdis =
false;
1846 q_prev_getdis = q_cur;
1852 "Cannot get velocity.");
1856 #elif !defined(VISP_BUILD_SHARED_LIBS)
1858 void dummy_vpRobotAfma4() {};
static vpColVector inverse(const vpHomogeneousMatrix &M)
Implementation of a matrix and operations on matrices.
vpRxyzVector buildFrom(const vpRotationMatrix &R)
vpHomogeneousMatrix get_fMc(const vpColVector &q) const
Error that can be emited by the vpRobot class and its derivates.
void get_fMe(const vpColVector &q, vpHomogeneousMatrix &fMe) const
void get_cMe(vpHomogeneousMatrix &cMe) const
static bool savePosFile(const char *filename, const vpColVector &q)
Implementation of an homogeneous matrix and operations on such kind of matrices.
void setVerbose(bool verbose)
virtual ~vpRobotAfma4(void)
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &velocity)
double getMaxTranslationVelocity(void) const
Initialize the position controller.
class that defines a generic virtual robot
static vpColVector saturateVelocities(const vpColVector &v_in, const vpColVector &v_max, bool verbose=false)
Type * data
Address of the first element of the data array.
void get_cVf(const vpColVector &q, vpVelocityTwistMatrix &cVf) const
double getMaxRotationVelocity(void) const
void move(const char *filename)
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
void get_eJe(const vpColVector &q, vpMatrix &eJe) const
Implementation of a rotation matrix and operations on such kind of matrices.
void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &position)
void get_cMe(vpHomogeneousMatrix &cMe) const
Initialize the velocity controller.
void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position)
void setPositioningVelocity(const double velocity)
vpVelocityTwistMatrix buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
static const unsigned int njoint
Number of joint.
Modelisation of Irisa's cylindrical robot named Afma4.
void extract(vpRotationMatrix &R) const
Implementation of a velocity twist matrix and operations on such kind of matrices.
unsigned int getRows() const
Return the number of rows of the 2D array.
static double rad(double deg)
void get_eJe(vpMatrix &eJe)
static bool readPosFile(const char *filename, vpColVector &q)
vpRobot::vpRobotStateType setRobotState(vpRobot::vpRobotStateType newState)
static double deg(double rad)
vpMatrix eJe
robot Jacobian expressed in the end-effector frame
void getDisplacement(vpRobot::vpControlFrameType frame, vpColVector &displacement)
Implementation of column vector and the associated operations.
vpHomogeneousMatrix inverse() const
void getVelocity(const vpRobot::vpControlFrameType frame, vpColVector &velocity)
void get_fJe_inverse(const vpColVector &q, vpMatrix &fJe_inverse) const
virtual vpRobotStateType getRobotState(void) const
void get_fJe(vpMatrix &fJe)
Implementation of a rotation vector as Euler angle minimal representation.
void get_fJe(const vpColVector &q, vpMatrix &fJe) const
double getPositioningVelocity(void)
void get_cVf(vpVelocityTwistMatrix &cVf) const
void get_cVe(vpVelocityTwistMatrix &cVe) const
static const double defaultPositioningVelocity
Class that consider the case of a translation vector.
void resize(const unsigned int i, const bool flagNullify=true)