48 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX
53 #include <sys/types.h>
59 #include <visp3/robot/vpServolens.h>
60 #include <visp3/robot/vpRobotException.h>
61 #include <visp3/core/vpDebug.h>
62 #include <visp3/core/vpTime.h>
119 printf(
"\nOpen the Servolens serial port \"%s\"\n", port);
121 if ((this->remfd=::
open(port, O_RDWR|O_NONBLOCK)) < 0) {
124 "Cannot open Servolens serial port.");
128 if (tcgetattr(this->remfd, &info) < 0) {
132 "Error using TCGETS in ioctl");
142 info.c_iflag |= INLCR;
152 info.c_cflag |= CREAD;
153 info.c_cflag |= B9600 | CS7 | PARENB;
159 if (tcsetattr(this->remfd, TCSANOW, &info) < 0) {
163 "Error using TCGETS in ioctl");
167 tcflush(this->remfd, TCIFLUSH);
176 vpERROR_TRACE (
"Cannot dial with the servolens. Check if the serial link is connected.");
178 "Cannot dial with the servolens. Check if the serial link is connected.");
193 printf(
"\nClose the serial connexion with Servolens\n");
211 "Cannot dial with Servolens.");
216 sprintf(commande,
"SE1");
217 this->write(commande);
220 sprintf(commande,
"SR0");
221 this->write(commande);
228 sprintf(commande,
"SE0");
229 this->write(commande);
232 sprintf(commande,
"VW0");
233 this->write(commande);
244 vpServolens::init()
const
249 "Cannot dial with Servolens.");
255 sprintf(commande,
"SE0");
256 this->write(commande);
259 sprintf(commande,
"VW0");
260 this->write(commande);
279 vpServolens::enableCmdComplete(vpServoType servo,
bool active)
const
284 "Cannot dial with Servolens.");
294 sprintf(commande,
"ZF1");
296 sprintf(commande,
"ZF0");
300 sprintf(commande,
"FF1");
302 sprintf(commande,
"FF0");
306 sprintf(commande,
"DF1");
308 sprintf(commande,
"DF0");
313 this->write(commande);
332 "Cannot dial with Servolens.");
338 sprintf(commande,
"SE1");
340 sprintf(commande,
"SE0");
342 this->write(commande);
359 "Cannot dial with Servolens.");
366 sprintf(commande,
"VW1");
367 this->write(commande);
371 sprintf(commande,
"SX0842");
372 this->write(commande);
374 sprintf(commande,
"VW0");
375 this->write(commande);
378 sprintf(commande,
"SX1084");
379 this->write(commande);
381 sprintf(commande,
"VW0");
382 this->write(commande);
400 "Cannot dial with Servolens.");
405 sprintf(commande,
"DA1");
407 sprintf(commande,
"DA0");
409 this->write(commande);
428 "Cannot dial with Servolens.");
441 this->enableCommandComplete();
474 sprintf(commande,
"ZD%d", position);
477 sprintf(commande,
"FD%d", position);
480 sprintf(commande,
"DD%d", position);
485 printf(
"\ncommande: %s", commande);
488 this->write(commande);
512 "Cannot dial with Servolens.");
515 char posit[10], *pt_posit;
517 short fin_lect_posit;
519 short lecture_posit_en_cours;
530 sprintf(commande,
"ZD?");
533 sprintf(commande,
"FD?");
536 sprintf(commande,
"DD?");
544 this->write(commande);
550 lecture_posit_en_cours = 0;
552 if (this->read(&c, 1) ==
true) {
563 if( c ==
'Z') posit_car = 1;
566 if( c ==
'F') posit_car = 1;
569 if( c ==
'D') posit_car = 1;
577 if( c ==
'D') posit_car = 2;
584 if (c >=
'0' && c <=
'9')
587 lecture_posit_en_cours = 1;
589 else if (lecture_posit_en_cours)
604 while ( !fin_lect_posit );
609 this->clean(posit, posit);
612 position = (
unsigned int)atoi(posit);
650 "Cannot dial with Servolens.");
653 double pix_size = 7.4e-6;
654 double px=1000, py=1000, u0=320, v0=240;
657 double subsample_factor = 1.;
662 if (width > 300 && width < 340 && height > 220 && height < 260)
663 subsample_factor = 2;
664 else if (width > 140 && width < 1800 && height > 100 && height < 140)
665 subsample_factor = 4;
674 double focale = zoom * 1.0e-5;
675 px = focale / (double)(subsample_factor * pix_size);
676 py = focale / (double)(subsample_factor * pix_size);
693 vpServolens::wait()
const
698 "Cannot dial with Servolens.");
702 r = ::write(this->remfd,
"\r\n", strlen(
"\r\n"));
703 if (r != (ssize_t)(strlen(
"\r\n"))) {
705 "Cannot write on Servolens.");
709 r = ::read(this->remfd, &c, 1);
728 vpServolens::wait(vpServoType servo)
const
733 "Cannot dial with Servolens.");
742 sprintf(fin_mvt,
"ZF");
745 sprintf(fin_mvt,
"FF");
749 sprintf(fin_mvt,
"DF");
757 if (::read(this->remfd,&c,1) != 1) {
759 "Cannot read on Servolens.");
764 if (c == fin_mvt[0]) {
766 if (::read(this->remfd,&c,1) != 1) {
768 "Cannot read on Servolens.");
772 if (c == fin_mvt[1]) {
794 vpServolens::read(
char *c,
long timeout_s)
const
799 "Cannot dial with Servolens.");
804 struct timeval timeout = {timeout_s, 0};
807 FD_SET(static_cast<unsigned int>(this->remfd), &readfds);
809 if (select(FD_SETSIZE, &readfds, (fd_set *)NULL,
810 (fd_set *)NULL, &timeout) > 0) {
811 n = ::read(this->remfd, c, 1);
831 vpServolens::write(
const char *s)
const
836 "Cannot dial with Servolens.");
839 r = ::write(this->remfd,
"\r", strlen(
"\r"));
840 r += ::write(this->remfd, s, strlen(s));
841 r += ::write(this->remfd,
"\r", strlen(
"\r"));
842 if (r != (ssize_t)(2*strlen(
"\r") + strlen(s))) {
844 "Cannot write on Servolens.");
870 vpServolens::clean(
const char *in,
char *out)
const
878 while( *(in) ==
'0' && i++ < nb_car ) {
888 while( i++ <= nb_car ) {
VISP_EXPORT int wait(double t0, double t)
Error that can be emited by the vpRobot class and its derivates.
unsigned int getWidth() const
void setController(vpControllerType controller) const
void initPersProjWithoutDistortion(const double px, const double py, const double u0, const double v0)
void enablePrompt(bool active) const
vpCameraParameters getCameraParameters(vpImage< unsigned char > &I) const
Generic class defining intrinsic camera parameters.
void open(const char *port="/dev/ttyS0")
void setAutoIris(bool enable) const
unsigned int getHeight() const
bool getPosition(vpServoType servo, unsigned int &position) const
void setPosition(vpServoType servo, unsigned int position) const