39 #include <visp3/core/vpConfig.h> 41 #ifdef VISP_HAVE_FLIR_PTU_SDK 55 #include <visp3/core/vpHomogeneousMatrix.h> 56 #include <visp3/robot/vpRobotFlirPtu.h> 67 std::stringstream msg;
68 msg <<
"Stop the FLIR PTU by signal (" << signo <<
"): " << (char)7;
71 msg <<
"SIGINT (stop by ^C) ";
74 msg <<
"SIGSEGV (stop due to a segmentation fault) ";
78 msg <<
"SIGBUS (stop due to a bus error) ";
81 msg <<
"SIGKILL (stop by CTRL \\) ";
88 msg << signo << std::endl;
156 eJe[3][0] = -sin(q[1]);
158 eJe[5][0] = -cos(q[1]);
183 fJe[3][1] = -sin(q[1]);
184 fJe[4][1] = -cos(q[1]);
207 double c1 = cos(q[0]);
208 double c2 = cos(q[1]);
209 double s1 = sin(q[0]);
210 double s2 = sin(q[1]);
214 fMe[0][2] = -c1 * s2;
216 fMe[1][0] = -s1 * c2;
263 "Cannot send a velocity-skew vector in tool frame that is not 6-dim (%d)", v.
size()));
309 std::cout <<
"Not implemented ! " << std::endl;
310 std::cout <<
"To implement me you need : " << std::endl;
311 std::cout <<
"\t to known the robot jacobian expressed in ";
312 std::cout <<
"the end-effector frame (eJe) " << std::endl;
313 std::cout <<
"\t the frame transformation between tool or camera frame ";
314 std::cout <<
"and end-effector frame (cMe)" << std::endl;
328 std::vector<int> vel_tics(2);
330 for (
int i = 0; i < 2; i++) {
331 vel_tics[i] = rad2tics(i, qdot[i]);
339 if (cpi_ptcmd(
m_cer, &
m_status, OP_PAN_DESIRED_SPEED_SET, vel_tics[0]) ||
340 cpi_ptcmd(
m_cer, &
m_status, OP_TILT_DESIRED_SPEED_SET, vel_tics[1])) {
356 "Cannot send a velocity to the robot. " 357 "Call setRobotState(vpRobot::STATE_VELOCITY_CONTROL) once before " 358 "entering your control loop.");
370 if (vel.
size() != 6) {
372 "Cannot apply a Cartesian velocity that is not a 6-dim vector (%d)", vel.
size()));
376 for (
unsigned int i = 0; i < 3; i++)
378 for (
unsigned int i = 3; i < 6; i++)
388 if (vel.
size() !=
static_cast<size_t>(
nDof)) {
419 std::vector<int> pos_tics(2);
421 if (cpi_ptcmd(
m_cer, &
m_status, OP_PAN_CURRENT_POS_GET, &pos_tics[0])) {
425 if (cpi_ptcmd(
m_cer, &
m_status, OP_TILT_CURRENT_POS_GET, &pos_tics[1])) {
431 for (
int i = 0; i < 2; i++) {
432 q[i] = tics2rad(i, pos_tics[i]);
446 std::cout <<
"Not implemented ! " << std::endl;
458 std::cout <<
"FLIR PTU positioning is not implemented in this frame" << std::endl;
472 double vmin = 0.01, vmax = 100.;
473 if (m_positioning_velocity < vmin || m_positioning_velocity > vmax) {
479 std::vector<int> pos_tics(2);
481 for (
int i = 0; i < 2; i++) {
482 pos_tics[i] = rad2tics(i, q[i]);
498 if (cpi_ptcmd(
m_cer, &
m_status, OP_PAN_DESIRED_POS_SET, pos_tics[0]) ||
499 cpi_ptcmd(
m_cer, &
m_status, OP_TILT_DESIRED_POS_SET, pos_tics[1])) {
505 if (cpi_block_until(
m_cer, NULL, NULL, OP_PAN_CURRENT_POS_GET, pos_tics[0]) ||
506 cpi_block_until(
m_cer, NULL, NULL, OP_TILT_CURRENT_POS_GET, pos_tics[1])) {
522 std::cout <<
"Not implemented ! " << std::endl;
539 if (portname.empty()) {
544 if ((
m_cer = (
struct cerial *)malloc(
sizeof(
struct cerial))) == NULL) {
550 if (ceropen(
m_cer, portname.c_str(), 0)) {
553 cerstrerror(
m_cer, errstr,
sizeof(errstr))));
556 cerstrerror(
m_cer, errstr,
sizeof(errstr)), portname.c_str()));
562 cerioctl(
m_cer, CERIAL_IOCTL_BAUDRATE_SET, &baudrate);
565 cerioctl(
m_cer, CERIAL_IOCTL_FLUSH_INPUT, NULL);
569 if (cerioctl(
m_cer, CERIAL_IOCTL_TIMEOUT_SET, &timeout)) {
586 if ((rc = cpi_ptcmd(
m_cer, &
m_status, OP_EXEC_MODE_SET, (cpi_enum)CPI_IMMEDIATE_MODE))) {
639 for (
size_t i = 0; i < 2; i++) {
660 return pan_pos_limits;
679 return tilt_pos_limits;
695 for (
int i = 0; i < 2; i++) {
713 if (pan_limits.
size() != 2) {
717 std::vector<int> pan_limits_tics(2);
718 for (
int i = 0; i < 2; i++) {
719 pan_limits_tics[i] = rad2tics(i, pan_limits[i]);
723 if ((status = cpi_ptcmd(
m_cer, &
m_status, OP_PAN_USER_MIN_POS_SET, pan_limits_tics[0])) ||
724 (status = cpi_ptcmd(
m_cer, &
m_status, OP_PAN_USER_MAX_POS_SET, pan_limits_tics[1]))) {
727 cpi_strerror(status)));
743 if (tilt_limits.
size() != 2) {
747 std::vector<int> tilt_limits_tics(2);
748 for (
int i = 0; i < 2; i++) {
749 tilt_limits_tics[i] = rad2tics(i, tilt_limits[i]);
753 if ((status = cpi_ptcmd(
m_cer, &
m_status, OP_TILT_USER_MIN_POS_SET, tilt_limits_tics[0])) ||
754 (status = cpi_ptcmd(
m_cer, &
m_status, OP_TILT_USER_MAX_POS_SET, tilt_limits_tics[1]))) {
757 cpi_strerror(status)));
789 if (cpi_ptcmd(
m_cer, &
m_status, OP_SPEED_CONTROL_MODE_SET, (cpi_enum)CPI_CONTROL_INDEPENDENT)) {
797 std::cout <<
"Change the control mode from velocity to position control.\n";
801 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), NULL, &str)) {
878 return (std::string(str));
894 if (cpi_ptcmd(
m_cer, &
m_status, OP_NET_GATEWAY_GET, (
int)
sizeof(str), NULL, &str)) {
898 return (std::string(str));
914 if (cpi_ptcmd(
m_cer, &
m_status, OP_NET_HOSTNAME_GET, (
int)
sizeof(str), NULL, &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 setTiltPosLimits(const vpColVector &tilt_limits)
Implementation of a matrix and operations on matrices.
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
Error that can be emited by the vpRobot class and its derivates.
vpHomogeneousMatrix m_eMc
Constant transformation between end-effector and tool (or camera) frame.
void setPanPosLimits(const vpColVector &pan_limits)
Implementation of an homogeneous matrix and operations on such kind of matrices.
virtual ~vpRobotFlirPtu()
double maxTranslationVelocity
std::vector< double > m_res
Pan/tilt tic resolution in deg.
std::vector< int > m_vel_max_tics
Pan/tilt max velocity in robot tics unit.
vpColVector getTiltPosLimits()
double maxRotationVelocity
double getMaxTranslationVelocity(void) const
std::string getNetworkHostName()
void setPositioningVelocity(double velocity)
Initialize the position controller.
void getDisplacement(const vpRobot::vpControlFrameType frame, vpColVector &q)
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
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)
vpColVector getPanPosLimits()
void getJointPosition(vpColVector &q)
std::string getNetworkGateway()
static const double maxTranslationVelocityDefault
static void emergencyStop(int signo)
Initialize the velocity controller.
vpRobot::vpRobotStateType setRobotState(vpRobot::vpRobotStateType newState)
vpVelocityTwistMatrix buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
std::vector< int > m_pos_max_tics
Pan min/max position in robot tics unit.
vpColVector getPanTiltVelMax()
static const double maxRotationVelocityDefault
void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q)
double m_positioning_velocity
void setCartVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &v)
std::vector< int > m_pos_min_tics
Tilt min/max position in robot tics unit.
static double rad(double deg)
Stops robot motion especially in velocity and acceleration control.
vpVelocityTwistMatrix get_cVe() const
void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &q)
void connect(const std::string &portname, int baudrate=9600)
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
std::string getNetworkIP()
Implementation of column vector and the associated operations.
vpHomogeneousMatrix inverse() const
virtual vpRobotStateType getRobotState(void) const
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel)
vpMatrix fJe
robot Jacobian expressed in the robot reference frame available
void setJointVelocity(const vpColVector &qdot)