39 #include <visp3/core/vpConfig.h> 41 #ifdef VISP_HAVE_JACOSDK 43 #include <visp3/core/vpIoTools.h> 44 #include <visp3/robot/vpRobotException.h> 51 #include <visp3/core/vpHomogeneousMatrix.h> 52 #include <visp3/robot/vpRobotKinova.h> 58 : m_eMc(), m_plugin_location(
"./"), m_verbose(false), m_plugin_loaded(false), m_devices_count(0),
59 m_devices_list(NULL), m_active_device(-1), m_command_layer(CMD_LAYER_UNSET), m_command_layer_handle()
82 if (dof == 4 || dof == 6 || dof == 7) {
133 std::cout <<
"Not implemented ! " << std::endl;
153 std::cout <<
"Not implemented ! " << std::endl;
211 TrajectoryPoint pointToSend;
212 pointToSend.InitStruct();
214 pointToSend.Position.Type = CARTESIAN_VELOCITY;
215 pointToSend.Position.HandMode = HAND_NOMOVEMENT;
217 pointToSend.Position.CartesianPosition.X =
static_cast<float>(v_mix[0]);
218 pointToSend.Position.CartesianPosition.Y =
static_cast<float>(v_mix[1]);
219 pointToSend.Position.CartesianPosition.Z =
static_cast<float>(v_mix[2]);
220 pointToSend.Position.CartesianPosition.ThetaX =
static_cast<float>(v_mix[3]);
221 pointToSend.Position.CartesianPosition.ThetaY =
static_cast<float>(v_mix[4]);
222 pointToSend.Position.CartesianPosition.ThetaZ =
static_cast<float>(v_mix[5]);
224 KinovaSetCartesianControl();
226 KinovaSendBasicTrajectory(pointToSend);
244 TrajectoryPoint pointToSend;
245 pointToSend.InitStruct();
247 pointToSend.Position.Type = CARTESIAN_VELOCITY;
248 pointToSend.Position.HandMode = HAND_NOMOVEMENT;
250 pointToSend.Position.CartesianPosition.X =
static_cast<float>(v_mix[0]);
251 pointToSend.Position.CartesianPosition.Y =
static_cast<float>(v_mix[1]);
252 pointToSend.Position.CartesianPosition.Z =
static_cast<float>(v_mix[2]);
253 pointToSend.Position.CartesianPosition.ThetaX =
static_cast<float>(v_mix[3]);
254 pointToSend.Position.CartesianPosition.ThetaY =
static_cast<float>(v_mix[4]);
255 pointToSend.Position.CartesianPosition.ThetaZ =
static_cast<float>(v_mix[5]);
257 KinovaSetCartesianControl();
259 KinovaSendBasicTrajectory(pointToSend);
270 std::cout <<
"rotation matrix from base to endeffector is bRe : " << std::endl;
271 std::cout <<
"bRe:\n" << bRe << std::endl;
279 TrajectoryPoint pointToSend;
280 pointToSend.InitStruct();
282 pointToSend.Position.Type = CARTESIAN_VELOCITY;
283 pointToSend.Position.HandMode = HAND_NOMOVEMENT;
285 pointToSend.Position.CartesianPosition.X =
static_cast<float>(v_mix[0]);
286 pointToSend.Position.CartesianPosition.Y =
static_cast<float>(v_mix[1]);
287 pointToSend.Position.CartesianPosition.Z =
static_cast<float>(v_mix[2]);
288 pointToSend.Position.CartesianPosition.ThetaX =
static_cast<float>(v_e[3]);
289 pointToSend.Position.CartesianPosition.ThetaY =
static_cast<float>(v_e[4]);
290 pointToSend.Position.CartesianPosition.ThetaZ =
static_cast<float>(v_e[5]);
292 KinovaSetCartesianControl();
293 KinovaSendBasicTrajectory(pointToSend);
309 if (qdot.
size() !=
static_cast<unsigned int>(
nDof)) {
312 TrajectoryPoint pointToSend;
313 pointToSend.InitStruct();
315 pointToSend.Position.Type = ANGULAR_VELOCITY;
316 pointToSend.Position.HandMode = HAND_NOMOVEMENT;
319 pointToSend.Position.Actuators.Actuator7 =
static_cast<float>(
vpMath::deg(qdot[6]));
320 pointToSend.Position.Actuators.Actuator6 =
static_cast<float>(
vpMath::deg(qdot[5]));
321 pointToSend.Position.Actuators.Actuator5 =
static_cast<float>(
vpMath::deg(qdot[4]));
322 pointToSend.Position.Actuators.Actuator4 =
static_cast<float>(
vpMath::deg(qdot[3]));
323 pointToSend.Position.Actuators.Actuator3 =
static_cast<float>(
vpMath::deg(qdot[2]));
324 pointToSend.Position.Actuators.Actuator2 =
static_cast<float>(
vpMath::deg(qdot[1]));
325 pointToSend.Position.Actuators.Actuator1 =
static_cast<float>(
vpMath::deg(qdot[0]));
329 pointToSend.Position.Actuators.Actuator6 =
static_cast<float>(
vpMath::deg(qdot[5]));
330 pointToSend.Position.Actuators.Actuator5 =
static_cast<float>(
vpMath::deg(qdot[4]));
331 pointToSend.Position.Actuators.Actuator4 =
static_cast<float>(
vpMath::deg(qdot[3]));
332 pointToSend.Position.Actuators.Actuator3 =
static_cast<float>(
vpMath::deg(qdot[2]));
333 pointToSend.Position.Actuators.Actuator2 =
static_cast<float>(
vpMath::deg(qdot[1]));
334 pointToSend.Position.Actuators.Actuator1 =
static_cast<float>(
vpMath::deg(qdot[0]));
338 pointToSend.Position.Actuators.Actuator4 =
static_cast<float>(
vpMath::deg(qdot[3]));
339 pointToSend.Position.Actuators.Actuator3 =
static_cast<float>(
vpMath::deg(qdot[2]));
340 pointToSend.Position.Actuators.Actuator2 =
static_cast<float>(
vpMath::deg(qdot[1]));
341 pointToSend.Position.Actuators.Actuator1 =
static_cast<float>(
vpMath::deg(qdot[0]));
348 KinovaSetAngularControl();
350 KinovaSendBasicTrajectory(pointToSend);
380 "Cannot send a velocity to the robot. " 381 "Call setRobotState(vpRobot::STATE_VELOCITY_CONTROL) once before " 382 "entering your control loop.");
394 if (vel.
size() != 6) {
399 for (
unsigned int i = 0; i < 3; i++)
401 for (
unsigned int i = 3; i < 6; i++)
412 if (vel.
size() !=
static_cast<size_t>(
nDof)) {
442 AngularPosition currentCommand;
445 KinovaGetAngularCommand(currentCommand);
450 q[6] =
vpMath::rad(currentCommand.Actuators.Actuator7);
451 q[5] =
vpMath::rad(currentCommand.Actuators.Actuator6);
452 q[4] =
vpMath::rad(currentCommand.Actuators.Actuator5);
453 q[3] =
vpMath::rad(currentCommand.Actuators.Actuator4);
454 q[2] =
vpMath::rad(currentCommand.Actuators.Actuator3);
455 q[1] =
vpMath::rad(currentCommand.Actuators.Actuator2);
456 q[0] =
vpMath::rad(currentCommand.Actuators.Actuator1);
460 q[5] =
vpMath::rad(currentCommand.Actuators.Actuator6);
461 q[4] =
vpMath::rad(currentCommand.Actuators.Actuator5);
462 q[3] =
vpMath::rad(currentCommand.Actuators.Actuator4);
463 q[2] =
vpMath::rad(currentCommand.Actuators.Actuator3);
464 q[1] =
vpMath::rad(currentCommand.Actuators.Actuator2);
465 q[0] =
vpMath::rad(currentCommand.Actuators.Actuator1);
469 q[3] =
vpMath::rad(currentCommand.Actuators.Actuator4);
470 q[2] =
vpMath::rad(currentCommand.Actuators.Actuator3);
471 q[1] =
vpMath::rad(currentCommand.Actuators.Actuator2);
472 q[0] =
vpMath::rad(currentCommand.Actuators.Actuator1);
520 CartesianPosition currentCommand;
522 KinovaGetCartesianCommand(currentCommand);
524 position[0] = currentCommand.Coordinates.X;
525 position[1] = currentCommand.Coordinates.Y;
526 position[2] = currentCommand.Coordinates.Z;
527 position[3] = currentCommand.Coordinates.ThetaX;
528 position[4] = currentCommand.Coordinates.ThetaY;
529 position[5] = currentCommand.Coordinates.ThetaZ;
532 std::cout <<
"Not implemented ! " << std::endl;
565 for (
unsigned int i=0; i < 3; i++) {
566 pose[i] = position[i];
567 rxyz[i] = position[i+3];
570 for (
unsigned int i=0; i < 3; i++) {
590 if (static_cast<int>(q.
size()) !=
nDof) {
593 TrajectoryPoint pointToSend;
594 pointToSend.InitStruct();
596 pointToSend.Position.Type = ANGULAR_POSITION;
597 pointToSend.Position.HandMode = HAND_NOMOVEMENT;
600 pointToSend.Position.Actuators.Actuator7 =
static_cast<float>(
vpMath::deg(q[6]));
601 pointToSend.Position.Actuators.Actuator6 =
static_cast<float>(
vpMath::deg(q[5]));
602 pointToSend.Position.Actuators.Actuator5 =
static_cast<float>(
vpMath::deg(q[4]));
603 pointToSend.Position.Actuators.Actuator4 =
static_cast<float>(
vpMath::deg(q[3]));
604 pointToSend.Position.Actuators.Actuator3 =
static_cast<float>(
vpMath::deg(q[2]));
605 pointToSend.Position.Actuators.Actuator2 =
static_cast<float>(
vpMath::deg(q[1]));
606 pointToSend.Position.Actuators.Actuator1 =
static_cast<float>(
vpMath::deg(q[0]));
610 pointToSend.Position.Actuators.Actuator6 =
static_cast<float>(
vpMath::deg(q[5]));
611 pointToSend.Position.Actuators.Actuator5 =
static_cast<float>(
vpMath::deg(q[4]));
612 pointToSend.Position.Actuators.Actuator4 =
static_cast<float>(
vpMath::deg(q[3]));
613 pointToSend.Position.Actuators.Actuator3 =
static_cast<float>(
vpMath::deg(q[2]));
614 pointToSend.Position.Actuators.Actuator2 =
static_cast<float>(
vpMath::deg(q[1]));
615 pointToSend.Position.Actuators.Actuator1 =
static_cast<float>(
vpMath::deg(q[0]));
619 pointToSend.Position.Actuators.Actuator4 =
static_cast<float>(
vpMath::deg(q[3]));
620 pointToSend.Position.Actuators.Actuator3 =
static_cast<float>(
vpMath::deg(q[2]));
621 pointToSend.Position.Actuators.Actuator2 =
static_cast<float>(
vpMath::deg(q[1]));
622 pointToSend.Position.Actuators.Actuator1 =
static_cast<float>(
vpMath::deg(q[0]));
629 KinovaSetAngularControl();
632 std::cout <<
"Move robot to joint position [rad rad rad rad rad rad]: " << q.
t() << std::endl;
634 KinovaSendBasicTrajectory(pointToSend);
640 TrajectoryPoint pointToSend;
641 pointToSend.InitStruct();
643 pointToSend.Position.Type = CARTESIAN_POSITION;
644 pointToSend.Position.HandMode = HAND_NOMOVEMENT;
645 pointToSend.Position.CartesianPosition.X =
static_cast<float>(q[0]);
646 pointToSend.Position.CartesianPosition.Y =
static_cast<float>(q[1]);
647 pointToSend.Position.CartesianPosition.Z =
static_cast<float>(q[2]);
648 pointToSend.Position.CartesianPosition.ThetaX =
static_cast<float>(q[3]);
649 pointToSend.Position.CartesianPosition.ThetaY =
static_cast<float>(q[4]);
650 pointToSend.Position.CartesianPosition.ThetaZ =
static_cast<float>(q[5]);
652 KinovaSetCartesianControl();
655 std::cout <<
"Move robot to cartesian position [m m m rad rad rad]: " << q.
t() << std::endl;
657 KinovaSendBasicTrajectory(pointToSend);
682 std::cout <<
"Not implemented ! " << std::endl;
706 std::string plugin_name = (
m_command_layer ==
CMD_LAYER_USB) ? std::string(
"Kinova.API.USBCommandLayerUbuntu.so") : std::string(
"Kinova.API.EthCommandLayerUbuntu.so");
709 std::cout <<
"Load plugin: \"" << plugin <<
"\"" << std::endl;
711 m_command_layer_handle = dlopen(plugin.c_str(), RTLD_NOW | RTLD_GLOBAL);
715 KinovaCloseAPI = (int(*)()) dlsym(m_command_layer_handle, (prefix + std::string(
"CloseAPI")).c_str());
716 KinovaGetAngularCommand = (int(*)(AngularPosition &)) dlsym(m_command_layer_handle, (prefix + std::string(
"GetAngularCommand")).c_str());
717 KinovaGetCartesianCommand = (int(*)(CartesianPosition &)) dlsym(m_command_layer_handle, (prefix + std::string(
"GetCartesianCommand")).c_str());
718 KinovaGetDevices = (int(*)(KinovaDevice devices[MAX_KINOVA_DEVICE],
int &result)) dlsym(m_command_layer_handle, (prefix + std::string(
"GetDevices")).c_str());
719 KinovaInitAPI = (int(*)()) dlsym(m_command_layer_handle, (prefix + std::string(
"InitAPI")).c_str());
720 KinovaInitFingers = (int(*)()) dlsym(m_command_layer_handle, (prefix + std::string(
"InitFingers")).c_str());
721 KinovaMoveHome = (int(*)()) dlsym(m_command_layer_handle, (prefix + std::string(
"MoveHome")).c_str());
722 KinovaSendBasicTrajectory = (int(*)(TrajectoryPoint)) dlsym(m_command_layer_handle, (prefix + std::string(
"SendBasicTrajectory")).c_str());
723 KinovaSetActiveDevice = (int(*)(KinovaDevice devices)) dlsym(m_command_layer_handle, (prefix + std::string(
"SetActiveDevice")).c_str());
724 KinovaSetAngularControl = (int(*)()) dlsym(m_command_layer_handle, (prefix + std::string(
"SetAngularControl")).c_str());
725 KinovaSetCartesianControl = (int(*)()) dlsym(m_command_layer_handle, (prefix + std::string(
"SetCartesianControl")).c_str());
728 std::string plugin_name = (
m_command_layer ==
CMD_LAYER_USB) ? std::string(
"CommandLayerWindows.dll") : std::string(
"CommandLayerEthernet.dll");
731 std::cout <<
"Load plugin: \"" << plugin <<
"\"" << std::endl;
733 m_command_layer_handle = LoadLibrary(TEXT(plugin.c_str()));
736 KinovaCloseAPI = (int(*)()) GetProcAddress(m_command_layer_handle,
"CloseAPI");
737 KinovaGetAngularCommand = (int(*)(AngularPosition &)) GetProcAddress(m_command_layer_handle,
"GetAngularCommand");
738 KinovaGetCartesianCommand = (int(*)(CartesianPosition &)) GetProcAddress(m_command_layer_handle,
"GetCartesianCommand");
739 KinovaGetDevices = (int(*)(KinovaDevice[MAX_KINOVA_DEVICE],
int&)) GetProcAddress(m_command_layer_handle,
"GetDevices");
740 KinovaInitAPI = (int(*)()) GetProcAddress(m_command_layer_handle,
"InitAPI");
741 KinovaInitFingers = (int(*)()) GetProcAddress(m_command_layer_handle,
"InitFingers");
742 KinovaMoveHome = (int(*)()) GetProcAddress(m_command_layer_handle,
"MoveHome");
743 KinovaSendBasicTrajectory = (int(*)(TrajectoryPoint)) GetProcAddress(m_command_layer_handle,
"SendBasicTrajectory");
744 KinovaSetActiveDevice = (int(*)(KinovaDevice)) GetProcAddress(m_command_layer_handle,
"SetActiveDevice");
745 KinovaSetAngularControl = (int(*)()) GetProcAddress(m_command_layer_handle,
"SetAngularControl");
746 KinovaSetCartesianControl = (int(*)()) GetProcAddress(m_command_layer_handle,
"SetCartesianControl");
750 if ((KinovaCloseAPI == NULL) ||
751 (KinovaGetAngularCommand == NULL) || (KinovaGetAngularCommand == NULL) || (KinovaGetCartesianCommand == NULL) || (KinovaGetDevices == NULL) ||
752 (KinovaInitAPI == NULL) || (KinovaInitFingers == NULL) ||
753 (KinovaMoveHome == NULL) || (KinovaSendBasicTrajectory == NULL) ||
754 (KinovaSetActiveDevice == NULL) || (KinovaSetAngularControl == NULL) || (KinovaSetCartesianControl == NULL)) {
758 std::cout <<
"Plugin successfully loaded" << std::endl;
771 std::cout <<
"Close plugin" << std::endl;
774 dlclose(m_command_layer_handle);
776 FreeLibrary(m_command_layer_handle);
795 std::cout <<
"Move the robot to home position" << std::endl;
811 int result = (*KinovaInitAPI)();
814 std::cout <<
"Initialization's result: " << result << std::endl;
859 #elif !defined(VISP_BUILD_SHARED_LIBS) 862 void dummy_vpRobotKinova() {};
Used to indicate that a value is not in the allowed range.
Implementation of a matrix and operations on matrices.
Error that can be emited by the vpRobot class and its derivates.
KinovaDevice * m_devices_list
double maxTranslationVelocity
double getMaxTranslationVelocity(void) const
double maxRotationVelocity
error that can be emited by ViSP classes.
static vpColVector saturateVelocities(const vpColVector &v_in, const vpColVector &v_max, bool verbose=false)
unsigned int size() const
Return the number of elements of the 2D array.
double getMaxRotationVelocity(void) const
void setActiveDevice(int device)
Implementation of a rotation matrix and operations on such kind of matrices.
vpHomogeneousMatrix m_eMc
Constant transformation between end-effector and tool (or camera) frame.
void setJointVelocity(const vpColVector &qdot)
static const double maxTranslationVelocityDefault
void getDisplacement(const vpRobot::vpControlFrameType frame, vpColVector &q)
Initialize the velocity controller.
virtual vpRobotStateType getRobotState(void) const
std::string m_plugin_location
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel)
static const double maxRotationVelocityDefault
CommandLayer m_command_layer
void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position)
static double rad(double deg)
void setDoF(unsigned int dof)
void get_fJe(vpMatrix &fJe)
int nDof
number of degrees of freedom
void resize(unsigned int i, bool flagNullify=true)
static double deg(double rad)
vpMatrix eJe
robot Jacobian expressed in the end-effector frame
void get_eJe(vpMatrix &eJe)
Implementation of column vector and the associated operations.
void setCartVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &v)
Implementation of a pose vector and operations on poses.
Implementation of a rotation vector as Euler angle minimal representation.
void insert(const vpMatrix &A, unsigned int r, unsigned int c)
void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &q)
vpMatrix fJe
robot Jacobian expressed in the robot reference frame available
Implementation of a rotation vector as axis-angle minimal representation.
void getJointPosition(vpColVector &q)