36 #include <visp3/core/vpConfig.h>
38 #ifdef VISP_HAVE_AFMA4
42 #include <sys/types.h>
45 #include <visp3/core/vpDebug.h>
46 #include <visp3/core/vpExponentialMap.h>
47 #include <visp3/core/vpIoTools.h>
48 #include <visp3/core/vpThetaUVector.h>
49 #include <visp3/core/vpVelocityTwistMatrix.h>
50 #include <visp3/robot/vpRobotAfma4.h>
51 #include <visp3/robot/vpRobotException.h>
58 bool vpRobotAfma4::robotAlreadyCreated =
false;
80 void emergencyStopAfma4(
int signo)
82 std::cout <<
"Stop the Afma4 application by signal (" << signo <<
"): " << (char)7;
85 std::cout <<
"SIGINT (stop by ^C) " << std::endl;
88 std::cout <<
"SIGBUS (stop due to a bus error) " << std::endl;
91 std::cout <<
"SIGSEGV (stop due to a segmentation fault) " << std::endl;
94 std::cout <<
"SIGKILL (stop by CTRL \\) " << std::endl;
97 std::cout <<
"SIGQUIT " << std::endl;
100 std::cout << signo << std::endl;
104 PrimitiveSTOP_Afma4();
105 std::cout <<
"Robot was stopped\n";
110 fprintf(stdout,
"Application ");
112 kill(getpid(), SIGKILL);
153 signal(SIGINT, emergencyStopAfma4);
154 signal(SIGBUS, emergencyStopAfma4);
155 signal(SIGSEGV, emergencyStopAfma4);
156 signal(SIGKILL, emergencyStopAfma4);
157 signal(SIGQUIT, emergencyStopAfma4);
161 std::cout <<
"Open communication with MotionBlox.\n";
172 vpRobotAfma4::robotAlreadyCreated =
true;
197 time_prev_getvel = 0;
198 first_time_getvel =
true;
203 first_time_getdis =
true;
206 Try(stt = InitializeConnection(
verbose_));
208 if (stt != SUCCESS) {
209 vpERROR_TRACE(
"Cannot open connection with the motionblox.");
214 Try(stt = InitializeNode_Afma4());
216 if (stt != SUCCESS) {
217 vpERROR_TRACE(
"Cannot open connection with the motionblox.");
220 Try(PrimitiveRESET_Afma4());
223 UInt32 HIPowerStatus;
225 Try(PrimitiveSTATUS_Afma4(
nullptr,
nullptr, &EStopStatus,
nullptr,
nullptr,
nullptr, &HIPowerStatus));
230 std::cout <<
"Robot status: ";
231 switch (EStopStatus) {
234 if (HIPowerStatus == 0)
235 std::cout <<
"Power is OFF" << std::endl;
237 std::cout <<
"Power is ON" << std::endl;
239 case ESTOP_ACTIVATED:
240 std::cout <<
"Emergency stop is activated" << std::endl;
243 std::cout <<
"Sorry there is an error on the emergency chain." << std::endl;
244 std::cout <<
"You have to call Adept for maintenance..." << std::endl;
247 std::cout << std::endl;
261 if (TryStt == -20001)
262 printf(
"No connection detected. Check if the robot is powered on \n"
263 "and if the firewire link exist between the MotionBlox and this "
265 else if (TryStt == -675)
266 printf(
" Timeout enabling power...\n");
270 PrimitivePOWEROFF_Afma4();
272 ShutDownConnection();
274 std::cout <<
"Cannot open connection with the motionblox..." << std::endl;
297 UInt32 HIPowerStatus;
298 Try(PrimitiveSTATUS_Afma4(
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, &HIPowerStatus));
309 ShutDownConnection();
311 vpRobotAfma4::robotAlreadyCreated =
false;
330 Try(PrimitiveSTOP_Afma4());
336 std::cout <<
"Change the control mode from velocity to position control.\n";
337 Try(PrimitiveSTOP_Afma4());
348 std::cout <<
"Change the control mode from stop to velocity control.\n";
376 Try(PrimitiveSTOP_Afma4());
381 vpERROR_TRACE(
"Cannot stop robot motion");
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(
nullptr,
nullptr, &EStopStatus,
nullptr,
nullptr,
nullptr, &HIPowerStatus));
407 if (EStopStatus == ESTOP_AUTO) {
410 else if (EStopStatus == ESTOP_MANUAL) {
413 else if (EStopStatus == ESTOP_ACTIVATED) {
415 std::cout <<
"Emergency stop is activated! \n"
416 <<
"Check the emergency stop button and push the yellow "
417 "button before continuing."
421 fprintf(stdout,
"Remaining time %us \r", nitermax - i);
426 std::cout <<
"Sorry there is an error on the emergency chain." << std::endl;
427 std::cout <<
"You have to call Adept for maintenance..." << std::endl;
429 ShutDownConnection();
434 if (EStopStatus == ESTOP_ACTIVATED)
435 std::cout << std::endl;
437 if (EStopStatus == ESTOP_ACTIVATED) {
438 std::cout <<
"Sorry, cannot power on the robot." << std::endl;
442 if (HIPowerStatus == 0) {
443 fprintf(stdout,
"Power ON the Afma4 robot\n");
446 Try(PrimitivePOWERON_Afma4());
451 vpERROR_TRACE(
"Cannot power on the robot");
470 UInt32 HIPowerStatus;
471 Try(PrimitiveSTATUS_Afma4(
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, &HIPowerStatus));
474 if (HIPowerStatus == 1) {
475 fprintf(stdout,
"Power OFF the Afma4 robot\n");
478 Try(PrimitivePOWEROFF_Afma4());
483 vpERROR_TRACE(
"Cannot power off the robot");
504 UInt32 HIPowerStatus;
505 Try(PrimitiveSTATUS_Afma4(
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, &HIPowerStatus));
508 if (HIPowerStatus == 1) {
514 vpERROR_TRACE(
"Cannot get the power status");
548 double position[this->
njoint];
552 Try(PrimitiveACQ_POS_Afma4(position, ×tamp));
556 for (
unsigned int i = 0; i <
njoint; i++)
563 vpERROR_TRACE(
"catch exception ");
595 double position[this->
njoint];
599 Try(PrimitiveACQ_POS_Afma4(position, ×tamp));
603 for (
unsigned int i = 0; i <
njoint; i++)
610 vpERROR_TRACE(
"catch exception ");
635 Try(PrimitiveACQ_POS_Afma4(position, ×tamp));
639 for (
unsigned int i = 0; i <
njoint; i++)
646 vpERROR_TRACE(
"Error caught");
763 vpERROR_TRACE(
"Robot was not in position-based control\n"
764 "Modification of the robot state");
773 "Reference frame not implemented.");
777 "Camera frame not implemented.");
781 "Mixt frame not implemented.");
785 "End-effector frame not implemented.");
792 if (position.
getRows() != this->njoint) {
793 vpERROR_TRACE(
"Positioning error: bad vector dimension.");
799 Try(PrimitiveMOVE_Afma4(position.
data, positioningVelocity));
800 Try(WaitState_Afma4(ETAT_ATTENTE_AFMA4, 1000));
803 if (TryStt == InvalidPosition || TryStt == -1023)
804 std::cout <<
" : Position out of range.\n";
806 std::cout <<
" : Unknown error (see Fabien).\n";
807 else if (error == -1)
808 std::cout <<
"Position out of range.\n";
810 if (TryStt < 0 || error < 0) {
811 vpERROR_TRACE(
"Positioning error.");
869 const double q4,
const double q5)
881 vpERROR_TRACE(
"Error caught");
923 vpERROR_TRACE(
"Bad position in \"%s\"", filename);
937 PrimitiveACQ_TIME_Afma4(×tamp);
1015 Try(PrimitiveACQ_POS_Afma4(_q, ×tamp));
1016 for (
unsigned int i = 0; i < this->
njoint; i++) {
1017 position[i] = _q[i];
1024 Try(PrimitiveACQ_POS_Afma4(_q, ×tamp));
1027 for (
unsigned int i = 0; i < this->
njoint; i++)
1040 for (
unsigned int i = 0; i < 3; i++) {
1041 position[i] = fMc[i][3];
1042 position[i + 3] = rxyz[i];
1058 vpERROR_TRACE(
"Cannot get position.");
1138 vpERROR_TRACE(
"Cannot send a velocity to the robot "
1139 "use setRobotState(vpRobot::STATE_VELOCITY_CONTROL) first) ");
1141 "Cannot send a velocity to the robot "
1142 "use setRobotState(vpRobot::STATE_VELOCITY_CONTROL) first) ");
1151 vpERROR_TRACE(
"Bad dimension of the velocity vector in camera frame");
1158 if (vel.
getRows() != this->njoint) {
1160 "velocity vector ");
1166 "in the reference frame:"
1167 "functionality not implemented");
1171 "in the mixt frame:"
1172 "functionality not implemented");
1176 "in the end-effector frame:"
1177 "functionality not implemented");
1193 for (
unsigned int i = 0; i < 3; i++) {
1206 joint_vel =
eJe * velocity;
1220 vpMatrix eJe_inverse = fJe_inverse * fVe;
1225 joint_vel = eJe_inverse * eVc * velocity;
1247 Try(PrimitiveMOVESPEED_Afma4(joint_vel.
data));
1251 if (TryStt == VelStopOnJoint) {
1252 UInt32 axisInJoint[
njoint];
1253 PrimitiveSTATUS_Afma4(
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, axisInJoint,
nullptr);
1254 for (
unsigned int i = 0; i <
njoint; i++) {
1256 std::cout <<
"\nWarning: Velocity control stopped: axis " << i + 1 <<
" on joint limit!" << std::endl;
1260 printf(
"\n%s(%d): Error %d", __FUNCTION__, TryLine, TryStt);
1261 if (TryString !=
nullptr) {
1263 printf(
" Error sentence %s\n", TryString);
1347 Try(PrimitiveACQ_POS_Afma4(q, ×tamp));
1348 time_cur = timestamp;
1350 for (
unsigned int i = 0; i < this->
njoint; i++) {
1357 if (!first_time_getvel) {
1362 cMc = fMc_prev_getvel.
inverse() * fMc_cur;
1371 velocity = (q_cur - q_prev_getvel) / (time_cur - time_prev_getvel);
1377 cMc = fMc_prev_getvel.
inverse() * fMc_cur;
1392 "functionality not implemented");
1398 "functionality not implemented");
1405 first_time_getvel =
false;
1409 fMc_prev_getvel = fMc_cur;
1412 q_prev_getvel = q_cur;
1415 time_prev_getvel = time_cur;
1419 vpERROR_TRACE(
"Cannot get velocity.");
1555 std::ifstream fd(filename.c_str(), std::ios::in);
1557 if (!fd.is_open()) {
1562 std::string key(
"R:");
1563 std::string id(
"#AFMA4 - Position");
1564 bool pos_found =
false;
1569 while (std::getline(fd, line)) {
1572 if (!(line.compare(0,
id.size(),
id) == 0)) {
1573 std::cout <<
"Error: this position file " << filename <<
" is not for Afma4 robot" << std::endl;
1577 if ((line.compare(0, 1,
"#") == 0)) {
1580 if ((line.compare(0, key.size(), key) == 0)) {
1583 if (chain.size() <
njoint + 1)
1585 if (chain.size() <
njoint + 1)
1588 std::istringstream ss(line);
1591 for (
unsigned int i = 0; i <
njoint; i++)
1606 std::cout <<
"Error: unable to find a position for Afma4 robot in " << filename << std::endl;
1640 fd = fopen(filename.c_str(),
"w");
1645 #AFMA4 - Position - Version 2.01\n\
1648 # Joint position: X : rotation of the turret in degrees (joint 1)\n\
1649 # Y : vertical translation in meters (joint 2)\n\
1650 # A : pan rotation of the camera in degrees (joint 4)\n\
1651 # B : tilt rotation of the camera in degrees (joint 5)\n\
1711 Try(PrimitiveACQ_POS_Afma4(q, ×tamp));
1712 for (
unsigned int i = 0; i <
njoint; i++) {
1716 if (!first_time_getdis) {
1719 std::cout <<
"getDisplacement() CAMERA_FRAME not implemented\n";
1724 displacement = q_cur - q_prev_getdis;
1729 std::cout <<
"getDisplacement() REFERENCE_FRAME not implemented\n";
1734 std::cout <<
"getDisplacement() MIXT_FRAME not implemented\n";
1738 std::cout <<
"getDisplacement() END_EFFECTOR_FRAME not implemented\n";
1744 first_time_getdis =
false;
1748 q_prev_getdis = q_cur;
1752 vpERROR_TRACE(
"Cannot get velocity.");
1757 #elif !defined(VISP_BUILD_SHARED_LIBS)
1759 void dummy_vpRobotAfma4() { };
Modelization of Irisa's cylindrical robot named Afma4.
void get_fJe(const vpColVector &q, vpMatrix &fJe) const
vpHomogeneousMatrix get_fMc(const vpColVector &q) const
void get_cMe(vpHomogeneousMatrix &cMe) const
void get_eJe(const vpColVector &q, vpMatrix &eJe) const
void get_fJe_inverse(const vpColVector &q, vpMatrix &fJe_inverse) const
void get_cVf(const vpColVector &q, vpVelocityTwistMatrix &cVf) const
static const unsigned int njoint
Number of joint.
void get_fMe(const vpColVector &q, vpHomogeneousMatrix &fMe) const
Type * data
Address of the first element of the data array.
unsigned int getRows() const
Implementation of column vector and the associated operations.
void resize(unsigned int i, bool flagNullify=true)
static vpColVector inverse(const vpHomogeneousMatrix &M)
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpHomogeneousMatrix inverse() const
void extract(vpRotationMatrix &R) const
static double rad(double deg)
static double deg(double rad)
Implementation of a matrix and operations on matrices.
void get_cMe(vpHomogeneousMatrix &cMe) const
void get_cVf(vpVelocityTwistMatrix &cVf) const
virtual ~vpRobotAfma4(void)
double getPositioningVelocity(void)
void getDisplacement(vpRobot::vpControlFrameType frame, vpColVector &displacement)
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &velocity) VP_OVERRIDE
void setPositioningVelocity(double velocity)
vpRobot::vpRobotStateType setRobotState(vpRobot::vpRobotStateType newState)
void move(const char *filename)
void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &position) VP_OVERRIDE
static const double defaultPositioningVelocity
void get_eJe(vpMatrix &eJe) VP_OVERRIDE
static bool readPosFile(const std::string &filename, vpColVector &q)
void get_cVe(vpVelocityTwistMatrix &cVe) const
void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position) VP_OVERRIDE
void get_fJe(vpMatrix &fJe) VP_OVERRIDE
static bool savePosFile(const std::string &filename, const vpColVector &q)
void getVelocity(const vpRobot::vpControlFrameType frame, vpColVector &velocity)
Error that can be emitted by the vpRobot class and its derivatives.
@ wrongStateError
Wrong robot state.
@ constructionError
Error from constructor.
@ positionOutOfRangeError
Position is out of range.
@ communicationError
Unable to communicate.
@ lowLevelError
Error thrown by the low level sdk.
Class that defines a generic virtual robot.
vpMatrix eJe
robot Jacobian expressed in the end-effector frame
void setVerbose(bool verbose)
virtual vpRobotStateType getRobotState(void) const
static vpColVector saturateVelocities(const vpColVector &v_in, const vpColVector &v_max, bool verbose=false)
@ STATE_POSITION_CONTROL
Initialize the position controller.
@ STATE_VELOCITY_CONTROL
Initialize the velocity controller.
@ STATE_STOP
Stops robot motion especially in velocity and acceleration control.
double getMaxRotationVelocity(void) const
vpMatrix fJe
robot Jacobian expressed in the robot reference frame available
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
double getMaxTranslationVelocity(void) const
Implementation of a rotation matrix and operations on such kind of matrices.
Implementation of a rotation vector as Euler angle minimal representation.
vpRxyzVector & buildFrom(const vpRotationMatrix &R)
Class that consider the case of a translation vector.
vpVelocityTwistMatrix & buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)