52 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
57 #include <sys/types.h>
63 #include <visp/vpServolens.h>
64 #include <visp/vpRobotException.h>
65 #include <visp/vpDebug.h>
66 #include <visp/vpTime.h>
74 vpServolens::vpServolens() : remfd(0), isinit(false)
86 vpServolens::vpServolens(
const char *port) : remfd(0), isinit(false)
98 vpServolens::~vpServolens()
118 vpServolens::open(
const char *port)
123 printf(
"\nOpen the Servolens serial port \"%s\"\n", port);
125 if ((this->remfd=::open(port, O_RDWR|O_NONBLOCK)) < 0) {
128 "Cannot open Servolens serial port.");
132 if (tcgetattr(this->remfd, &info) < 0) {
133 ::close(this->remfd);
136 "Error using TCGETS in ioctl");
146 info.c_iflag |= INLCR;
156 info.c_cflag |= CREAD;
157 info.c_cflag |= B9600 | CS7 | PARENB;
163 if (tcsetattr(this->remfd, TCSANOW, &info) < 0) {
164 ::close(this->remfd);
167 "Error using TCGETS in ioctl");
171 tcflush(this->remfd, TCIFLUSH);
179 if (this->getPosition(vpServolens::ZOOM, izoom) ==
false) {
180 vpERROR_TRACE (
"Cannot dial with the servolens. Check if the serial link is connected.");
182 "Cannot dial with the servolens. Check if the serial link is connected.");
197 printf(
"\nClose the serial connexion with Servolens\n");
198 ::close(this->remfd);
210 vpServolens::reset()
const
215 "Cannot dial with Servolens.");
220 sprintf(commande,
"SE1");
221 this->write(commande);
224 sprintf(commande,
"SR0");
225 this->write(commande);
232 sprintf(commande,
"SE0");
233 this->write(commande);
236 sprintf(commande,
"VW0");
237 this->write(commande);
248 vpServolens::init()
const
253 "Cannot dial with Servolens.");
259 sprintf(commande,
"SE0");
260 this->write(commande);
263 sprintf(commande,
"VW0");
264 this->write(commande);
283 vpServolens::enableCmdComplete(vpServoType servo,
bool active)
const
288 "Cannot dial with Servolens.");
298 sprintf(commande,
"ZF1");
300 sprintf(commande,
"ZF0");
304 sprintf(commande,
"FF1");
306 sprintf(commande,
"FF0");
310 sprintf(commande,
"DF1");
312 sprintf(commande,
"DF0");
317 this->write(commande);
331 vpServolens::enablePrompt(
bool active)
const
336 "Cannot dial with Servolens.");
342 sprintf(commande,
"SE1");
344 sprintf(commande,
"SE0");
346 this->write(commande);
358 vpServolens::setController(vpControllerType controller)
const
363 "Cannot dial with Servolens.");
370 sprintf(commande,
"VW1");
371 this->write(commande);
375 sprintf(commande,
"SX0842");
376 this->write(commande);
378 sprintf(commande,
"VW0");
379 this->write(commande);
382 sprintf(commande,
"SX1084");
383 this->write(commande);
385 sprintf(commande,
"VW0");
386 this->write(commande);
399 vpServolens::setAutoIris(
bool enable)
const
404 "Cannot dial with Servolens.");
409 sprintf(commande,
"DA1");
411 sprintf(commande,
"DA0");
413 this->write(commande);
427 vpServolens::setPosition(vpServoType servo,
unsigned int position)
const
432 "Cannot dial with Servolens.");
445 this->enableCommandComplete();
458 if (position < ZOOM_MIN) position = ZOOM_MIN;
464 if (position > FOCUS_MAX) position = FOCUS_MAX;
470 if (position > IRIS_MAX) position = IRIS_MAX;
478 sprintf(commande,
"ZD%d", position);
481 sprintf(commande,
"FD%d", position);
484 sprintf(commande,
"DD%d", position);
489 printf(
"\ncommande: %s", commande);
492 this->write(commande);
511 vpServolens::getPosition(vpServoType servo,
unsigned int &position)
const
516 "Cannot dial with Servolens.");
519 char posit[10], *pt_posit;
521 short fin_lect_posit;
523 short lecture_posit_en_cours;
534 sprintf(commande,
"ZD?");
537 sprintf(commande,
"FD?");
540 sprintf(commande,
"DD?");
548 this->write(commande);
554 lecture_posit_en_cours = 0;
556 if (this->read(&c, 1) ==
true) {
567 if( c ==
'Z') posit_car = 1;
570 if( c ==
'F') posit_car = 1;
573 if( c ==
'D') posit_car = 1;
581 if( c ==
'D') posit_car = 2;
588 if (c >=
'0' && c <=
'9')
591 lecture_posit_en_cours = 1;
593 else if (lecture_posit_en_cours)
608 while ( !fin_lect_posit );
613 this->clean(posit, posit);
616 position = (
unsigned int)atoi(posit);
654 "Cannot dial with Servolens.");
657 double pix_size = 7.4e-6;
658 double px=1000, py=1000, u0=320, v0=240;
661 double subsample_factor = 1.;
666 if (width > 300 && width < 340 && height > 220 && height < 260)
667 subsample_factor = 2;
668 else if (width > 140 && width < 1800 && height > 100 && height < 140)
669 subsample_factor = 4;
672 getPosition(vpServolens::ZOOM, zoom);
678 double focale = zoom * 1.0e-5;
679 px = focale / (double)(subsample_factor * pix_size);
680 py = focale / (double)(subsample_factor * pix_size);
697 vpServolens::wait()
const
702 "Cannot dial with Servolens.");
706 r = ::write(this->remfd,
"\r\n", strlen(
"\r\n"));
707 if (r != (ssize_t)(strlen(
"\r\n"))) {
709 "Cannot write on Servolens.");
713 r = ::read(this->remfd, &c, 1);
732 vpServolens::wait(vpServoType servo)
const
737 "Cannot dial with Servolens.");
746 sprintf(fin_mvt,
"ZF");
749 sprintf(fin_mvt,
"FF");
753 sprintf(fin_mvt,
"DF");
761 if (::read(this->remfd,&c,1) != 1) {
763 "Cannot read on Servolens.");
768 if (c == fin_mvt[0]) {
770 if (::read(this->remfd,&c,1) != 1) {
772 "Cannot read on Servolens.");
776 if (c == fin_mvt[1]) {
798 vpServolens::read(
char *c,
long timeout_s)
const
803 "Cannot dial with Servolens.");
808 struct timeval timeout = {timeout_s, 0};
811 FD_SET(static_cast<unsigned int>(this->remfd), &readfds);
813 if (select(FD_SETSIZE, &readfds, (fd_set *)NULL,
814 (fd_set *)NULL, &timeout) > 0) {
815 n = ::read(this->remfd, c, 1);
835 vpServolens::write(
const char *s)
const
840 "Cannot dial with Servolens.");
843 r = ::write(this->remfd,
"\r", strlen(
"\r"));
844 r += ::write(this->remfd, s, strlen(s));
845 r += ::write(this->remfd,
"\r", strlen(
"\r"));
846 if (r != (ssize_t)(2*strlen(
"\r") + strlen(s))) {
848 "Cannot write on Servolens.");
874 vpServolens::clean(
const char *in,
char *out)
const
882 while( *(in) ==
'0' && i++ < nb_car ) {
892 while( i++ <= nb_car ) {
Error that can be emited by the vpRobot class and its derivates.
unsigned int getWidth() const
static int wait(double t0, double t)
void initPersProjWithoutDistortion(const double px, const double py, const double u0, const double v0)
Generic class defining intrinsic camera parameters.
unsigned int getHeight() const