Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpRobotFlirPtu.cpp
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 *
30 * Description:
31 * Interface for Flir Ptu Cpi robot.
32 */
33
34#include <visp3/core/vpConfig.h>
35
36#ifdef VISP_HAVE_FLIR_PTU_SDK
37
38#include <signal.h>
39#include <stdexcept>
40
41extern "C" {
42#include <cpi.h>
43}
44
49
50#include <visp3/core/vpHomogeneousMatrix.h>
51#include <visp3/robot/vpRobotFlirPtu.h>
52
62{
63 std::stringstream msg;
64 msg << "Stop the FLIR PTU by signal (" << signo << "): " << static_cast<char>(7);
65 switch (signo) {
66 case SIGINT:
67 msg << "SIGINT (stop by ^C) ";
68 break;
69 case SIGSEGV:
70 msg << "SIGSEGV (stop due to a segmentation fault) ";
71 break;
72#ifndef _WIN32
73 case SIGBUS:
74 msg << "SIGBUS (stop due to a bus error) ";
75 break;
76 case SIGKILL:
77 msg << "SIGKILL (stop by CTRL \\) ";
78 break;
79 case SIGQUIT:
80 msg << "SIGQUIT ";
81 break;
82#endif
83 default:
84 msg << signo << std::endl;
85 }
86
88}
89
94{
95 // If you want to control the robot in Cartesian in a tool frame, set the corresponding transformation in m_eMc
96 // that is set to identity by default in the constructor.
97
100
101 // Set here the robot degrees of freedom number
102 nDof = 2; // Flir Ptu has 2 dof
103}
104
109 : m_eMc(), m_cer(nullptr), m_status(0), m_pos_max_tics(2), m_pos_min_tics(2), m_vel_max_tics(2), m_res(2),
111{
112 signal(SIGINT, vpRobotFlirPtu::emergencyStop);
113 signal(SIGSEGV, vpRobotFlirPtu::emergencyStop);
114#ifndef _WIN32
115 signal(SIGBUS, vpRobotFlirPtu::emergencyStop);
116 signal(SIGKILL, vpRobotFlirPtu::emergencyStop);
117 signal(SIGQUIT, vpRobotFlirPtu::emergencyStop);
118#endif
119
120 init();
121}
122
131
132/*
133 At least one of these function has to be implemented to control the robot with a
134 Cartesian velocity:
135 - get_eJe()
136 - get_fJe()
137*/
138
146{
148 vpColVector q;
150 eJe.resize(6, 2);
151 eJe = 0;
152 eJe[3][0] = -sin(q[1]);
153 eJe[4][1] = -1;
154 eJe[5][0] = -cos(q[1]);
155 return eJe;
156}
157
165
173{
175 vpColVector q;
177 fJe.resize(6, 2);
178 fJe = 0;
179 fJe[3][1] = -sin(q[1]);
180 fJe[4][1] = -cos(q[1]);
181 fJe[5][0] = -1;
182
183 return fJe;
184}
185
193
199{
201 vpColVector q;
203 double c1 = cos(q[0]);
204 double c2 = cos(q[1]);
205 double s1 = sin(q[0]);
206 double s2 = sin(q[1]);
207
208 fMe[0][0] = c1 * c2;
209 fMe[0][1] = s1;
210 fMe[0][2] = -c1 * s2;
211
212 fMe[1][0] = -s1 * c2;
213 fMe[1][1] = c1;
214 fMe[1][2] = s1 * s2;
215
216 fMe[2][0] = s2;
217 fMe[2][1] = 0;
218 fMe[2][2] = c2;
219
220 return fMe;
221}
222
236{
238 cVe.buildFrom(m_eMc.inverse());
239
240 return cVe;
241}
242
243/*
244 At least one of these function has to be implemented to control the robot:
245 - setCartVelocity()
246 - setJointVelocity()
247*/
248
256{
257 if (v.size() != 6) {
259 "Cannot send a velocity-skew vector in tool frame that is not 6-dim (%d)", v.size()));
260 }
261
262 vpColVector v_e; // This is the velocity that the robot is able to apply in the end-effector frame
263 switch (frame) {
264 case vpRobot::TOOL_FRAME: {
265 // We have to transform the requested velocity in the end-effector frame.
266 // Knowing that the constant transformation between the tool frame and the end-effector frame obtained
267 // by extrinsic calibration is set in m_eMc we can compute the velocity twist matrix eVc that transform
268 // a velocity skew from tool (or camera) frame into end-effector frame
270 v_e = eVc * v;
271 break;
272 }
273
276 v_e = v;
277 break;
278 }
281 // Out of the scope
282 break;
283 }
284
285 // Implement your stuff here to send the end-effector velocity skew v_e
286 // - If the SDK allows to send cartesian velocities in the end-effector, it's done. Just wrap data in v_e
287 // - If the SDK allows to send cartesian velocities in the reference (or base) frame you have to implement
288 // the robot Jacobian in set_fJe() and call:
289 // vpColVector v = get_fJe().inverse() * v_e;
290 // At this point you have to wrap data in v that is the 6-dim velocity to apply to the robot
291 // - If the SDK allows to send only joint velocities you have to implement the robot Jacobian in set_eJe()
292 // and call:
293 // vpColVector qdot = get_eJe().inverse() * v_e;
294 // setJointVelocity(qdot);
295 // - If the SDK allows to send only a cartesian position trajectory of the end-effector position in the base frame
296 // called fMe (for fix frame to end-effector homogeneous transformation) you can transform the cartesian
297 // velocity in the end-effector into a displacement eMe using the exponetial map:
298 // double delta_t = 0.010; // in sec
299 // vpHomogenesousMatrix eMe = vpExponentialMap::direct(v_e, delta_t);
300 // vpHomogenesousMatrix fMe = getPosition(vpRobot::REFERENCE_FRAME);
301 // the new position to reach is than given by fMe * eMe
302 // vpColVector fpe(vpPoseVector(fMe * eMe));
303 // setPosition(vpRobot::REFERENCE_FRAME, fpe);
304
305 std::cout << "Not implemented ! " << std::endl;
306 std::cout << "To implement me you need : " << std::endl;
307 std::cout << "\t to known the robot jacobian expressed in ";
308 std::cout << "the end-effector frame (eJe) " << std::endl;
309 std::cout << "\t the frame transformation between tool or camera frame ";
310 std::cout << "and end-effector frame (cMe)" << std::endl;
311}
312
318{
319 if (!m_connected) {
320 disconnect();
321 throw(vpException(vpException::fatalError, "FLIR PTU is not connected."));
322 }
323
324 std::vector<int> vel_tics(2);
325
326 for (int i = 0; i < 2; i++) {
327 vel_tics[i] = rad2tics(i, qdot[i]);
328 if (std::fabs(vel_tics[i]) > m_vel_max_tics[i]) {
329 disconnect();
330 throw(vpException(vpException::fatalError, "Cannot set joint %d velocity %f (deg/s). Out of limits [-%f, %f].", i,
331 vpMath::deg(qdot[i]), -tics2deg(i, m_vel_max_tics[i]), tics2deg(i, m_vel_max_tics[i])));
332 }
333 }
334
335 if (cpi_ptcmd(m_cer, &m_status, OP_PAN_DESIRED_SPEED_SET, vel_tics[0]) ||
336 cpi_ptcmd(m_cer, &m_status, OP_TILT_DESIRED_SPEED_SET, vel_tics[1])) {
337 throw(vpException(vpException::fatalError, "Unable to set velocity."));
338 }
339}
340
349{
352 "Cannot send a velocity to the robot. "
353 "Call setRobotState(vpRobot::STATE_VELOCITY_CONTROL) once before "
354 "entering your control loop.");
355 }
356
357 vpColVector vel_sat(6);
358
359 // Velocity saturation
360 switch (frame) {
361 // Saturation in cartesian space
365 case vpRobot::MIXT_FRAME: {
366 if (vel.size() != 6) {
368 "Cannot apply a Cartesian velocity that is not a 6-dim vector (%d)", vel.size()));
369 }
370 vpColVector vel_max(6);
371
372 for (unsigned int i = 0; i < 3; i++)
373 vel_max[i] = getMaxTranslationVelocity();
374 for (unsigned int i = 3; i < 6; i++)
375 vel_max[i] = getMaxRotationVelocity();
376
377 vel_sat = vpRobot::saturateVelocities(vel, vel_max, true);
378
379 setCartVelocity(frame, vel_sat);
380 break;
381 }
382 // Saturation in joint space
384 if (vel.size() != static_cast<size_t>(nDof)) {
385 throw(vpException(vpException::dimensionError, "Cannot apply a joint velocity that is not a %d-dim vector (%d)",
386 nDof, vel.size()));
387 }
388 vpColVector vel_max(vel.size());
389
390 // Since the robot has only rotation axis all the joint max velocities are set to getMaxRotationVelocity()
391 vel_max = getMaxRotationVelocity();
392
393 vel_sat = vpRobot::saturateVelocities(vel, vel_max, true);
394
395 setJointVelocity(vel_sat);
396 }
397 }
398}
399
400/*
401 THESE FUNCTIONS ARE NOT MANDATORY BUT ARE USUALLY USEFUL
402*/
403
409{
410 if (!m_connected) {
411 disconnect();
412 throw(vpException(vpException::fatalError, "FLIR PTU is not connected."));
413 }
414
415 std::vector<int> pos_tics(2);
416
417 if (cpi_ptcmd(m_cer, &m_status, OP_PAN_CURRENT_POS_GET, &pos_tics[0])) {
418 disconnect();
419 throw(vpException(vpException::fatalError, "Unable to query pan position."));
420 }
421 if (cpi_ptcmd(m_cer, &m_status, OP_TILT_CURRENT_POS_GET, &pos_tics[1])) {
422 disconnect();
423 throw(vpException(vpException::fatalError, "Unable to query pan position."));
424 }
425
426 q.resize(2);
427 for (int i = 0; i < 2; i++) {
428 q[i] = tics2rad(i, pos_tics[i]);
429 }
430}
431
438{
439 if (frame == JOINT_STATE) {
441 }
442 else {
443 std::cout << "Not implemented ! " << std::endl;
444 }
445}
446
453{
454 if (frame != vpRobot::JOINT_STATE) {
455 std::cout << "FLIR PTU positioning is not implemented in this frame" << std::endl;
456 return;
457 }
458
459 if (q.size() != 2) {
460 disconnect();
461 throw(vpException(vpException::fatalError, "FLIR PTU has only %d joints. Cannot set a position that is %d-dim.",
462 m_njoints, q.size()));
463 }
464 if (!m_connected) {
465 disconnect();
466 throw(vpException(vpException::fatalError, "FLIR PTU is not connected."));
467 }
468
469 double vmin = 0.01, vmax = 100.;
471 disconnect();
472 throw(
473 vpException(vpException::fatalError, "FLIR PTU Positioning velocity %f is not in range [%f, %f]", vmin, vmax));
474 }
475
476 std::vector<int> pos_tics(2);
477
478 for (int i = 0; i < 2; i++) {
479 pos_tics[i] = rad2tics(i, q[i]);
480 if (pos_tics[i] < m_pos_min_tics[i] || pos_tics[i] > m_pos_max_tics[i]) {
481 disconnect();
482 throw(vpException(vpException::fatalError, "Cannot set joint %d position %f (deg). Out of limits [%f, %f].", i,
483 vpMath::deg(q[i]), tics2deg(i, m_pos_min_tics[i]), tics2deg(i, m_pos_max_tics[i])));
484 }
485 }
486
487 // Set desired speed wrt max pan/tilt speed
488 if (cpi_ptcmd(m_cer, &m_status, OP_PAN_DESIRED_SPEED_SET, static_cast<int>(m_vel_max_tics[0] * m_positioning_velocity / 100.)) ||
489 cpi_ptcmd(m_cer, &m_status, OP_TILT_DESIRED_SPEED_SET,
490 static_cast<int>(m_vel_max_tics[1] * m_positioning_velocity / 100.))) {
491 disconnect();
492 throw(vpException(vpException::fatalError, "Setting FLIR pan/tilt positioning velocity failed"));
493 }
494
495 if (cpi_ptcmd(m_cer, &m_status, OP_PAN_DESIRED_POS_SET, pos_tics[0]) ||
496 cpi_ptcmd(m_cer, &m_status, OP_TILT_DESIRED_POS_SET, pos_tics[1])) {
497 disconnect();
498 throw(vpException(vpException::fatalError, "FLIR PTU failed to go to position %d, %d (deg).", vpMath::deg(q[0]),
499 vpMath::deg(q[1])));
500 }
501
502 if (cpi_block_until(m_cer, nullptr, nullptr, OP_PAN_CURRENT_POS_GET, pos_tics[0]) ||
503 cpi_block_until(m_cer, nullptr, nullptr, OP_TILT_CURRENT_POS_GET, pos_tics[1])) {
504 disconnect();
505 throw(vpException(vpException::fatalError, "FLIR PTU failed to wait until position %d, %d reached (deg)",
506 vpMath::deg(q[0]), vpMath::deg(q[1])));
507 }
508}
509
516{
517 (void)frame;
518 (void)q;
519 std::cout << "Not implemented ! " << std::endl;
520}
521
528void vpRobotFlirPtu::connect(const std::string &portname, int baudrate)
529{
530 char errstr[128];
531
532 if (m_connected) {
533 disconnect();
534 }
535
536 if (portname.empty()) {
537 disconnect();
538 throw(vpException(vpException::fatalError, "Port name is required to connect to FLIR PTU."));
539 }
540
541 if ((m_cer = (struct cerial *)malloc(sizeof(struct cerial))) == nullptr) {
542 disconnect();
543 throw(vpException(vpException::fatalError, "Out of memory during FLIR PTU connection."));
544 }
545
546 // Open a port
547 if (ceropen(m_cer, portname.c_str(), 0)) {
548#if _WIN32
549 throw(vpException(vpException::fatalError, "Failed to open %s: %s.", portname.c_str(),
550 cerstrerror(m_cer, errstr, sizeof(errstr))));
551#else
552 throw(vpException(vpException::fatalError, "Failed to open %s: %s.\nRun `sudo chmod a+rw %s`", portname.c_str(),
553 cerstrerror(m_cer, errstr, sizeof(errstr)), portname.c_str()));
554#endif
555 }
556
557 // Set baudrate
558 // ignore errors since not all devices are serial ports
559 cerioctl(m_cer, CERIAL_IOCTL_BAUDRATE_SET, &baudrate);
560
561 // Flush any characters already buffered
562 cerioctl(m_cer, CERIAL_IOCTL_FLUSH_INPUT, nullptr);
563
564 // Set two second timeout */
565 int timeout = 2000;
566 if (cerioctl(m_cer, CERIAL_IOCTL_TIMEOUT_SET, &timeout)) {
567 disconnect();
568 throw(vpException(vpException::fatalError, "cerial: timeout ioctl not supported."));
569 }
570
571 // Sync and lock
572 int trial = 0;
573 do {
574 trial++;
575 } while (trial <= 3 && (cpi_resync(m_cer) || cpi_ptcmd(m_cer, &m_status, OP_NOOP)));
576 if (trial > 3) {
577 disconnect();
578 throw(vpException(vpException::fatalError, "Cannot communicate with FLIR PTU."));
579 }
580
581 // Immediately execute commands (slave mode should be opt-in)
582 int rc;
583 if ((rc = cpi_ptcmd(m_cer, &m_status, OP_EXEC_MODE_SET, (cpi_enum)CPI_IMMEDIATE_MODE))) {
584 disconnect();
585 throw(vpException(vpException::fatalError, "Set Immediate Mode failed: %s", cpi_strerror(rc)));
586 }
587
588 m_connected = true;
589
590 getLimits();
591}
592
598{
599 if (m_cer != nullptr) {
600 cerclose(m_cer);
601 free(m_cer);
602 m_cer = nullptr;
603 m_connected = false;
604 }
605}
606
611{
612 if (!m_connected) {
613 disconnect();
614 throw(vpException(vpException::fatalError, "FLIR PTU is not connected."));
615 }
616
617 int status;
618
619 if ((status = cpi_ptcmd(m_cer, &m_status, OP_PAN_MAX_POSITION, &m_pos_max_tics[0])) ||
620 (status = cpi_ptcmd(m_cer, &m_status, OP_PAN_MIN_POSITION, &m_pos_min_tics[0])) ||
621 (status = cpi_ptcmd(m_cer, &m_status, OP_TILT_MAX_POSITION, &m_pos_max_tics[1])) ||
622 (status = cpi_ptcmd(m_cer, &m_status, OP_TILT_MIN_POSITION, &m_pos_min_tics[1])) ||
623 (status = cpi_ptcmd(m_cer, &m_status, OP_PAN_UPPER_SPEED_LIMIT_GET, &m_vel_max_tics[0])) ||
624 (status = cpi_ptcmd(m_cer, &m_status, OP_TILT_UPPER_SPEED_LIMIT_GET, &m_vel_max_tics[1]))) {
625 disconnect();
626 throw(vpException(vpException::fatalError, "Failed to get limits (%d) %s.", status, cpi_strerror(status)));
627 }
628
629 // Get the ptu resolution so we can convert the angles to ptu positions
630 if ((status = cpi_ptcmd(m_cer, &m_status, OP_PAN_RESOLUTION, &m_res[0])) ||
631 (status = cpi_ptcmd(m_cer, &m_status, OP_TILT_RESOLUTION, &m_res[1]))) {
632 disconnect();
633 throw(vpException(vpException::fatalError, "Failed to get resolution (%d) %s.", status, cpi_strerror(status)));
634 }
635
636 for (size_t i = 0; i < 2; i++) {
637 m_res[i] /= 3600.; // Resolutions are in arc-seconds, but we want degrees
638 }
639}
640
648{
649 if (!m_connected) {
650 disconnect();
651 throw(vpException(vpException::fatalError, "FLIR PTU is not connected."));
652 }
653 vpColVector pan_pos_limits(2);
654 pan_pos_limits[0] = tics2rad(0, m_pos_min_tics[0]);
655 pan_pos_limits[1] = tics2rad(0, m_pos_max_tics[0]);
656
657 return pan_pos_limits;
658}
659
667{
668 if (!m_connected) {
669 disconnect();
670 throw(vpException(vpException::fatalError, "FLIR PTU is not connected."));
671 }
672 vpColVector tilt_pos_limits(2);
673 tilt_pos_limits[0] = tics2rad(0, m_pos_min_tics[1]);
674 tilt_pos_limits[1] = tics2rad(0, m_pos_max_tics[1]);
675
676 return tilt_pos_limits;
677}
678
686{
687 if (!m_connected) {
688 disconnect();
689 throw(vpException(vpException::fatalError, "FLIR PTU is not connected."));
690 }
691 vpColVector vel_max(2);
692 for (int i = 0; i < 2; i++) {
693 vel_max[i] = tics2rad(i, m_vel_max_tics[i]);
694 }
695 return vel_max;
696}
697
705{
706 if (!m_connected) {
707 disconnect();
708 throw(vpException(vpException::fatalError, "FLIR PTU is not connected."));
709 }
710 if (pan_limits.size() != 2) {
711 disconnect();
712 throw(vpException(vpException::fatalError, "Cannot set max position that is not a 2-dim vector."));
713 }
714 std::vector<int> pan_limits_tics(2);
715 for (int i = 0; i < 2; i++) {
716 pan_limits_tics[i] = rad2tics(i, pan_limits[i]);
717 }
718
719 int status;
720 if ((status = cpi_ptcmd(m_cer, &m_status, OP_PAN_USER_MIN_POS_SET, pan_limits_tics[0])) ||
721 (status = cpi_ptcmd(m_cer, &m_status, OP_PAN_USER_MAX_POS_SET, pan_limits_tics[1]))) {
722 disconnect();
723 throw(vpException(vpException::fatalError, "Failed to set pan position limits (%d) %s.", status,
724 cpi_strerror(status)));
725 }
726}
727
735{
736 if (!m_connected) {
737 disconnect();
738 throw(vpException(vpException::fatalError, "FLIR PTU is not connected."));
739 }
740 if (tilt_limits.size() != 2) {
741 disconnect();
742 throw(vpException(vpException::fatalError, "Cannot set max position that is not a 2-dim vector."));
743 }
744 std::vector<int> tilt_limits_tics(2);
745 for (int i = 0; i < 2; i++) {
746 tilt_limits_tics[i] = rad2tics(i, tilt_limits[i]);
747 }
748
749 int status;
750 if ((status = cpi_ptcmd(m_cer, &m_status, OP_TILT_USER_MIN_POS_SET, tilt_limits_tics[0])) ||
751 (status = cpi_ptcmd(m_cer, &m_status, OP_TILT_USER_MAX_POS_SET, tilt_limits_tics[1]))) {
752 disconnect();
753 throw(vpException(vpException::fatalError, "Failed to set tilt position limits (%d) %s.", status,
754 cpi_strerror(status)));
755 }
756}
757
765
774{
775 if (!m_connected) {
776 return getRobotState();
777 }
778
779 switch (newState) {
780 case vpRobot::STATE_STOP: {
781 // Start primitive STOP only if the current state is Velocity
783 stopMotion();
784
785 // Set the PTU to pure velocity mode
786 if (cpi_ptcmd(m_cer, &m_status, OP_SPEED_CONTROL_MODE_SET, (cpi_enum)CPI_CONTROL_INDEPENDENT)) {
787 throw(vpException(vpException::fatalError, "Unable to set control mode independent."));
788 }
789 }
790 break;
791 }
794 std::cout << "Change the control mode from velocity to position control.\n";
795 stopMotion();
796
797 // Set the PTU to pure velocity mode
798 if (cpi_ptcmd(m_cer, &m_status, OP_SPEED_CONTROL_MODE_SET, (cpi_enum)CPI_CONTROL_INDEPENDENT)) {
799 throw(vpException(vpException::fatalError, "Unable to set control mode independent."));
800 }
801
802 }
803 else {
804 // std::cout << "Change the control mode from stop to position
805 // control.\n";
806 }
807 break;
808 }
811 std::cout << "Change the control mode from stop to velocity control.\n";
812
813 // Set the PTU to pure velocity mode
814 if (cpi_ptcmd(m_cer, &m_status, OP_SPEED_CONTROL_MODE_SET, (cpi_enum)CPI_CONTROL_PURE_VELOCITY)) {
815 throw(vpException(vpException::fatalError, "Unable to set velocity control mode."));
816 }
817 }
818 break;
819 }
820 default:
821 break;
822 }
823
824 return vpRobot::setRobotState(newState);
825}
826
831{
832 if (!m_connected) {
833 return;
834 }
835
836 if (cpi_ptcmd(m_cer, &m_status, OP_RESET, nullptr)) {
837 throw(vpException(vpException::fatalError, "Unable to reset PTU."));
838 }
839}
840
845{
847 return;
848 }
849
850 if (!m_connected) {
851 return;
852 }
853
854 if (cpi_ptcmd(m_cer, &m_status, OP_HALT, nullptr)) {
855 throw(vpException(vpException::fatalError, "Unable to stop PTU."));
856 }
857}
858
865{
866 if (!m_connected) {
867 disconnect();
868 throw(vpException(vpException::fatalError, "FLIR PTU is not connected."));
869 }
870
871 char str[64];
872 if (cpi_ptcmd(m_cer, &m_status, OP_NET_IP_GET, static_cast<int>(sizeof(str)), nullptr, &str)) {
873 throw(vpException(vpException::fatalError, "Unable to get Network IP."));
874 }
875
876 return (std::string(str));
877}
878
885{
886 if (!m_connected) {
887 disconnect();
888 throw(vpException(vpException::fatalError, "FLIR PTU is not connected."));
889 }
890
891 char str[64];
892 if (cpi_ptcmd(m_cer, &m_status, OP_NET_GATEWAY_GET, static_cast<int>(sizeof(str)), nullptr, &str)) {
893 throw(vpException(vpException::fatalError, "Unable to get Network Gateway."));
894 }
895
896 return (std::string(str));
897}
898
905{
906 if (!m_connected) {
907 disconnect();
908 throw(vpException(vpException::fatalError, "FLIR PTU is not connected."));
909 }
910
911 char str[64];
912 if (cpi_ptcmd(m_cer, &m_status, OP_NET_HOSTNAME_GET, static_cast<int>(sizeof(str)), nullptr, &str)) {
913 throw(vpException(vpException::fatalError, "Unable to get Network hostname."));
914 }
915
916 return (std::string(str));
917}
918
927int vpRobotFlirPtu::rad2tics(int axis, double rad) { return (static_cast<int>(vpMath::deg(rad) / m_res[axis])); }
928
937double vpRobotFlirPtu::tics2deg(int axis, int tics) { return (tics * m_res[axis]); }
938
947double vpRobotFlirPtu::tics2rad(int axis, int tics) { return vpMath::rad(tics2deg(axis, tics)); }
948END_VISP_NAMESPACE
949#elif !defined(VISP_BUILD_SHARED_LIBS)
950// Work around to avoid warning: libvisp_robot.a(vpRobotFlirPtu.cpp.o) has
951// no symbols
952void dummy_vpRobotFlirPtu() { }
953#endif
unsigned int size() const
Return the number of elements of the 2D array.
Definition vpArray2D.h:435
Implementation of column vector and the associated operations.
void resize(unsigned int i, bool flagNullify=true)
error that can be emitted by ViSP classes.
Definition vpException.h:60
@ dimensionError
Bad dimension.
Definition vpException.h:71
@ fatalError
Fatal error.
Definition vpException.h:72
Implementation of an homogeneous matrix and operations on such kind of matrices.
static double rad(double deg)
Definition vpMath.h:129
static double deg(double rad)
Definition vpMath.h:119
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:175
Error that can be emitted by the vpRobot class and its derivatives.
@ wrongStateError
Wrong robot state.
@ signalException
Signal exception returned after SIGINT (CTRL-C), SIGBUS, SIGSEGV, SIGSEGV (CTRL-),...
vpHomogeneousMatrix m_eMc
Constant transformation between end-effector and tool (or camera) frame.
std::vector< int > m_pos_max_tics
Pan min/max position in robot tics unit.
void connect(const std::string &portname, int baudrate=9600)
vpColVector getTiltPosLimits()
vpColVector getPanPosLimits()
double m_positioning_velocity
std::string getNetworkGateway()
void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q) VP_OVERRIDE
std::vector< double > m_res
Pan/tilt tic resolution in deg.
void setPositioningVelocity(double velocity)
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) VP_OVERRIDE
virtual ~vpRobotFlirPtu()
std::string getNetworkIP()
void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &q) VP_OVERRIDE
std::vector< int > m_vel_max_tics
Pan/tilt max velocity in robot tics unit.
void setCartVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &v)
struct cerial * m_cer
vpVelocityTwistMatrix get_cVe() const
void getJointPosition(vpColVector &q)
std::string getNetworkHostName()
void setJointVelocity(const vpColVector &qdot)
static void emergencyStop(int signo)
void setPanPosLimits(const vpColVector &pan_limits)
std::vector< int > m_pos_min_tics
Tilt min/max position in robot tics unit.
vpColVector getPanTiltVelMax()
vpRobot::vpRobotStateType setRobotState(vpRobot::vpRobotStateType newState)
void getDisplacement(const vpRobot::vpControlFrameType frame, vpColVector &q) VP_OVERRIDE
void setTiltPosLimits(const vpColVector &tilt_limits)
int nDof
number of degrees of freedom
Definition vpRobot.h:101
vpMatrix eJe
robot Jacobian expressed in the end-effector frame
Definition vpRobot.h:103
virtual vpRobotStateType getRobotState(void) const
Definition vpRobot.h:152
static vpColVector saturateVelocities(const vpColVector &v_in, const vpColVector &v_max, bool verbose=false)
Definition vpRobot.cpp:162
vpControlFrameType
Definition vpRobot.h:74
@ REFERENCE_FRAME
Definition vpRobot.h:75
@ JOINT_STATE
Definition vpRobot.h:79
@ TOOL_FRAME
Definition vpRobot.h:83
@ MIXT_FRAME
Definition vpRobot.h:85
@ END_EFFECTOR_FRAME
Definition vpRobot.h:80
static const double maxRotationVelocityDefault
Definition vpRobot.h:98
vpRobotStateType
Definition vpRobot.h:62
@ STATE_POSITION_CONTROL
Initialize the position controller.
Definition vpRobot.h:65
@ STATE_VELOCITY_CONTROL
Initialize the velocity controller.
Definition vpRobot.h:64
@ STATE_STOP
Stops robot motion especially in velocity and acceleration control.
Definition vpRobot.h:63
static const double maxTranslationVelocityDefault
Definition vpRobot.h:96
double getMaxRotationVelocity(void) const
Definition vpRobot.cpp:272
vpMatrix fJe
robot Jacobian expressed in the robot reference frame available
Definition vpRobot.h:107
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
Definition vpRobot.cpp:200
double maxTranslationVelocity
Definition vpRobot.h:95
double getMaxTranslationVelocity(void) const
Definition vpRobot.cpp:250
double maxRotationVelocity
Definition vpRobot.h:97
vpVelocityTwistMatrix & buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)