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>
109 printf(
"\nOpen the Servolens serial port \"%s\"\n", port);
111 if ((this->remfd = ::
open(port, O_RDWR | O_NONBLOCK)) < 0) {
117 if (tcgetattr(this->remfd, &info) < 0) {
130 info.c_iflag |= INLCR;
140 info.c_cflag |= CREAD;
141 info.c_cflag |= B9600 | CS7 | PARENB;
147 if (tcsetattr(this->remfd, TCSANOW, &info) < 0) {
154 tcflush(this->remfd, TCIFLUSH);
164 vpERROR_TRACE(
"Cannot dial with the servolens. Check if the serial "
165 "link is connected.");
167 "serial link is connected.");
179 printf(
"\nClose the serial connection with Servolens\n");
201 this->write(cmd.c_str());
205 this->write(cmd.c_str());
213 this->write(cmd.c_str());
217 this->write(cmd.c_str());
227 void vpServolens::init()
const
238 this->write(cmd.c_str());
242 this->write(cmd.c_str());
272 this->write(cmd.c_str());
291 switch (controller) {
295 this->write(cmd.c_str());
300 this->write(cmd.c_str());
303 this->write(cmd.c_str());
307 this->write(cmd.c_str());
310 this->write(cmd.c_str());
334 this->write(cmd.c_str());
353 std::stringstream command;
364 this->enableCommandComplete();
400 command <<
"ZD" << position;
403 command <<
"FD" << position;
406 command <<
"DD" << position;
411 printf(
"\ncommand: %s", command.str());
414 this->write(command.str().c_str());
439 char posit[10], *pt_posit;
441 short fin_lect_posit;
443 short lecture_posit_en_cours;
468 this->write(cmd.c_str());
474 lecture_posit_en_cours = 0;
476 if (this->read(&c, 1) ==
true) {
513 if (c >=
'0' && c <=
'9') {
515 lecture_posit_en_cours = 1;
517 else if (lecture_posit_en_cours) {
531 }
while (!fin_lect_posit);
536 this->clean(posit, posit);
539 position = (
unsigned int)atoi(posit);
581 double pix_size = 7.4e-6;
582 double px = 1000, py = 1000, u0 = 320, v0 = 240;
585 double subsample_factor = 1.;
589 if (width > 300 && width < 340 && height > 220 && height < 260)
590 subsample_factor = 2;
591 else if (width > 140 && width < 1800 && height > 100 && height < 140)
592 subsample_factor = 4;
602 double focale = zoom * 1.0e-5;
603 px = focale / (double)(subsample_factor * pix_size);
604 py = focale / (double)(subsample_factor * pix_size);
620 char vpServolens::wait()
const
628 r = ::write(this->remfd,
"\r\n", strlen(
"\r\n"));
629 if (r != (ssize_t)(strlen(
"\r\n"))) {
634 r = ::read(this->remfd, &c, 1);
653 void vpServolens::wait(vpServoType servo)
const
680 if (::read(this->remfd, &c, 1) != 1) {
686 if (c == fin_mvt.c_str()[0]) {
688 if (::read(this->remfd, &c, 1) != 1) {
693 if (c == fin_mvt.c_str()[1]) {
713 bool vpServolens::read(
char *c,
long timeout_s)
const
721 struct timeval timeout = { timeout_s, 0 };
724 FD_SET(
static_cast<unsigned int>(this->remfd), &readfds);
726 if (select(FD_SETSIZE, &readfds, (fd_set *)
nullptr, (fd_set *)
nullptr, &timeout) > 0) {
727 ssize_t n = ::read(this->remfd, c, 1);
746 void vpServolens::write(
const char *s)
const
753 r = ::write(this->remfd,
"\r", strlen(
"\r"));
754 r += ::write(this->remfd, s, strlen(s));
755 r += ::write(this->remfd,
"\r", strlen(
"\r"));
756 if (r != (ssize_t)(2 * strlen(
"\r") + strlen(s))) {
781 bool vpServolens::clean(
const char *in,
char *out)
const
789 while (*(in) ==
'0' && i++ < nb_car) {
798 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)