36 #include <visp3/core/vpConfig.h>
37 #if defined(VISP_HAVE_MODULE_GUI) && defined(VISP_HAVE_THREADS)
41 #include <visp3/core/vpDebug.h>
42 #include <visp3/core/vpImagePoint.h>
43 #include <visp3/core/vpIoTools.h>
44 #include <visp3/core/vpMeterPixelConversion.h>
45 #include <visp3/core/vpPoint.h>
46 #include <visp3/core/vpTime.h>
47 #include <visp3/robot/vpRobotException.h>
48 #include <visp3/robot/vpSimulatorAfma6.h>
50 #include "../wireframe-simulator/vpBound.h"
51 #include "../wireframe-simulator/vpRfstack.h"
52 #include "../wireframe-simulator/vpScene.h"
53 #include "../wireframe-simulator/vpVwstack.h"
56 const double vpSimulatorAfma6::defaultPositioningVelocity = 25.0;
61 vpSimulatorAfma6::vpSimulatorAfma6()
62 : vpRobotWireFrameSimulator(),
vpAfma6(), q_prev_getdis(), first_time_getdis(true),
63 positioningVelocity(defaultPositioningVelocity), zeroPos(), reposPos(), toolCustom(false), arm_dir()
70 m_thread =
new std::thread(&launcher, std::ref(*
this));
81 vpSimulatorAfma6::vpSimulatorAfma6(
bool do_display)
82 : vpRobotWireFrameSimulator(do_display), q_prev_getdis(), first_time_getdis(true),
83 positioningVelocity(defaultPositioningVelocity), zeroPos(), reposPos(), toolCustom(false), arm_dir()
90 m_thread =
new std::thread(&launcher, std::ref(*
this));
98 vpSimulatorAfma6::~vpSimulatorAfma6()
100 m_mutex_robotStop.lock();
102 m_mutex_robotStop.unlock();
106 if (robotArms !=
nullptr) {
107 for (
int i = 0; i < 6; i++)
108 free_Bound_scene(&(robotArms[i]));
124 void vpSimulatorAfma6::init()
128 std::vector<std::string> arm_dirs =
vpIoTools::splitChain(std::string(VISP_ROBOT_ARMS_DIR), std::string(
";"));
129 bool armDirExists =
false;
130 for (
size_t i = 0; i < arm_dirs.size(); i++)
132 arm_dir = arm_dirs[i];
139 std::cout <<
"The simulator uses data from VISP_ROBOT_ARMS_DIR=" << arm_dir << std::endl;
142 std::cout <<
"Cannot get VISP_ROBOT_ARMS_DIR environment variable" << std::endl;
152 artVel.resize(njoint);
154 zeroPos.resize(njoint);
156 reposPos.resize(njoint);
158 reposPos[1] = -M_PI / 2;
160 reposPos[4] = M_PI / 2;
165 q_prev_getdis.resize(njoint);
167 first_time_getdis =
true;
169 positioningVelocity = defaultPositioningVelocity;
176 _joint_min[0] = -0.7501;
177 _joint_min[1] = -0.6501;
178 _joint_min[2] = -0.5001;
179 _joint_min[3] = -2.7301;
180 _joint_min[4] = -0.3001;
181 _joint_min[5] = -1.5901;
183 _joint_max[0] = 0.6001;
184 _joint_max[1] = 0.6701;
185 _joint_max[2] = 0.4601;
186 _joint_max[3] = 2.7301;
187 _joint_max[4] = 2.4801;
188 _joint_max[5] = 1.5901;
194 void vpSimulatorAfma6::initDisplay()
197 robotArms =
new Bound_scene[6];
201 cameraParam.initPersProjWithoutDistortion(558.5309599, 556.055053, 320, 240);
202 setExternalCameraParameters(cameraParam);
204 getCameraParameters(tmp, 640, 480);
207 sceneInitialized =
true;
227 this->projModel = proj_model;
228 unsigned int name_length = 30;
229 if (arm_dir.size() > FILENAME_MAX)
231 unsigned int full_length = (
unsigned int)arm_dir.size() + name_length;
232 if (full_length > FILENAME_MAX)
247 if (robotArms !=
nullptr) {
248 while (get_displayBusy())
250 free_Bound_scene(&(robotArms[5]));
251 char *name_arm =
new char[full_length];
252 strcpy(name_arm, arm_dir.c_str());
253 strcat(name_arm,
"/afma6_tool_ccmop.bnd");
254 set_scene(name_arm, robotArms + 5, 1.0);
255 set_displayBusy(
false);
270 if (robotArms !=
nullptr) {
271 while (get_displayBusy())
273 free_Bound_scene(&(robotArms[5]));
274 char *name_arm =
new char[full_length];
275 strcpy(name_arm, arm_dir.c_str());
276 strcat(name_arm,
"/afma6_tool_gripper.bnd");
277 set_scene(name_arm, robotArms + 5, 1.0);
278 set_displayBusy(
false);
293 if (robotArms !=
nullptr) {
294 while (get_displayBusy())
296 free_Bound_scene(&(robotArms[5]));
298 char *name_arm =
new char[full_length];
300 strcpy(name_arm, arm_dir.c_str());
301 strcat(name_arm,
"/afma6_tool_vacuum.bnd");
302 set_scene(name_arm, robotArms + 5, 1.0);
303 set_displayBusy(
false);
309 std::cout <<
"The custom tool is not handled in vpSimulatorAfma6.cpp" << std::endl;
313 std::cout <<
"The Intel D435 camera is not handled in vpSimulatorAfma6.cpp" << std::endl;
317 std::cout <<
"The generic camera is not handled in vpSimulatorAfma6.cpp" << std::endl;
325 this->_eMc.buildFrom(_etc, eRc);
326 m_mutex_eMc.unlock();
342 void vpSimulatorAfma6::getCameraParameters(
vpCameraParameters &cam,
const unsigned int &image_width,
343 const unsigned int &image_height)
349 switch (getToolType()) {
352 if (image_width == 640 && image_height == 480) {
358 vpTRACE(
"Cannot get default intrinsic camera parameters for this image "
365 if (image_width == 640 && image_height == 480) {
371 vpTRACE(
"Cannot get default intrinsic camera parameters for this image "
377 std::cout <<
"The generic tool is not handled in vpSimulatorAfma6.cpp" << std::endl;
381 std::cout <<
"The Intel D435 camera is not handled in vpSimulatorAfma6.cpp" << std::endl;
385 std::cout <<
"The generic camera is not handled in vpSimulatorAfma6.cpp" << std::endl;
389 std::cout <<
"The vacuum tool is not handled in vpSimulatorAfma6.cpp" << std::endl;
393 vpERROR_TRACE(
"This error should not occur!");
441 void vpSimulatorAfma6::updateArticularPosition()
443 double tcur_1 = tcur;
446 bool setVelocityCalled_ =
false;
452 m_mutex_setVelocityCalled.lock();
453 setVelocityCalled_ = setVelocityCalled;
454 m_mutex_setVelocityCalled.unlock();
456 if (setVelocityCalled_ || !constantSamplingTimeMode) {
457 m_mutex_setVelocityCalled.lock();
458 setVelocityCalled =
false;
459 m_mutex_setVelocityCalled.unlock();
461 computeArticularVelocity();
463 double ellapsedTime = (tcur - tprev) * 1e-3;
464 if (constantSamplingTimeMode) {
467 ellapsedTime = getSamplingTime();
474 double art = articularCoordinates[jointLimitArt - 1] + ellapsedTime * articularVelocities[jointLimitArt - 1];
475 if (art <= _joint_min[jointLimitArt - 1] || art >= _joint_max[jointLimitArt - 1]) {
477 std::cout <<
"Joint " << jointLimitArt - 1
479 <<
" < " <<
vpMath::deg(_joint_max[jointLimitArt - 1]) << std::endl;
482 articularVelocities = 0.0;
488 articularCoordinates[0] = articularCoordinates[0] + ellapsedTime * articularVelocities[0];
489 articularCoordinates[1] = articularCoordinates[1] + ellapsedTime * articularVelocities[1];
490 articularCoordinates[2] = articularCoordinates[2] + ellapsedTime * articularVelocities[2];
491 articularCoordinates[3] = articularCoordinates[3] + ellapsedTime * articularVelocities[3];
492 articularCoordinates[4] = articularCoordinates[4] + ellapsedTime * articularVelocities[4];
493 articularCoordinates[5] = articularCoordinates[5] + ellapsedTime * articularVelocities[5];
495 int jl = isInJointLimit();
497 if (jl != 0 && jointLimit ==
false) {
499 ellapsedTime = (_joint_min[(
unsigned int)(-jl - 1)] - articularCoordinates[(
unsigned int)(-jl - 1)]) /
500 (articularVelocities[(
unsigned int)(-jl - 1)]);
502 ellapsedTime = (_joint_max[(
unsigned int)(jl - 1)] - articularCoordinates[(
unsigned int)(jl - 1)]) /
503 (articularVelocities[(
unsigned int)(jl - 1)]);
505 for (
unsigned int i = 0; i < 6; i++)
506 articularCoordinates[i] = articularCoordinates[i] + ellapsedTime * articularVelocities[i];
509 jointLimitArt = (
unsigned int)fabs((
double)jl);
512 set_artCoord(articularCoordinates);
513 set_artVel(articularVelocities);
517 if (displayAllowed) {
523 if (displayType == MODEL_3D && displayAllowed) {
524 while (get_displayBusy()) {
527 vpSimulatorAfma6::getExternalImage(I);
528 set_displayBusy(
false);
531 if (displayType == MODEL_DH && displayAllowed) {
541 pt.track(getExternalCameraPosition());
543 pt.track(getExternalCameraPosition() * fMit[0]);
546 for (
unsigned int k = 1; k < 7; k++) {
547 pt.track(getExternalCameraPosition() * fMit[k - 1]);
550 pt.track(getExternalCameraPosition() * fMit[k]);
568 m_mutex_robotStop.lock();
570 m_mutex_robotStop.unlock();
587 void vpSimulatorAfma6::compute_fMi()
661 fMit[4][0][0] = s4 * s5;
662 fMit[4][1][0] = -c4 * s5;
664 fMit[4][0][1] = s4 * c5;
665 fMit[4][1][1] = -c4 * c5;
670 fMit[4][0][3] = c4 * this->_long_56 + q1;
671 fMit[4][1][3] = s4 * this->_long_56 + q2;
674 fMit[5][0][0] = s4 * s5 * c6 + c4 * s6;
675 fMit[5][1][0] = -c4 * s5 * c6 + s4 * s6;
676 fMit[5][2][0] = c5 * c6;
677 fMit[5][0][1] = -s4 * s5 * s6 + c4 * c6;
678 fMit[5][1][1] = c4 * s5 * s6 + s4 * c6;
679 fMit[5][2][1] = -c5 * s6;
680 fMit[5][0][2] = -s4 * c5;
681 fMit[5][1][2] = c4 * c5;
683 fMit[5][0][3] = c4 * this->_long_56 + q1;
684 fMit[5][1][3] = s4 * this->_long_56 + q2;
687 fMit[6][0][0] = fMit[5][0][0];
688 fMit[6][1][0] = fMit[5][1][0];
689 fMit[6][2][0] = fMit[5][2][0];
690 fMit[6][0][1] = fMit[5][0][1];
691 fMit[6][1][1] = fMit[5][1][1];
692 fMit[6][2][1] = fMit[5][2][1];
693 fMit[6][0][2] = fMit[5][0][2];
694 fMit[6][1][2] = fMit[5][1][2];
695 fMit[6][2][2] = fMit[5][2][2];
696 fMit[6][0][3] = fMit[5][0][3];
697 fMit[6][1][3] = fMit[5][1][3];
698 fMit[6][2][3] = fMit[5][2][3];
706 m_mutex_eMc.unlock();
709 for (
int i = 0; i < 8; i++) {
712 m_mutex_fMi.unlock();
732 std::cout <<
"Change the control mode from velocity to position control.\n";
743 std::cout <<
"Change the control mode from stop to velocity control.\n";
834 vpERROR_TRACE(
"Cannot send a velocity to the robot "
835 "use setRobotState(vpRobot::STATE_VELOCITY_CONTROL) first) ");
837 "Cannot send a velocity to the robot "
838 "use setRobotState(vpRobot::STATE_VELOCITY_CONTROL) first) ");
843 double scale_sat = 1;
844 double vel_trans_max = getMaxTranslationVelocity();
845 double vel_rot_max = getMaxRotationVelocity();
855 vpERROR_TRACE(
"The velocity vector must have a size of 6 !!!!");
859 for (
unsigned int i = 0; i < 3; ++i) {
860 vel_abs = fabs(vel[i]);
861 if (vel_abs > vel_trans_max && !jointLimit) {
862 vel_trans_max = vel_abs;
863 vpERROR_TRACE(
"Excess velocity %g m/s in TRANSLATION "
868 vel_abs = fabs(vel[i + 3]);
869 if (vel_abs > vel_rot_max && !jointLimit) {
870 vel_rot_max = vel_abs;
871 vpERROR_TRACE(
"Excess velocity %g rad/s in ROTATION "
877 double scale_trans_sat = 1;
878 double scale_rot_sat = 1;
879 if (vel_trans_max > getMaxTranslationVelocity())
880 scale_trans_sat = getMaxTranslationVelocity() / vel_trans_max;
882 if (vel_rot_max > getMaxRotationVelocity())
883 scale_rot_sat = getMaxRotationVelocity() / vel_rot_max;
885 if ((scale_trans_sat < 1) || (scale_rot_sat < 1)) {
886 if (scale_trans_sat < scale_rot_sat)
887 scale_sat = scale_trans_sat;
889 scale_sat = scale_rot_sat;
897 vpERROR_TRACE(
"The velocity vector must have a size of 6 !!!!");
900 for (
unsigned int i = 0; i < 6; ++i) {
901 vel_abs = fabs(vel[i]);
902 if (vel_abs > vel_rot_max && !jointLimit) {
903 vel_rot_max = vel_abs;
904 vpERROR_TRACE(
"Excess velocity %g rad/s in ROTATION "
909 double scale_rot_sat = 1;
910 if (vel_rot_max > getMaxRotationVelocity())
911 scale_rot_sat = getMaxRotationVelocity() / vel_rot_max;
912 if (scale_rot_sat < 1)
913 scale_sat = scale_rot_sat;
918 "functionality not implemented");
922 "functionality not implemented");
926 set_velocity(vel * scale_sat);
928 m_mutex_frame.lock();
929 setRobotFrame(frame);
930 m_mutex_frame.unlock();
932 m_mutex_setVelocityCalled.lock();
933 setVelocityCalled =
true;
934 m_mutex_setVelocityCalled.unlock();
940 void vpSimulatorAfma6::computeArticularVelocity()
944 m_mutex_frame.lock();
945 frame = getRobotFrame();
946 m_mutex_frame.unlock();
948 double vel_rot_max = getMaxRotationVelocity();
960 if (singularityManagement)
961 singularityTest(articularCoordinates, eJe_);
962 articularVelocity = eJe_ * eVc * velocityframe;
963 set_artVel(articularVelocity);
970 if (singularityManagement)
971 singularityTest(articularCoordinates, fJe_);
972 articularVelocity = fJe_ * velocityframe;
973 set_artVel(articularVelocity);
977 articularVelocity = velocityframe;
978 set_artVel(articularVelocity);
990 for (
unsigned int i = 0; i < 6; ++i) {
991 double vel_abs = fabs(articularVelocity[i]);
992 if (vel_abs > vel_rot_max && !jointLimit) {
993 vel_rot_max = vel_abs;
994 vpERROR_TRACE(
"Excess velocity %g rad/s in ROTATION "
996 articularVelocity[i], i + 1);
999 double scale_rot_sat = 1;
1000 double scale_sat = 1;
1001 if (vel_rot_max > getMaxRotationVelocity())
1002 scale_rot_sat = getMaxRotationVelocity() / vel_rot_max;
1003 if (scale_rot_sat < 1)
1004 scale_sat = scale_rot_sat;
1006 set_artVel(articularVelocity * scale_sat);
1070 vpColVector articularCoordinates = get_artCoord();
1078 vel = cVe * eJe_ * articularVelocity;
1082 vel = articularVelocity;
1088 vel = fJe_ * articularVelocity;
1096 vpERROR_TRACE(
"Error in spec of vpRobot. "
1097 "Case not taken in account.");
1122 getVelocity(frame, vel);
1173 getVelocity(frame, vel);
1194 getVelocity(frame, vel);
1199 void vpSimulatorAfma6::findHighestPositioningSpeed(
vpColVector &q)
1201 double vel_rot_max = getMaxRotationVelocity();
1202 double velmax = fabs(q[0]);
1203 for (
unsigned int i = 1; i < 6; i++) {
1204 if (velmax < fabs(q[i]))
1205 velmax = fabs(q[i]);
1208 double alpha = (getPositioningVelocity() * vel_rot_max) / (velmax * 100);
1293 vpERROR_TRACE(
"Robot was not in position-based control\n"
1294 "Modification of the robot state");
1298 vpColVector articularCoordinates = get_artCoord();
1309 for (
unsigned int i = 0; i < 3; i++) {
1323 articularCoordinates = get_artCoord();
1324 qdes = articularCoordinates;
1325 nbSol = getInverseKinematics(fMc2, qdes,
true, verbose_);
1327 m_mutex_setVelocityCalled.lock();
1328 setVelocityCalled =
true;
1329 m_mutex_setVelocityCalled.unlock();
1332 error = qdes - articularCoordinates;
1336 if (errsqr < 1e-4) {
1340 set_velocity(error);
1345 vpERROR_TRACE(
"Positioning error.");
1348 }
while (errsqr > 1e-8 && nbSol > 0);
1355 articularCoordinates = get_artCoord();
1356 error = q - articularCoordinates;
1360 m_mutex_setVelocityCalled.lock();
1361 setVelocityCalled =
true;
1362 m_mutex_setVelocityCalled.unlock();
1363 if (errsqr < 1e-4) {
1367 set_velocity(error);
1370 }
while (errsqr > 1e-8);
1380 for (
unsigned int i = 0; i < 3; i++) {
1389 articularCoordinates = get_artCoord();
1390 qdes = articularCoordinates;
1391 nbSol = getInverseKinematics(fMc_, qdes,
true, verbose_);
1392 m_mutex_setVelocityCalled.lock();
1393 setVelocityCalled =
true;
1394 m_mutex_setVelocityCalled.unlock();
1396 error = qdes - articularCoordinates;
1397 errsqr = error.sumSquare();
1400 if (errsqr < 1e-4) {
1404 set_velocity(error);
1409 vpERROR_TRACE(
"Positioning error. Position unreachable");
1410 }
while (errsqr > 1e-8 && nbSol > 0);
1414 vpERROR_TRACE(
"Positioning error. Mixt frame not implemented");
1416 "MIXT_FRAME not implemented.");
1419 vpERROR_TRACE(
"Positioning error. Mixt frame not implemented");
1421 "END_EFFECTOR_FRAME not implemented.");
1493 double pos4,
double pos5,
double pos6)
1504 setPosition(frame, position);
1507 vpERROR_TRACE(
"Error caught");
1550 void vpSimulatorAfma6::setPosition(
const char *filename)
1555 ret = this->readPosFile(filename, q);
1558 vpERROR_TRACE(
"Bad position in \"%s\"", filename);
1653 for (
unsigned int i = 0; i < 3; i++) {
1662 "Mixt frame not implemented.");
1666 "End-effector frame not implemented.");
1700 getPosition(frame, q);
1718 this->getPosition(frame, posRxyz);
1724 for (
unsigned int j = 0; j < 3; j++) {
1725 position[j] = posRxyz[j];
1726 position[j + 3] = RtuVect[j];
1744 getPosition(frame, position);
1760 vpTRACE(
"Joint limit vector has not a size of 6 !");
1764 _joint_min[0] = limitMin[0];
1765 _joint_min[1] = limitMin[1];
1766 _joint_min[2] = limitMin[2];
1767 _joint_min[3] = limitMin[3];
1768 _joint_min[4] = limitMin[4];
1769 _joint_min[5] = limitMin[5];
1771 _joint_max[0] = limitMax[0];
1772 _joint_max[1] = limitMax[1];
1773 _joint_max[2] = limitMax[2];
1774 _joint_max[3] = limitMax[3];
1775 _joint_max[4] = limitMax[4];
1776 _joint_max[5] = limitMax[5];
1788 bool cond = fabs(q5 - M_PI / 2) < 1e-1;
1808 int vpSimulatorAfma6::isInJointLimit()
1814 vpColVector articularCoordinates = get_artCoord();
1816 for (
unsigned int i = 0; i < 6; i++) {
1817 if (articularCoordinates[i] <= _joint_min[i]) {
1818 difft = _joint_min[i] - articularCoordinates[i];
1821 artNumb = -(int)i - 1;
1826 for (
unsigned int i = 0; i < 6; i++) {
1827 if (articularCoordinates[i] >= _joint_max[i]) {
1828 difft = articularCoordinates[i] - _joint_max[i];
1831 artNumb = (int)(i + 1);
1837 std::cout <<
"\nWarning: Velocity control stopped: axis " << fabs((
float)artNumb) <<
" on joint limit!"
1866 q_cur = get_artCoord();
1868 if (!first_time_getdis) {
1871 std::cout <<
"getDisplacement() CAMERA_FRAME not implemented\n";
1875 displacement = q_cur - q_prev_getdis;
1879 std::cout <<
"getDisplacement() REFERENCE_FRAME not implemented\n";
1883 std::cout <<
"getDisplacement() MIXT_FRAME not implemented\n";
1887 std::cout <<
"getDisplacement() END_EFFECTOR_FRAME not implemented\n";
1893 first_time_getdis =
false;
1897 q_prev_getdis = q_cur;
1947 bool vpSimulatorAfma6::readPosFile(
const std::string &filename,
vpColVector &q)
1949 std::ifstream fd(filename.c_str(), std::ios::in);
1951 if (!fd.is_open()) {
1956 std::string key(
"R:");
1957 std::string id(
"#AFMA6 - Position");
1958 bool pos_found =
false;
1963 while (std::getline(fd, line)) {
1966 if (!(line.compare(0,
id.size(),
id) == 0)) {
1967 std::cout <<
"Error: this position file " << filename <<
" is not for Afma6 robot" << std::endl;
1971 if ((line.compare(0, 1,
"#") == 0)) {
1974 if ((line.compare(0, key.size(), key) == 0)) {
1977 if (chain.size() < njoint + 1)
1979 if (chain.size() < njoint + 1)
1982 std::istringstream ss(line);
1985 for (
unsigned int i = 0; i < njoint; i++)
2000 std::cout <<
"Error: unable to find a position for Afma6 robot in " << filename << std::endl;
2029 bool vpSimulatorAfma6::savePosFile(
const std::string &filename,
const vpColVector &q)
2032 fd = fopen(filename.c_str(),
"w");
2037 #AFMA6 - Position - Version 2.01\n\
2040 # Joint position: X, Y, Z: translations in meters\n\
2041 # A, B, C: rotations in degrees\n\
2060 void vpSimulatorAfma6::move(
const char *filename)
2065 this->readPosFile(filename, q);
2109 void vpSimulatorAfma6::get_eJe(
vpMatrix &eJe_)
2115 vpERROR_TRACE(
"catch exception ");
2130 void vpSimulatorAfma6::get_fJe(
vpMatrix &fJe_)
2133 vpColVector articularCoordinates = get_artCoord();
2137 vpERROR_TRACE(
"Error caught");
2145 void vpSimulatorAfma6::stopMotion()
2170 void vpSimulatorAfma6::initArms()
2174 std::string scene_dir_;
2175 std::vector<std::string> scene_dirs =
vpIoTools::splitChain(std::string(VISP_SCENES_DIR), std::string(
";"));
2176 bool sceneDirExists =
false;
2177 for (
size_t i = 0; i < scene_dirs.size(); i++)
2179 scene_dir_ = scene_dirs[i];
2180 sceneDirExists =
true;
2183 if (!sceneDirExists) {
2186 std::cout <<
"The simulator uses data from VISP_SCENES_DIR=" << scene_dir_ << std::endl;
2189 std::cout <<
"Cannot get VISP_SCENES_DIR environment variable" << std::endl;
2193 unsigned int name_length = 30;
2194 if (scene_dir_.size() > FILENAME_MAX)
2196 unsigned int full_length = (
unsigned int)scene_dir_.size() + name_length;
2197 if (full_length > FILENAME_MAX)
2200 char *name_cam =
new char[full_length];
2202 strcpy(name_cam, scene_dir_.c_str());
2203 strcat(name_cam,
"/camera.bnd");
2204 set_scene(name_cam, &camera, cameraFactor);
2206 if (arm_dir.size() > FILENAME_MAX)
2208 full_length = (
unsigned int)arm_dir.size() + name_length;
2209 if (full_length > FILENAME_MAX)
2212 char *name_arm =
new char[full_length];
2213 strcpy(name_arm, arm_dir.c_str());
2214 strcat(name_arm,
"/afma6_gate.bnd");
2215 std::cout <<
"name arm: " << name_arm << std::endl;
2216 set_scene(name_arm, robotArms, 1.0);
2217 strcpy(name_arm, arm_dir.c_str());
2218 strcat(name_arm,
"/afma6_arm1.bnd");
2219 set_scene(name_arm, robotArms + 1, 1.0);
2220 strcpy(name_arm, arm_dir.c_str());
2221 strcat(name_arm,
"/afma6_arm2.bnd");
2222 set_scene(name_arm, robotArms + 2, 1.0);
2223 strcpy(name_arm, arm_dir.c_str());
2224 strcat(name_arm,
"/afma6_arm3.bnd");
2225 set_scene(name_arm, robotArms + 3, 1.0);
2226 strcpy(name_arm, arm_dir.c_str());
2227 strcat(name_arm,
"/afma6_arm4.bnd");
2228 set_scene(name_arm, robotArms + 4, 1.0);
2231 tool = getToolType();
2232 strcpy(name_arm, arm_dir.c_str());
2235 strcat(name_arm,
"/afma6_tool_ccmop.bnd");
2239 strcat(name_arm,
"/afma6_tool_gripper.bnd");
2243 strcat(name_arm,
"/afma6_tool_vacuum.bnd");
2247 std::cout <<
"The custom tool is not handled in vpSimulatorAfma6.cpp" << std::endl;
2251 std::cout <<
"The Intel D435 camera is not handled in vpSimulatorAfma6.cpp" << std::endl;
2255 std::cout <<
"The generic camera is not handled in vpSimulatorAfma6.cpp" << std::endl;
2259 set_scene(name_arm, robotArms + 5, 1.0);
2261 add_rfstack(IS_BACK);
2263 add_vwstack(
"start",
"depth", 0.0, 100.0);
2264 add_vwstack(
"start",
"window", -0.1, 0.1, -0.1, 0.1);
2265 add_vwstack(
"start",
"type", PERSPECTIVE);
2269 displayCamera =
true;
2277 m_mutex_scene.lock();
2278 bool changed =
false;
2282 if (std::fabs(displacement[2][3]) > std::numeric_limits<double>::epsilon())
2283 camMf2 = camMf2 * displacement;
2285 f2Mf = camMf2.
inverse() * camMf;
2287 camMf = camMf2 * displacement * f2Mf;
2293 if ((std::fabs(px_ext - 1.) >
vpMath::maximum(px_ext, 1.) * std::numeric_limits<double>::epsilon()) &&
2294 (std::fabs(py_ext - 1) >
vpMath::maximum(py_ext, 1.) * std::numeric_limits<double>::epsilon())) {
2295 u = (double)I_.
getWidth() / (2 * px_ext);
2296 v = (double)I_.
getHeight() / (2 * py_ext);
2303 float w44o[4][4], w44cext[4][4], x, y, z;
2305 vp2jlc_matrix(camMf.inverse(), w44cext);
2307 add_vwstack(
"start",
"cop", w44cext[3][0], w44cext[3][1], w44cext[3][2]);
2308 x = w44cext[2][0] + w44cext[3][0];
2309 y = w44cext[2][1] + w44cext[3][1];
2310 z = w44cext[2][2] + w44cext[3][2];
2311 add_vwstack(
"start",
"vrp", x, y, z);
2312 add_vwstack(
"start",
"vpn", w44cext[2][0], w44cext[2][1], w44cext[2][2]);
2313 add_vwstack(
"start",
"vup", w44cext[1][0], w44cext[1][1], w44cext[1][2]);
2314 add_vwstack(
"start",
"window", -u, u, -v, v);
2320 display_scene(w44o, robotArms[0], I_, curColor);
2322 vp2jlc_matrix(fMit[0], w44o);
2323 display_scene(w44o, robotArms[1], I_, curColor);
2325 vp2jlc_matrix(fMit[2], w44o);
2326 display_scene(w44o, robotArms[2], I_, curColor);
2328 vp2jlc_matrix(fMit[3], w44o);
2329 display_scene(w44o, robotArms[3], I_, curColor);
2331 vp2jlc_matrix(fMit[4], w44o);
2332 display_scene(w44o, robotArms[4], I_, curColor);
2334 vp2jlc_matrix(fMit[5], w44o);
2335 display_scene(w44o, robotArms[5], I_, curColor);
2337 if (displayCamera) {
2341 cMe = fMit[6] * cMe;
2342 vp2jlc_matrix(cMe, w44o);
2343 display_scene(w44o, camera, I_, camColor);
2346 if (displayObject) {
2347 vp2jlc_matrix(fMo, w44o);
2348 display_scene(w44o, scene, I_, curColor);
2350 m_mutex_scene.unlock();
2375 m_mutex_scene.lock();
2381 vpColVector articularCoordinates = get_artCoord();
2382 int nbSol = getInverseKinematics(fMc_, articularCoordinates,
true, verbose_);
2386 vpERROR_TRACE(
"Positioning error. Position unreachable");
2390 std::cout <<
"Used joint coordinates (rad): " << articularCoordinates.
t() << std::endl;
2392 set_artCoord(articularCoordinates);
2395 m_mutex_scene.unlock();
2417 m_mutex_scene.lock();
2422 fMo = fMit[7] * cMo_;
2423 m_mutex_scene.unlock();
2440 double vMax = getMaxTranslationVelocity();
2441 double wMax = getMaxRotationVelocity();
2442 setMaxTranslationVelocity(10. * vMax);
2443 setMaxRotationVelocity(10. * wMax);
2452 const double lambda = 5.;
2456 unsigned int i, iter = 0;
2457 while ((iter++ < 300) && (err.frobeniusNorm() > errMax)) {
2461 if (Iint !=
nullptr) {
2463 getInternalView(*Iint);
2468 cdMc = cdMo_ * get_cMo().
inverse();
2474 v = -lambda * cdRc.
t() * cdTc;
2475 w = -lambda * cdTUc;
2476 for (i = 0; i < 3; ++i) {
2480 err[i + 3] = cdTUc[i];
2492 setMaxTranslationVelocity(vMax);
2493 setMaxRotationVelocity(wMax);
2496 return (err.frobeniusNorm() <= errMax);
2499 #elif !defined(VISP_BUILD_SHARED_LIBS)
2502 void dummy_vpSimulatorAfma6() { };
Modelization of Irisa's gantry robot named Afma6.
static const char *const CONST_CCMOP_CAMERA_NAME
void get_cMe(vpHomogeneousMatrix &cMe) const
static const char *const CONST_GRIPPER_CAMERA_NAME
vpHomogeneousMatrix get_fMc(const vpColVector &q) const
void get_eJe(const vpColVector &q, vpMatrix &eJe) const
void get_fJe(const vpColVector &q, vpMatrix &fJe) const
vpAfma6ToolType
List of possible tools that can be attached to the robot end-effector.
unsigned int getRows() const
Generic class defining intrinsic camera parameters.
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
vpCameraParametersProjType
Implementation of column vector and the associated operations.
void resize(unsigned int i, bool flagNullify=true)
static const vpColor none
static const vpColor green
static void display(const vpImage< unsigned char > &I)
static void displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1, bool segment=true)
static void displayFrame(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color=vpColor::none, unsigned int thickness=1, const vpImagePoint &offset=vpImagePoint(0, 0), const std::string &frameName="", const vpColor &textColor=vpColor::black, const vpImagePoint &textOffset=vpImagePoint(15, 15))
static void flush(const vpImage< unsigned char > &I)
static void displayCamera(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, const vpColor &color, unsigned int thickness)
error that can be emitted by ViSP classes.
@ dimensionError
Bad dimension.
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpHomogeneousMatrix inverse() const
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true)
void extract(vpRotationMatrix &R) const
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
unsigned int getWidth() const
unsigned int getHeight() const
void init(unsigned int h, unsigned int w, Type value)
static double rad(double deg)
static Type maximum(const Type &a, const Type &b)
static Type minimum(const Type &a, const Type &b)
static double deg(double rad)
Implementation of a matrix and operations on matrices.
vpMatrix pseudoInverse(double svThreshold=1e-6) const
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Implementation of a pose vector and operations on poses.
Error that can be emitted by the vpRobot class and its derivatives.
@ wrongStateError
Wrong robot state.
@ positionOutOfRangeError
Position is out of range.
@ lowLevelError
Error thrown by the low level sdk.
@ STATE_POSITION_CONTROL
Initialize the position controller.
@ STATE_VELOCITY_CONTROL
Initialize the velocity controller.
@ STATE_ACCELERATION_CONTROL
Initialize the acceleration controller.
@ STATE_STOP
Stops robot motion especially in velocity and acceleration control.
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
Implementation of a rotation matrix and operations on such kind of matrices.
vpRotationMatrix t() const
Implementation of a rotation vector as Euler angle minimal representation.
Implementation of a rotation vector as axis-angle minimal representation.
vpThetaUVector & buildFrom(const vpHomogeneousMatrix &M)
Class that consider the case of a translation vector.
vpVelocityTwistMatrix & buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
VISP_EXPORT int wait(double t0, double t)
VISP_EXPORT double getMinTimeForUsleepCall()
VISP_EXPORT double measureTimeSecond()
VISP_EXPORT double measureTimeMs()