39 #include <visp3/core/vpConfig.h> 41 #ifdef VISP_HAVE_AFMA4 45 #include <sys/types.h> 48 #include <visp3/core/vpDebug.h> 49 #include <visp3/core/vpExponentialMap.h> 50 #include <visp3/core/vpIoTools.h> 51 #include <visp3/core/vpThetaUVector.h> 52 #include <visp3/core/vpVelocityTwistMatrix.h> 53 #include <visp3/robot/vpRobotAfma4.h> 54 #include <visp3/robot/vpRobotException.h> 60 bool vpRobotAfma4::robotAlreadyCreated =
false;
82 void emergencyStopAfma4(
int signo)
84 std::cout <<
"Stop the Afma4 application by signal (" << signo <<
"): " << (char)7;
87 std::cout <<
"SIGINT (stop by ^C) " << std::endl;
90 std::cout <<
"SIGBUS (stop due to a bus error) " << std::endl;
93 std::cout <<
"SIGSEGV (stop due to a segmentation fault) " << std::endl;
96 std::cout <<
"SIGKILL (stop by CTRL \\) " << std::endl;
99 std::cout <<
"SIGQUIT " << std::endl;
102 std::cout << signo << std::endl;
106 PrimitiveSTOP_Afma4();
107 std::cout <<
"Robot was stopped\n";
112 fprintf(stdout,
"Application ");
114 kill(getpid(), SIGKILL);
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";
173 vpRobotAfma4::robotAlreadyCreated =
true;
198 time_prev_getvel = 0;
199 first_time_getvel =
true;
204 first_time_getdis =
true;
207 Try(stt = InitializeConnection(
verbose_));
209 if (stt != SUCCESS) {
210 vpERROR_TRACE(
"Cannot open connection with the motionblox.");
215 Try(stt = InitializeNode_Afma4());
217 if (stt != SUCCESS) {
218 vpERROR_TRACE(
"Cannot open connection with the motionblox.");
221 Try(PrimitiveRESET_Afma4());
224 UInt32 HIPowerStatus;
226 Try(PrimitiveSTATUS_Afma4(NULL, NULL, &EStopStatus, NULL, NULL, NULL, &HIPowerStatus));
231 std::cout <<
"Robot status: ";
232 switch (EStopStatus) {
235 if (HIPowerStatus == 0)
236 std::cout <<
"Power is OFF" << std::endl;
238 std::cout <<
"Power is ON" << std::endl;
240 case ESTOP_ACTIVATED:
241 std::cout <<
"Emergency stop is activated" << std::endl;
244 std::cout <<
"Sorry there is an error on the emergency chain." << std::endl;
245 std::cout <<
"You have to call Adept for maintenance..." << std::endl;
248 std::cout << std::endl;
262 if (TryStt == -20001)
263 printf(
"No connection detected. Check if the robot is powered on \n" 264 "and if the firewire link exist between the MotionBlox and this " 266 else if (TryStt == -675)
267 printf(
" Timeout enabling power...\n");
271 PrimitivePOWEROFF_Afma4();
273 ShutDownConnection();
275 std::cout <<
"Cannot open connection with the motionblox..." << std::endl;
298 UInt32 HIPowerStatus;
299 Try(PrimitiveSTATUS_Afma4(NULL, NULL, NULL, NULL, NULL, NULL, &HIPowerStatus));
310 ShutDownConnection();
312 vpRobotAfma4::robotAlreadyCreated =
false;
331 Try(PrimitiveSTOP_Afma4());
337 std::cout <<
"Change the control mode from velocity to position control.\n";
338 Try(PrimitiveSTOP_Afma4());
348 std::cout <<
"Change the control mode from stop to velocity control.\n";
376 Try(PrimitiveSTOP_Afma4());
400 UInt32 HIPowerStatus;
402 bool firsttime =
true;
403 unsigned int nitermax = 10;
405 for (
unsigned int i = 0; i < nitermax; i++) {
406 Try(PrimitiveSTATUS_Afma4(NULL, NULL, &EStopStatus, NULL, NULL, NULL, &HIPowerStatus));
407 if (EStopStatus == ESTOP_AUTO) {
409 }
else if (EStopStatus == ESTOP_MANUAL) {
411 }
else if (EStopStatus == ESTOP_ACTIVATED) {
413 std::cout <<
"Emergency stop is activated! \n" 414 <<
"Check the emergency stop button and push the yellow " 415 "button before continuing." 419 fprintf(stdout,
"Remaining time %us \r", nitermax - i);
423 std::cout <<
"Sorry there is an error on the emergency chain." << std::endl;
424 std::cout <<
"You have to call Adept for maintenance..." << std::endl;
426 ShutDownConnection();
431 if (EStopStatus == ESTOP_ACTIVATED)
432 std::cout << std::endl;
434 if (EStopStatus == ESTOP_ACTIVATED) {
435 std::cout <<
"Sorry, cannot power on the robot." << std::endl;
439 if (HIPowerStatus == 0) {
440 fprintf(stdout,
"Power ON the Afma4 robot\n");
443 Try(PrimitivePOWERON_Afma4());
467 UInt32 HIPowerStatus;
468 Try(PrimitiveSTATUS_Afma4(NULL, NULL, NULL, NULL, NULL, NULL, &HIPowerStatus));
471 if (HIPowerStatus == 1) {
472 fprintf(stdout,
"Power OFF the Afma4 robot\n");
475 Try(PrimitivePOWEROFF_Afma4());
501 UInt32 HIPowerStatus;
502 Try(PrimitiveSTATUS_Afma4(NULL, NULL, NULL, NULL, NULL, NULL, &HIPowerStatus));
505 if (HIPowerStatus == 1) {
545 double position[this->
njoint];
549 Try(PrimitiveACQ_POS_Afma4(position, ×tamp));
553 for (
unsigned int i = 0; i <
njoint; i++)
591 double position[this->
njoint];
595 Try(PrimitiveACQ_POS_Afma4(position, ×tamp));
599 for (
unsigned int i = 0; i <
njoint; i++)
630 Try(PrimitiveACQ_POS_Afma4(position, ×tamp));
634 for (
unsigned int i = 0; i <
njoint; i++)
758 "Modification of the robot state");
766 vpERROR_TRACE(
"Positionning error. Reference frame not implemented");
768 "Reference frame not implemented.");
771 vpERROR_TRACE(
"Positionning error. Camera frame not implemented");
773 "Camera frame not implemented.");
776 vpERROR_TRACE(
"Positionning error. Mixt frame not implemented");
778 "Mixt frame not implemented.");
792 Try(PrimitiveMOVE_Afma4(position.
data, positioningVelocity));
793 Try(WaitState_Afma4(ETAT_ATTENTE_AFMA4, 1000));
796 if (TryStt == InvalidPosition || TryStt == -1023)
797 std::cout <<
" : Position out of range.\n";
799 std::cout <<
" : Unknown error (see Fabien).\n";
800 else if (error == -1)
801 std::cout <<
"Position out of range.\n";
803 if (TryStt < 0 || error < 0) {
862 const double q4,
const double q5)
929 PrimitiveACQ_TIME_Afma4(×tamp);
1007 Try(PrimitiveACQ_POS_Afma4(_q, ×tamp));
1008 for (
unsigned int i = 0; i < this->
njoint; i++) {
1009 position[i] = _q[i];
1016 Try(PrimitiveACQ_POS_Afma4(_q, ×tamp));
1019 for (
unsigned int i = 0; i < this->
njoint; i++)
1032 for (
unsigned int i = 0; i < 3; i++) {
1033 position[i] = fMc[i][3];
1034 position[i + 3] = rxyz[i];
1039 vpERROR_TRACE(
"Cannot get position in mixt frame: not implemented");
1128 "use setRobotState(vpRobot::STATE_VELOCITY_CONTROL) first) ");
1130 "Cannot send a velocity to the robot " 1131 "use setRobotState(vpRobot::STATE_VELOCITY_CONTROL) first) ");
1140 vpERROR_TRACE(
"Bad dimension of the velocity vector in camera frame");
1148 vpERROR_TRACE(
"Bad dimension of the articular velocity vector");
1150 "velocity vector ");
1156 "in the reference frame: " 1157 "functionality not implemented");
1159 "in the reference frame:" 1160 "functionality not implemented");
1164 "in the mixt frame: " 1165 "functionality not implemented");
1167 "in the mixt frame:" 1168 "functionality not implemented");
1172 "Case not taken in account.");
1186 for (
unsigned int i = 0; i < 3; i++) {
1199 joint_vel = eJe * velocity;
1213 vpMatrix eJe_inverse = fJe_inverse * fVe;
1218 joint_vel = eJe_inverse * eVc * velocity;
1240 Try(PrimitiveMOVESPEED_Afma4(joint_vel.
data));
1244 if (TryStt == VelStopOnJoint) {
1245 UInt32 axisInJoint[
njoint];
1246 PrimitiveSTATUS_Afma4(NULL, NULL, NULL, NULL, NULL, axisInJoint, NULL);
1247 for (
unsigned int i = 0; i <
njoint; i++) {
1249 std::cout <<
"\nWarning: Velocity control stopped: axis " << i + 1 <<
" on joint limit!" << std::endl;
1252 printf(
"\n%s(%d): Error %d", __FUNCTION__, TryLine, TryStt);
1253 if (TryString != NULL) {
1255 printf(
" Error sentence %s\n", TryString);
1338 Try(PrimitiveACQ_POS_Afma4(q, ×tamp));
1339 time_cur = timestamp;
1341 for (
unsigned int i = 0; i < this->
njoint; i++) {
1348 if (!first_time_getvel) {
1353 cMc = fMc_prev_getvel.
inverse() * fMc_cur;
1362 velocity = (q_cur - q_prev_getvel) / (time_cur - time_prev_getvel);
1368 cMc = fMc_prev_getvel.
inverse() * fMc_cur;
1383 "functionality not implemented");
1385 "functionality not implemented");
1391 first_time_getvel =
false;
1395 fMc_prev_getvel = fMc_cur;
1398 q_prev_getvel = q_cur;
1401 time_prev_getvel = time_cur;
1541 std::ifstream fd(filename.c_str(), std::ios::in);
1543 if (!fd.is_open()) {
1548 std::string key(
"R:");
1549 std::string id(
"#AFMA4 - Position");
1550 bool pos_found =
false;
1555 while (std::getline(fd, line)) {
1558 if (!(line.compare(0,
id.size(), id) == 0)) {
1559 std::cout <<
"Error: this position file " << filename <<
" is not for Afma4 robot" << std::endl;
1563 if ((line.compare(0, 1,
"#") == 0)) {
1566 if ((line.compare(0, key.size(), key) == 0)) {
1569 if (chain.size() <
njoint + 1)
1571 if (chain.size() <
njoint + 1)
1574 std::istringstream ss(line);
1577 for (
unsigned int i = 0; i <
njoint; i++)
1592 std::cout <<
"Error: unable to find a position for Afma4 robot in " << filename << std::endl;
1626 fd = fopen(filename.c_str(),
"w");
1631 #AFMA4 - Position - Version 2.01\n\ 1634 # Joint position: X : rotation of the turret in degrees (joint 1)\n\ 1635 # Y : vertical translation in meters (joint 2)\n\ 1636 # A : pan rotation of the camera in degrees (joint 4)\n\ 1637 # B : tilt rotation of the camera in degrees (joint 5)\n\ 1697 Try(PrimitiveACQ_POS_Afma4(q, ×tamp));
1698 for (
unsigned int i = 0; i <
njoint; i++) {
1702 if (!first_time_getdis) {
1705 std::cout <<
"getDisplacement() CAMERA_FRAME not implemented\n";
1710 displacement = q_cur - q_prev_getdis;
1715 std::cout <<
"getDisplacement() REFERENCE_FRAME not implemented\n";
1720 std::cout <<
"getDisplacement() MIXT_FRAME not implemented\n";
1725 first_time_getdis =
false;
1729 q_prev_getdis = q_cur;
1738 #elif !defined(VISP_BUILD_SHARED_LIBS) 1741 void dummy_vpRobotAfma4(){};
static vpColVector inverse(const vpHomogeneousMatrix &M)
Implementation of a matrix and operations on matrices.
vpRxyzVector buildFrom(const vpRotationMatrix &R)
Error that can be emited by the vpRobot class and its derivates.
void get_cMe(vpHomogeneousMatrix &cMe) const
void get_cVe(vpVelocityTwistMatrix &cVe) const
Implementation of an homogeneous matrix and operations on such kind of matrices.
void setVerbose(bool verbose)
virtual ~vpRobotAfma4(void)
double getMaxTranslationVelocity(void) const
void get_fMe(const vpColVector &q, vpHomogeneousMatrix &fMe) const
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &velocity)
Initialize the position controller.
unsigned int getRows() const
vpHomogeneousMatrix inverse() const
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.
double getMaxRotationVelocity(void) const
void extract(vpRotationMatrix &R) const
void move(const char *filename)
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
Implementation of a rotation matrix and operations on such kind of matrices.
void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &position)
Initialize the velocity controller.
virtual vpRobotStateType getRobotState(void) const
void get_cMe(vpHomogeneousMatrix &cMe) const
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)
void get_fJe(const vpColVector &q, vpMatrix &fJe) const
static const unsigned int njoint
Number of joint.
Modelisation of Irisa's cylindrical robot named Afma4.
void get_fJe_inverse(const vpColVector &q, vpMatrix &fJe_inverse) const
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 get_fMc(const vpColVector &q) const
void getVelocity(const vpRobot::vpControlFrameType frame, vpColVector &velocity)
void get_fJe(vpMatrix &fJe)
void get_eJe(const vpColVector &q, vpMatrix &eJe) const
Implementation of a rotation vector as Euler angle minimal representation.
double getPositioningVelocity(void)
static const double defaultPositioningVelocity
vpMatrix fJe
robot Jacobian expressed in the robot reference frame available
Class that consider the case of a translation vector.
void get_cVf(const vpColVector &q, vpVelocityTwistMatrix &cVf) const
void get_cVf(vpVelocityTwistMatrix &cVf) const
void resize(const unsigned int i, const bool flagNullify=true)