46 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
53 #include <sys/types.h>
57 #include <visp3/core/vpDebug.h>
58 #include <visp3/core/vpTime.h>
59 #include <visp3/robot/vpRobotException.h>
60 #include <visp3/robot/vpServolens.h>
108 printf(
"\nOpen the Servolens serial port \"%s\"\n", port);
110 if ((this->remfd = ::
open(port, O_RDWR | O_NONBLOCK)) < 0) {
116 if (tcgetattr(this->remfd, &info) < 0) {
129 info.c_iflag |= INLCR;
139 info.c_cflag |= CREAD;
140 info.c_cflag |= B9600 | CS7 | PARENB;
146 if (tcsetattr(this->remfd, TCSANOW, &info) < 0) {
153 tcflush(this->remfd, TCIFLUSH);
163 vpERROR_TRACE(
"Cannot dial with the servolens. Check if the serial "
164 "link is connected.");
166 "serial link is connected.");
178 printf(
"\nClose the serial connection with Servolens\n");
200 this->write(cmd.c_str());
204 this->write(cmd.c_str());
212 this->write(cmd.c_str());
216 this->write(cmd.c_str());
226 void vpServolens::init()
const
237 this->write(cmd.c_str());
241 this->write(cmd.c_str());
271 this->write(cmd.c_str());
290 switch (controller) {
294 this->write(cmd.c_str());
299 this->write(cmd.c_str());
302 this->write(cmd.c_str());
306 this->write(cmd.c_str());
309 this->write(cmd.c_str());
333 this->write(cmd.c_str());
352 std::stringstream command;
363 this->enableCommandComplete();
399 command <<
"ZD" << position;
402 command <<
"FD" << position;
405 command <<
"DD" << position;
410 printf(
"\ncommand: %s", command.str());
413 this->write(command.str().c_str());
438 char posit[10], *pt_posit;
440 short fin_lect_posit;
442 short lecture_posit_en_cours;
467 this->write(cmd.c_str());
473 lecture_posit_en_cours = 0;
475 if (this->read(&c, 1) ==
true) {
512 if (c >=
'0' && c <=
'9') {
514 lecture_posit_en_cours = 1;
515 }
else if (lecture_posit_en_cours) {
527 }
while (!fin_lect_posit);
532 this->clean(posit, posit);
535 position = (
unsigned int)atoi(posit);
573 double pix_size = 7.4e-6;
574 double px = 1000, py = 1000, u0 = 320, v0 = 240;
577 double subsample_factor = 1.;
581 if (width > 300 && width < 340 && height > 220 && height < 260)
582 subsample_factor = 2;
583 else if (width > 140 && width < 1800 && height > 100 && height < 140)
584 subsample_factor = 4;
594 double focale = zoom * 1.0e-5;
595 px = focale / (double)(subsample_factor * pix_size);
596 py = focale / (double)(subsample_factor * pix_size);
612 char vpServolens::wait()
const
620 r = ::write(this->remfd,
"\r\n", strlen(
"\r\n"));
621 if (r != (ssize_t)(strlen(
"\r\n"))) {
626 r = ::read(this->remfd, &c, 1);
645 void vpServolens::wait(vpServoType servo)
const
672 if (::read(this->remfd, &c, 1) != 1) {
678 if (c == fin_mvt.c_str()[0]) {
680 if (::read(this->remfd, &c, 1) != 1) {
685 if (c == fin_mvt.c_str()[1]) {
705 bool vpServolens::read(
char *c,
long timeout_s)
const
713 struct timeval timeout = {timeout_s, 0};
716 FD_SET(
static_cast<unsigned int>(this->remfd), &readfds);
718 if (select(FD_SETSIZE, &readfds, (fd_set *)NULL, (fd_set *)NULL, &timeout) > 0) {
719 ssize_t n = ::read(this->remfd, c, 1);
738 void vpServolens::write(
const char *s)
const
745 r = ::write(this->remfd,
"\r", strlen(
"\r"));
746 r += ::write(this->remfd, s, strlen(s));
747 r += ::write(this->remfd,
"\r", strlen(
"\r"));
748 if (r != (ssize_t)(2 * strlen(
"\r") + strlen(s))) {
773 bool vpServolens::clean(
const char *in,
char *out)
const
781 while (*(in) ==
'0' && i++ < nb_car) {
790 while (i++ <= nb_car) {
Generic class defining intrinsic camera parameters.
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
unsigned int getWidth() const
unsigned int getHeight() const
Error that can be emitted by the vpRobot class and its derivatives.
@ communicationError
Unable to communicate.
void setPosition(vpServoType servo, unsigned int position) const
vpCameraParameters getCameraParameters(vpImage< unsigned char > &I) const
void setController(vpControllerType controller) const
bool getPosition(vpServoType servo, unsigned int &position) const
void setAutoIris(bool enable) const
void open(const char *port="/dev/ttyS0")
void enablePrompt(bool active) const
VISP_EXPORT int wait(double t0, double t)