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");
767 "Reference frame not implemented.");
771 "Camera frame not implemented.");
775 "Mixt frame not implemented.");
779 "End-effector frame not implemented.");
793 Try(PrimitiveMOVE_Afma4(position.
data, positioningVelocity));
794 Try(WaitState_Afma4(ETAT_ATTENTE_AFMA4, 1000));
797 if (TryStt == InvalidPosition || TryStt == -1023)
798 std::cout <<
" : Position out of range.\n";
800 std::cout <<
" : Unknown error (see Fabien).\n";
801 else if (error == -1)
802 std::cout <<
"Position out of range.\n";
804 if (TryStt < 0 || error < 0) {
863 const double q4,
const double q5)
930 PrimitiveACQ_TIME_Afma4(×tamp);
1008 Try(PrimitiveACQ_POS_Afma4(_q, ×tamp));
1009 for (
unsigned int i = 0; i < this->
njoint; i++) {
1010 position[i] = _q[i];
1017 Try(PrimitiveACQ_POS_Afma4(_q, ×tamp));
1020 for (
unsigned int i = 0; i < this->
njoint; i++)
1033 for (
unsigned int i = 0; i < 3; i++) {
1034 position[i] = fMc[i][3];
1035 position[i + 3] = rxyz[i];
1132 "use setRobotState(vpRobot::STATE_VELOCITY_CONTROL) first) ");
1134 "Cannot send a velocity to the robot " 1135 "use setRobotState(vpRobot::STATE_VELOCITY_CONTROL) first) ");
1144 vpERROR_TRACE(
"Bad dimension of the velocity vector in camera frame");
1153 "velocity vector ");
1159 "in the reference frame:" 1160 "functionality not implemented");
1164 "in the mixt frame:" 1165 "functionality not implemented");
1169 "in the end-effector frame:" 1170 "functionality not implemented");
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");
1389 "functionality not implemented");
1395 first_time_getvel =
false;
1399 fMc_prev_getvel = fMc_cur;
1402 q_prev_getvel = q_cur;
1405 time_prev_getvel = time_cur;
1545 std::ifstream fd(filename.c_str(), std::ios::in);
1547 if (!fd.is_open()) {
1552 std::string key(
"R:");
1553 std::string id(
"#AFMA4 - Position");
1554 bool pos_found =
false;
1559 while (std::getline(fd, line)) {
1562 if (!(line.compare(0,
id.size(), id) == 0)) {
1563 std::cout <<
"Error: this position file " << filename <<
" is not for Afma4 robot" << std::endl;
1567 if ((line.compare(0, 1,
"#") == 0)) {
1570 if ((line.compare(0, key.size(), key) == 0)) {
1573 if (chain.size() <
njoint + 1)
1575 if (chain.size() <
njoint + 1)
1578 std::istringstream ss(line);
1581 for (
unsigned int i = 0; i <
njoint; i++)
1596 std::cout <<
"Error: unable to find a position for Afma4 robot in " << filename << std::endl;
1630 fd = fopen(filename.c_str(),
"w");
1635 #AFMA4 - Position - Version 2.01\n\ 1638 # Joint position: X : rotation of the turret in degrees (joint 1)\n\ 1639 # Y : vertical translation in meters (joint 2)\n\ 1640 # A : pan rotation of the camera in degrees (joint 4)\n\ 1641 # B : tilt rotation of the camera in degrees (joint 5)\n\ 1701 Try(PrimitiveACQ_POS_Afma4(q, ×tamp));
1702 for (
unsigned int i = 0; i <
njoint; i++) {
1706 if (!first_time_getdis) {
1709 std::cout <<
"getDisplacement() CAMERA_FRAME not implemented\n";
1714 displacement = q_cur - q_prev_getdis;
1719 std::cout <<
"getDisplacement() REFERENCE_FRAME not implemented\n";
1724 std::cout <<
"getDisplacement() MIXT_FRAME not implemented\n";
1728 std::cout <<
"getDisplacement() END_EFFECTOR_FRAME not implemented\n";
1733 first_time_getdis =
false;
1737 q_prev_getdis = q_cur;
1746 #elif !defined(VISP_BUILD_SHARED_LIBS) 1749 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)
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)
Stops robot motion especially in velocity and acceleration control.
vpRobot::vpRobotStateType setRobotState(vpRobot::vpRobotStateType newState)
void resize(unsigned int i, bool flagNullify=true)
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 setPositioningVelocity(double velocity)
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