36 #include <visp3/core/vpConfig.h>
38 #ifdef VISP_HAVE_FLIR_PTU_SDK
52 #include <visp3/core/vpHomogeneousMatrix.h>
53 #include <visp3/robot/vpRobotFlirPtu.h>
65 std::stringstream msg;
66 msg <<
"Stop the FLIR PTU by signal (" << signo <<
"): " << (char)7;
69 msg <<
"SIGINT (stop by ^C) ";
72 msg <<
"SIGSEGV (stop due to a segmentation fault) ";
76 msg <<
"SIGBUS (stop due to a bus error) ";
79 msg <<
"SIGKILL (stop by CTRL \\) ";
86 msg << signo << std::endl;
111 : 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),
112 m_connected(false), m_njoints(2), m_positioning_velocity(20.)
154 eJe[3][0] = -sin(q[1]);
156 eJe[5][0] = -cos(q[1]);
181 fJe[3][1] = -sin(q[1]);
182 fJe[4][1] = -cos(q[1]);
205 double c1 = cos(q[0]);
206 double c2 = cos(q[1]);
207 double s1 = sin(q[0]);
208 double s2 = sin(q[1]);
212 fMe[0][2] = -c1 * s2;
214 fMe[1][0] = -s1 * c2;
261 "Cannot send a velocity-skew vector in tool frame that is not 6-dim (%d)", v.
size()));
307 std::cout <<
"Not implemented ! " << std::endl;
308 std::cout <<
"To implement me you need : " << std::endl;
309 std::cout <<
"\t to known the robot jacobian expressed in ";
310 std::cout <<
"the end-effector frame (eJe) " << std::endl;
311 std::cout <<
"\t the frame transformation between tool or camera frame ";
312 std::cout <<
"and end-effector frame (cMe)" << std::endl;
326 std::vector<int> vel_tics(2);
328 for (
int i = 0; i < 2; i++) {
329 vel_tics[i] = rad2tics(i, qdot[i]);
337 if (cpi_ptcmd(
m_cer, &
m_status, OP_PAN_DESIRED_SPEED_SET, vel_tics[0]) ||
338 cpi_ptcmd(
m_cer, &
m_status, OP_TILT_DESIRED_SPEED_SET, vel_tics[1])) {
354 "Cannot send a velocity to the robot. "
355 "Call setRobotState(vpRobot::STATE_VELOCITY_CONTROL) once before "
356 "entering your control loop.");
368 if (vel.
size() != 6) {
370 "Cannot apply a Cartesian velocity that is not a 6-dim vector (%d)", vel.
size()));
374 for (
unsigned int i = 0; i < 3; i++)
376 for (
unsigned int i = 3; i < 6; i++)
386 if (vel.
size() !=
static_cast<size_t>(
nDof)) {
417 std::vector<int> pos_tics(2);
419 if (cpi_ptcmd(
m_cer, &
m_status, OP_PAN_CURRENT_POS_GET, &pos_tics[0])) {
423 if (cpi_ptcmd(
m_cer, &
m_status, OP_TILT_CURRENT_POS_GET, &pos_tics[1])) {
429 for (
int i = 0; i < 2; i++) {
430 q[i] = tics2rad(i, pos_tics[i]);
445 std::cout <<
"Not implemented ! " << std::endl;
457 std::cout <<
"FLIR PTU positioning is not implemented in this frame" << std::endl;
471 double vmin = 0.01, vmax = 100.;
472 if (m_positioning_velocity < vmin || m_positioning_velocity > vmax) {
478 std::vector<int> pos_tics(2);
480 for (
int i = 0; i < 2; i++) {
481 pos_tics[i] = rad2tics(i, q[i]);
497 if (cpi_ptcmd(
m_cer, &
m_status, OP_PAN_DESIRED_POS_SET, pos_tics[0]) ||
498 cpi_ptcmd(
m_cer, &
m_status, OP_TILT_DESIRED_POS_SET, pos_tics[1])) {
504 if (cpi_block_until(
m_cer,
nullptr,
nullptr, OP_PAN_CURRENT_POS_GET, pos_tics[0]) ||
505 cpi_block_until(
m_cer,
nullptr,
nullptr, OP_TILT_CURRENT_POS_GET, pos_tics[1])) {
521 std::cout <<
"Not implemented ! " << std::endl;
538 if (portname.empty()) {
543 if ((
m_cer = (
struct cerial *)malloc(
sizeof(
struct cerial))) ==
nullptr) {
549 if (ceropen(
m_cer, portname.c_str(), 0)) {
552 cerstrerror(
m_cer, errstr,
sizeof(errstr))));
555 cerstrerror(
m_cer, errstr,
sizeof(errstr)), portname.c_str()));
561 cerioctl(
m_cer, CERIAL_IOCTL_BAUDRATE_SET, &baudrate);
564 cerioctl(
m_cer, CERIAL_IOCTL_FLUSH_INPUT,
nullptr);
568 if (cerioctl(
m_cer, CERIAL_IOCTL_TIMEOUT_SET, &timeout)) {
585 if ((rc = cpi_ptcmd(
m_cer, &
m_status, OP_EXEC_MODE_SET, (cpi_enum)CPI_IMMEDIATE_MODE))) {
601 if (
m_cer !=
nullptr) {
638 for (
size_t i = 0; i < 2; i++) {
659 return pan_pos_limits;
678 return tilt_pos_limits;
694 for (
int i = 0; i < 2; i++) {
712 if (pan_limits.
size() != 2) {
716 std::vector<int> pan_limits_tics(2);
717 for (
int i = 0; i < 2; i++) {
718 pan_limits_tics[i] = rad2tics(i, pan_limits[i]);
722 if ((status = cpi_ptcmd(
m_cer, &
m_status, OP_PAN_USER_MIN_POS_SET, pan_limits_tics[0])) ||
723 (status = cpi_ptcmd(
m_cer, &
m_status, OP_PAN_USER_MAX_POS_SET, pan_limits_tics[1]))) {
726 cpi_strerror(status)));
742 if (tilt_limits.
size() != 2) {
746 std::vector<int> tilt_limits_tics(2);
747 for (
int i = 0; i < 2; i++) {
748 tilt_limits_tics[i] = rad2tics(i, tilt_limits[i]);
752 if ((status = cpi_ptcmd(
m_cer, &
m_status, OP_TILT_USER_MIN_POS_SET, tilt_limits_tics[0])) ||
753 (status = cpi_ptcmd(
m_cer, &
m_status, OP_TILT_USER_MAX_POS_SET, tilt_limits_tics[1]))) {
756 cpi_strerror(status)));
788 if (cpi_ptcmd(
m_cer, &
m_status, OP_SPEED_CONTROL_MODE_SET, (cpi_enum)CPI_CONTROL_INDEPENDENT)) {
796 std::cout <<
"Change the control mode from velocity to position control.\n";
800 if (cpi_ptcmd(
m_cer, &
m_status, OP_SPEED_CONTROL_MODE_SET, (cpi_enum)CPI_CONTROL_INDEPENDENT)) {
813 std::cout <<
"Change the control mode from stop to velocity control.\n";
816 if (cpi_ptcmd(
m_cer, &
m_status, OP_SPEED_CONTROL_MODE_SET, (cpi_enum)CPI_CONTROL_PURE_VELOCITY)) {
874 if (cpi_ptcmd(
m_cer, &
m_status, OP_NET_IP_GET, (
int)
sizeof(str),
nullptr, &str)) {
878 return (std::string(str));
894 if (cpi_ptcmd(
m_cer, &
m_status, OP_NET_GATEWAY_GET, (
int)
sizeof(str),
nullptr, &str)) {
898 return (std::string(str));
914 if (cpi_ptcmd(
m_cer, &
m_status, OP_NET_HOSTNAME_GET, (
int)
sizeof(str),
nullptr, &str)) {
918 return (std::string(str));
929 int vpRobotFlirPtu::rad2tics(
int axis,
double rad) {
return (
static_cast<int>(
vpMath::deg(rad) /
m_res[axis])); }
939 double vpRobotFlirPtu::tics2deg(
int axis,
int tics) {
return (tics *
m_res[axis]); }
949 double vpRobotFlirPtu::tics2rad(
int axis,
int tics) {
return vpMath::rad(tics2deg(axis, tics)); }
951 #elif !defined(VISP_BUILD_SHARED_LIBS)
954 void dummy_vpRobotFlirPtu() { };
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
unsigned int size() const
Return the number of elements of the 2D array.
Implementation of column vector and the associated operations.
void resize(unsigned int i, bool flagNullify=true)
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
static double rad(double deg)
static double deg(double rad)
Implementation of a matrix and operations on matrices.
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)
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
vpMatrix eJe
robot Jacobian expressed in the end-effector frame
virtual vpRobotStateType getRobotState(void) const
static vpColVector saturateVelocities(const vpColVector &v_in, const vpColVector &v_max, bool verbose=false)
static const double maxRotationVelocityDefault
@ 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.
static const double maxTranslationVelocityDefault
double getMaxRotationVelocity(void) const
vpMatrix fJe
robot Jacobian expressed in the robot reference frame available
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
double maxTranslationVelocity
double getMaxTranslationVelocity(void) const
double maxRotationVelocity
vpVelocityTwistMatrix & buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)