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/core/vpIoTools.h>
53 #include <visp3/robot/vpRobotAfma4.h>
59 bool vpRobotAfma4::robotAlreadyCreated =
false;
82 void emergencyStopAfma4(
int signo)
84 std::cout <<
"Stop the Afma4 application by signal ("
85 << signo <<
"): " << (char)7 ;
89 std::cout <<
"SIGINT (stop by ^C) " << std::endl ; break ;
91 std::cout <<
"SIGBUS (stop due to a bus error) " << std::endl ; break ;
93 std::cout <<
"SIGSEGV (stop due to a segmentation fault) " << std::endl ; break ;
95 std::cout <<
"SIGKILL (stop by CTRL \\) " << std::endl ; break ;
97 std::cout <<
"SIGQUIT " << std::endl ; break ;
99 std::cout << signo << std::endl ;
103 PrimitiveSTOP_Afma4();
104 std::cout <<
"Robot was stopped\n";
109 fprintf(stdout,
"Application ");
111 kill(getpid(), SIGKILL);
131 vpRobotAfma4::vpRobotAfma4 (
bool verbose)
156 signal(SIGINT, emergencyStopAfma4);
157 signal(SIGBUS, emergencyStopAfma4) ;
158 signal(SIGSEGV, emergencyStopAfma4) ;
159 signal(SIGKILL, emergencyStopAfma4);
160 signal(SIGQUIT, emergencyStopAfma4);
164 std::cout <<
"Open communication with MotionBlox.\n";
175 vpRobotAfma4::robotAlreadyCreated =
true;
202 time_prev_getvel = 0;
203 first_time_getvel =
true;
208 first_time_getdis =
true;
211 Try( stt = InitializeConnection(
verbose_) );
213 if (stt != SUCCESS) {
214 vpERROR_TRACE (
"Cannot open connection with the motionblox.");
216 "Cannot open connection with the motionblox");
220 Try( stt = InitializeNode_Afma4() );
222 if (stt != SUCCESS) {
223 vpERROR_TRACE (
"Cannot open connection with the motionblox.");
225 "Cannot open connection with the motionblox");
227 Try( PrimitiveRESET_Afma4() );
230 UInt32 HIPowerStatus;
232 Try( PrimitiveSTATUS_Afma4(NULL, NULL, &EStopStatus, NULL, NULL, NULL,
238 std::cout <<
"Robot status: ";
239 switch(EStopStatus) {
242 if (HIPowerStatus == 0)
243 std::cout <<
"Power is OFF" << std::endl;
245 std::cout <<
"Power is ON" << std::endl;
247 case ESTOP_ACTIVATED:
248 std::cout <<
"Emergency stop is activated" << std::endl;
251 std::cout <<
"Sorry there is an error on the emergency chain." << std::endl;
252 std::cout <<
"You have to call Adept for maintenance..." << std::endl;
255 std::cout << std::endl;
268 if (TryStt == -20001)
269 printf(
"No connection detected. Check if the robot is powered on \n"
270 "and if the firewire link exist between the MotionBlox and this computer.\n");
271 else if (TryStt == -675)
272 printf(
" Timeout enabling power...\n");
276 PrimitivePOWEROFF_Afma4();
278 ShutDownConnection();
280 std::cout <<
"Cannot open connection with the motionblox..." << std::endl;
282 "Cannot open connection with the motionblox");
305 UInt32 HIPowerStatus;
306 Try( PrimitiveSTATUS_Afma4(NULL, NULL, NULL, NULL, NULL, NULL,
318 ShutDownConnection();
320 vpRobotAfma4::robotAlreadyCreated =
false;
344 Try( PrimitiveSTOP_Afma4() );
350 std::cout <<
"Change the control mode from velocity to position control.\n";
351 Try( PrimitiveSTOP_Afma4() );
361 std::cout <<
"Change the control mode from stop to velocity control.\n";
390 Try( PrimitiveSTOP_Afma4() );
397 "Cannot stop robot motion.");
417 UInt32 HIPowerStatus;
419 bool firsttime =
true;
420 unsigned int nitermax = 10;
422 for (
unsigned int i=0; i<nitermax; i++) {
423 Try( PrimitiveSTATUS_Afma4(NULL, NULL, &EStopStatus, NULL, NULL, NULL,
425 if (EStopStatus == ESTOP_AUTO) {
428 else if (EStopStatus == ESTOP_MANUAL) {
431 else if (EStopStatus == ESTOP_ACTIVATED) {
433 std::cout <<
"Emergency stop is activated! \n"
434 <<
"Check the emergency stop button and push the yellow button before continuing." << std::endl;
437 fprintf(stdout,
"Remaining time %us \r", nitermax-i);
442 std::cout <<
"Sorry there is an error on the emergency chain." << std::endl;
443 std::cout <<
"You have to call Adept for maintenance..." << std::endl;
445 ShutDownConnection();
450 if (EStopStatus == ESTOP_ACTIVATED)
451 std::cout << std::endl;
453 if (EStopStatus == ESTOP_ACTIVATED) {
454 std::cout <<
"Sorry, cannot power on the robot." << std::endl;
456 "Cannot power on the robot.");
459 if (HIPowerStatus == 0) {
460 fprintf(stdout,
"Power ON the Afma4 robot\n");
463 Try( PrimitivePOWERON_Afma4() );
470 "Cannot power off the robot.");
489 UInt32 HIPowerStatus;
490 Try( PrimitiveSTATUS_Afma4(NULL, NULL, NULL, NULL, NULL, NULL,
494 if (HIPowerStatus == 1) {
495 fprintf(stdout,
"Power OFF the Afma4 robot\n");
498 Try( PrimitivePOWEROFF_Afma4() );
505 "Cannot power off the robot.");
526 UInt32 HIPowerStatus;
527 Try( PrimitiveSTATUS_Afma4(NULL, NULL, NULL, NULL, NULL, NULL,
531 if (HIPowerStatus == 1) {
539 "Cannot get the power status.");
574 double position[this->
njoint];
578 Try( PrimitiveACQ_POS_Afma4(position, ×tamp) );
582 for (
unsigned int i=0; i <
njoint; i++)
625 double position[this->
njoint];
629 Try( PrimitiveACQ_POS_Afma4(position, ×tamp) );
633 for (
unsigned int i=0; i <
njoint; i++)
665 Try( PrimitiveACQ_POS_Afma4(position, ×tamp) );
669 for (
unsigned int i=0; i <
njoint; i++)
711 positioningVelocity = velocity;
722 return positioningVelocity;
804 "Modification of the robot state");
812 vpERROR_TRACE (
"Positionning error. Reference frame not implemented");
814 "Positionning error: "
815 "Reference frame not implemented.");
818 vpERROR_TRACE (
"Positionning error. Camera frame not implemented");
820 "Positionning error: "
821 "Camera frame not implemented.");
824 vpERROR_TRACE (
"Positionning error. Mixt frame not implemented");
826 "Positionning error: "
827 "Mixt frame not implemented.");
838 "Positionning error: bad vector dimension.");
843 Try( PrimitiveMOVE_Afma4(position.
data, positioningVelocity) );
844 Try( WaitState_Afma4(ETAT_ATTENTE_AFMA4, 1000) );
847 if (TryStt == InvalidPosition || TryStt == -1023)
848 std::cout <<
" : Position out of range.\n";
850 std::cout <<
" : Unknown error (see Fabien).\n";
851 else if (error == -1)
852 std::cout <<
"Position out of range.\n";
854 if (TryStt < 0 || error < 0) {
857 "Position out of range.");
974 "Bad position in filename.");
986 PrimitiveACQ_TIME_Afma4(×tamp);
1065 Try( PrimitiveACQ_POS_Afma4(_q, ×tamp) );
1066 for (
unsigned int i=0; i < this->
njoint; i ++) {
1067 position[i] = _q[i];
1074 Try( PrimitiveACQ_POS_Afma4(_q, ×tamp) );
1077 for (
unsigned int i=0; i < this->
njoint; i++)
1090 for (
unsigned int i=0; i < 3; i++) {
1091 position[i] = fMc[i][3];
1092 position[i+3] = rxyz[i];
1097 vpERROR_TRACE (
"Cannot get position in mixt frame: not implemented");
1099 "Cannot get position in mixt frame: "
1108 "Cannot get position.");
1184 "use setRobotState(vpRobot::STATE_VELOCITY_CONTROL) first) ");
1186 "Cannot send a velocity to the robot "
1187 "use setRobotState(vpRobot::STATE_VELOCITY_CONTROL) first) ");
1196 vpERROR_TRACE (
"Bad dimension of the velocity vector in camera frame");
1198 "Bad dimension of the velocity vector "
1205 vpERROR_TRACE (
"Bad dimension of the articular velocity vector");
1207 "Bad dimension of the articular "
1208 "velocity vector ");
1214 "in the reference frame: "
1215 "functionality not implemented");
1217 "Cannot send a velocity to the robot "
1218 "in the reference frame:"
1219 "functionality not implemented");
1223 "in the mixt frame: "
1224 "functionality not implemented");
1226 "Cannot send a velocity to the robot "
1227 "in the mixt frame:"
1228 "functionality not implemented");
1232 "Case not taken in account.");
1234 "Cannot send a velocity to the robot ");
1248 for (
unsigned int i=0; i<3; i++) {
1261 joint_vel = eJe * velocity;
1275 vpMatrix eJe_inverse = fJe_inverse * fVe;
1280 joint_vel = eJe_inverse * eVc * velocity;
1302 Try( PrimitiveMOVESPEED_Afma4(joint_vel.
data) );
1306 if (TryStt == VelStopOnJoint) {
1307 UInt32 axisInJoint[
njoint];
1308 PrimitiveSTATUS_Afma4(NULL, NULL, NULL, NULL, NULL, axisInJoint, NULL);
1309 for (
unsigned int i=0; i <
njoint; i ++) {
1311 std::cout <<
"\nWarning: Velocity control stopped: axis "
1312 << i+1 <<
" on joint limit!" <<std::endl;
1316 printf(
"\n%s(%d): Error %d", __FUNCTION__, TryLine, TryStt);
1317 if (TryString != NULL) {
1319 printf(
" Error sentence %s\n", TryString);
1406 Try( PrimitiveACQ_POS_Afma4(q, ×tamp) );
1407 time_cur = timestamp;
1409 for (
unsigned int i=0; i < this->
njoint; i ++) {
1416 if ( ! first_time_getvel ) {
1421 cMc = fMc_prev_getvel.
inverse() * fMc_cur;
1430 velocity = (q_cur - q_prev_getvel) / (time_cur - time_prev_getvel);
1436 cMc = fMc_prev_getvel.
inverse() * fMc_cur;
1451 "functionality not implemented");
1453 "Cannot get a displacement in the mixt frame:"
1454 "functionality not implemented");
1461 first_time_getvel =
false;
1465 fMc_prev_getvel = fMc_cur;
1468 q_prev_getvel = q_cur;
1471 time_prev_getvel = time_cur;
1478 "Cannot get velocity.");
1617 std::ifstream fd(filename.c_str(), std::ios::in);
1619 if(! fd.is_open()) {
1624 std::string key(
"R:");
1625 std::string id(
"#AFMA4 - Position");
1626 bool pos_found =
false;
1631 while(std::getline(fd, line)) {
1634 if(! (line.compare(0,
id.size(), id) == 0)) {
1635 std::cout <<
"Error: this position file " << filename <<
" is not for Afma4 robot" << std::endl;
1639 if((line.compare(0, 1,
"#") == 0)) {
1642 if((line.compare(0, key.size(), key) == 0)) {
1645 if (chain.size() <
njoint+1)
1647 if(chain.size() <
njoint+1)
1650 std::istringstream ss(line);
1653 for (
unsigned int i=0; i<
njoint; i++)
1668 std::cout <<
"Error: unable to find a position for Afma4 robot in " << filename << std::endl;
1703 fd = fopen(filename.c_str(),
"w") ;
1708 #AFMA4 - Position - Version 2.01\n\
1711 # Joint position: X : rotation of the turret in degrees (joint 1)\n\
1712 # Y : vertical translation in meters (joint 2)\n\
1713 # A : pan rotation of the camera in degrees (joint 4)\n\
1714 # B : tilt rotation of the camera in degrees (joint 5)\n\
1718 fprintf(fd,
"R: %lf %lf %lf %lf\n",
1763 vpRobotAfma4::getCameraDisplacement(
vpColVector &displacement)
1779 vpRobotAfma4::getArticularDisplacement(
vpColVector &displacement)
1818 Try( PrimitiveACQ_POS_Afma4(q, ×tamp) );
1819 for (
unsigned int i=0; i <
njoint; i ++) {
1823 if ( ! first_time_getdis ) {
1826 std::cout <<
"getDisplacement() CAMERA_FRAME not implemented\n";
1831 displacement = q_cur - q_prev_getdis;
1836 std::cout <<
"getDisplacement() REFERENCE_FRAME not implemented\n";
1841 std::cout <<
"getDisplacement() MIXT_FRAME not implemented\n";
1847 first_time_getdis =
false;
1851 q_prev_getdis = q_cur;
1857 "Cannot get velocity.");
1861 #elif !defined(VISP_BUILD_SHARED_LIBS)
1863 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
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 bool readPosFile(const std::string &filename, vpColVector &q)
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 bool savePosFile(const std::string &filename, const vpColVector &q)
static double rad(double deg)
void get_eJe(vpMatrix &eJe)
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)