114 fprintf(stderr,
"ERROR: start baudrate = %d is not valid!\n",
124 fprintf(stderr,
"ERROR: set baudrate = %d is not valid!\n",
134 fprintf(stderr,
"ERROR: angle range = %d is not valid!\n",
148 fprintf(stderr,
"ERROR: ang-res=0.25 is not valid for this laser!\n");
156 fprintf(stderr,
"ERROR: ang-res=0.25 and ang-range=180 is not valid!\n");
162 fprintf(stderr,
"ERROR: type = PLS and ang-range=100 is not valid!\n");
172 fprintf(stderr,
"ERROR: remission values are only available using LMS laser!\n");
177 fprintf(stderr,
"ERROR: remission values are only available with 1.0 degree resolution!\n");
195 else if (type ==
"PLS")
198 if (fabs(fov-
M_PI) < 0.1 || fabs(fov-100.0/180.0*
M_PI) < 0.1)
199 qDebug(
"The parameter laser_laserX_fov in the ini file must\nbe specified in degrees not in radians!");
205 qDebug(
"The laser driver only provides 180 deg and 100 deg field of view!");
217 if (rem ==
"direct") {
221 else if (rem ==
"normalized") {
225 else if (rem ==
"no") {
228 else if (rem ==
"off") {
230 qDebug() <<
"Warning: please set the value of the parameter \nlaser_use_remission to \"no\" and do not use \"off\".\nAssuming \"no\" for now.\n\n";
232 else qDebug() <<
"ERROR: Parameter laser_use_remission for laser" << laser->
settings.
laser_num <<
"has invalid value:" << rem <<
"\nPossible values are: direct, normalized and off.\n";
241 QString str1, str2, str3, str4, str5;
242 double res1, res2, res3, res4, res5;
243 double fov1, fov2, fov3, fov4, fov5;
244 QString rem1, rem2, rem3, rem4, rem5;
248 switch (laserScanner)
410 switch (laserScanner)
559 static int first = 1;
560 static double last_update;
561 static double last_alive = 0;
564 static int laser1_stalled = 0, laser2_stalled = 0, laser3_stalled = 0, laser4_stalled = 0, laser5_stalled = 0;;
575 print_stats = (current_time - last_update > 1.0);
678 if(current_time - last_alive > 1.0)
680 last_alive = current_time;
723 double *laserrange = NULL;
731 laserrange[angle] /= 100;
732 return laserrange[angle];
737 laserrange[angle] /= 100;
738 return laserrange[angle];
743 laserrange[angle] /= 100;
744 return laserrange[angle];
749 laserrange[angle] /= 100;
750 return laserrange[angle];
755 laserrange[angle] /= 100;
756 return laserrange[angle];
782 return (theta * 180.0 /
M_PI);
787 return (theta *
M_PI / 180.0);
855 return(PARENB | PARODD);
900 #if !defined(CYGWIN) && !defined(__APPLE__)
921 tcgetattr(laser->
dev.
fd, &ctio);
931 ctio.c_cflag &= ~CRTSCTS;
933 ctio.c_cc[VTIME] = 0;
940 tcsetattr(laser->
dev.
fd, TCSANOW, &ctio);
952 sscanf( uts.release,
"%d.%d.%d", &ca, &cb, &cc );
953 if (ca*65536+cb*256+cc>=a*65536+b*256+c) {
966 tcgetattr(laser->
dev.
fd, &ctio);
969 #if !defined(CYGWIN) && !defined(__APPLE__)
971 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)
972 struct serial_struct serinfo;
975 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20)
978 cfsetispeed ( &ctio, (speed_t)
cBaudrate(38400) );
979 cfsetospeed ( &ctio, (speed_t)
cBaudrate(38400) );
980 serinfo.reserved_char[0] = 0;
981 if (ioctl(laser->
dev.
fd, TIOCGSERIAL, &serinfo) < 0)
983 fprintf(stderr,
" cannot get serial info\n");
984 close(laser->
dev.
fd);
987 serinfo.flags = ( serinfo.flags & ~ASYNC_SPD_MASK) | ASYNC_SPD_CUST;
988 serinfo.custom_divisor = serinfo.baud_base / brate;
989 if (ioctl(laser->
dev.
fd, TIOCSSERIAL, &serinfo) < 0)
991 fprintf(stderr,
" cannot set serial info\n");
992 close(laser->
dev.
fd);
998 cfsetispeed ( &ctio, (speed_t)
cBaudrate(brate) );
999 cfsetospeed ( &ctio, (speed_t)
cBaudrate(brate) );
1002 cfsetispeed( &ctio, (speed_t)
cBaudrate(brate) );
1003 cfsetospeed( &ctio, (speed_t)
cBaudrate(brate) );
1008 cfsetispeed( &ctio, (speed_t)
cBaudrate(brate) );
1009 cfsetospeed( &ctio, (speed_t)
cBaudrate(brate) );
1014 tcsetattr(laser->
dev.
fd, TCSANOW, &ctio);
1021 QByteArray ba = laser->
dev.
ttyport.toLatin1();
1024 if((laser->
dev.
fd = open(ba.data(), O_RDWR | O_NOCTTY | O_NONBLOCK)) < 0)
1034 if (ioctl(laser->
dev.
fd, TIOCEXCL) == -1)
1036 qDebug(
"Error setting TIOCEXCL on /dev/tty... - %s(%d).", strerror(errno), errno);
1039 qDebug(
"TIOCEXCL set succesfully.");
1044 if (fcntl(laser->
dev.
fd, F_SETFL, 0) == -1)
1046 qDebug(
"Error clearing O_NONBLOCK - %s(%d).", strerror(errno), errno);
1049 qDebug(
"O_NONBLOCK cleared successfully.");
1052 #ifdef DIRECS_LASER_LOW_LATENCY
1061 return(laser->
dev.
fd);
1067 unsigned char abData[2] = {0, 0}, uCrc16[2] = {0, 0};
1070 abData[0] = abData[1];
1071 abData[1] = *CommData++;
1072 if(uCrc16[0] & 0x80) {
1074 if(uCrc16[1] & 0x80)
1082 if(uCrc16[1] & 0x80)
1086 uCrc16[0] ^= abData[0];
1087 uCrc16[1] ^= abData[1];
1089 return (((
int)uCrc16[0]) * 256 + ((
int)uCrc16[1]));
1095 static int val, i, j, l, pos, chk1, chk2;
1098 #ifdef DIRECS_LASER_USE_SELECT
1100 struct timeval timer;
1101 timer.tv_sec=(long)(floor(timeout));
1102 timer.tv_usec=(long)((timeout-floor(timeout))*1000000);
1104 FD_SET(laser->
dev.
fd, &read_set);
1112 #ifdef DIRECS_LASER_USE_SELECT
1113 while(select(laser->
dev.
fd+1, &read_set, NULL, NULL, &timer))
1130 if(pos + val >= l + 6)
1133 read(laser->
dev.
fd, &(data[pos]), val);
1136 if(!chk1 && pos > 2)
1138 if(data[0] !=
STX || data[1] !=
LID)
1140 for(i = 1; i < pos - 1; i++)
1142 if(data[i] ==
STX && data[i+1] ==
LID)
1144 for(j = i; j < pos; j++)
1146 data[j - i] = data[j];
1161 if(!chk2 && pos > 4)
1163 l = data[3] * 256 + data[2];
1171 #ifndef DIRECS_LASER_USE_SELECT
1183 int pos = 0, i, check, length, loop, answer = 0, counter = 0;
1185 #ifdef DIRECS_LASER_USE_SELECT
1187 struct timeval timer;
1191 FD_SET(laser->
dev.
fd, &read_set);
1195 buffer[pos++] = 0x02;
1197 buffer[pos++] = 0x00;
1199 length = 1 + arg_length;
1200 buffer[pos++] = length & 0x00ff;
1201 buffer[pos++] = length / 256;
1203 buffer[pos++] = command;
1206 for(i=0; i < arg_length; i++)
1207 buffer[pos++] = argument[i];
1210 buffer[pos++] = check & 0x00ff;
1211 buffer[pos++] = check / 256;
1217 #ifdef DIRECS_LASER_USE_SELECT
1218 loop=select(laser->
dev.
fd+1, &read_set, NULL, NULL, &timer);
1226 read(laser->
dev.
fd, &buffer, val);
1245 else if(counter > 5) {
1249 #ifndef DIRECS_LASER_USE_SELECT
1264 static unsigned char args[2] = {0x05, 0xb4};
1272 unsigned char args[1];
1277 else if(brate == 38400)
1279 else if(brate == 19200)
1284 return (result ==
ACK);
1293 for(i = 0; i < 8; i++)
1294 args[i + 1] = (
unsigned char)laser->
dev.
passwd[i];
1307 unsigned char args[4];
1311 args[0] = 0x64; args[1] = 0x00;
1313 args[2] = 0x64; args[3] = 0x00;
1316 args[2] = 0x32; args[3] = 0x00;
1319 args[2] = 0x19; args[3] = 0x00;
1323 args[0] = 0xB4; args[1] = 0x00;
1325 args[2] = 0x64; args[3] = 0x00;
1327 args[2] = 0x32; args[3] = 0x00;
1331 return(result ==
ACK);
1340 return(result ==
ACK);
1350 return(result ==
ACK);
1360 unsigned char data[32];
1366 if((length != 42 && length != 40) || buf[4] != 0xF4 ||
1367 buf[length - 2] != (check & 0x00ff) || buf[length - 1] != (check / 256))
1369 for(i = 0; i < 32; i++)
1370 data[i] = buf[i + 5];
1381 fprintf(stderr,
"config-mode ... ");
1383 fprintf(stderr,
"ok ...");
1422 fprintf(stderr,
" set LMS config ... ");
1424 fprintf(stderr,
"ok ...");
1447 unsigned char lmsarg[1] = {0x24}, pls180arg[1] = {0x20};
1448 unsigned char pls360arg[1] = {0x24};
1460 }
while(result !=
ACK);
1466 unsigned char args[1] = {0x25};
1471 }
while(result !=
ACK);
1477 unsigned char lmsarg[7] = {0x2b, 1,0,0,0,0,0}, pls180arg[1] = {0x20};
1478 unsigned char pls360arg[1] = {0x24};
1487 fprintf(stderr,
"WARNING: No remission-mode support for non LMS lasers. Continuing normal mode.\n");
1499 }
while(result !=
ACK);
1505 unsigned char data[
BUFFER_SIZE], ReqLaser[2] = {5, 180};
1525 fprintf(stderr,
"Error : Could not send command to laser.\n");
1587 fprintf(stderr,
"check baudrate:\n");
1588 fprintf(stderr,
" %d ... ", brate);
1590 fprintf(stderr,
"yes\n");
1594 fprintf(stderr,
"no\n");
1647 laser->
range[i] = 0.0;
1648 laser->
glare[i] = 0;
1671 emit(
message(QString(
"Connecting Laser Scanner to %1...").arg(laser->
dev.
ttyport)));
1674 if(laser->
dev.
fd == -1)
1676 emit(
message(QString(
"Connecting Laser Scanner to %1...failed!").arg(laser->
dev.
ttyport)));
1712 fprintf(stderr,
"ERROR: communication does not work!\n");
1720 int errorCounter = 0;
1722 emit(
message(
"Setting Laser Scanner in config mode..."));
1723 qDebug(
"Setting Laser Scanner in config mode...");
1726 if (++errorCounter > 3)
1728 emit(
message(
"Error setting Laser Scanner in config mode!"));
1729 qDebug(
"Error setting Laser Scanner in config mode!");
1765 emit(
message(
"Setting Laser Scanner to continuous remission mode..."));
1770 emit(
message(
"Setting Laser Scanner to continuous mode..."));
1782 int i, check, packet_size = 0, theo_size = 0;
1784 for(i = 0; i < size; i++) {
1785 if(packet_size == 0 && *data == 0x02)
1787 else if(packet_size == 1 && *data == 0x80)
1789 else if(packet_size == 1)
1791 else if(packet_size == 2) {
1792 theo_size = data[0];
1795 else if(packet_size == 3) {
1796 theo_size += (data[0] << 8) + 6;
1797 if(size >= theo_size + (i - packet_size)) {
1798 check = data[theo_size - 3 - 2];
1799 check += data[theo_size - 3 - 1] << 8;
1806 *offset = i - packet_size;
1822 int i = 0, LoB = 0, HiB = 0, bit14, bit15, numMeasurements;
1823 float conversion = 1.0;
1825 if(packet[0] == 0xb0)
1828 numMeasurements = ((packet[2] << 8) + packet[1]) & 0x3FFF;
1831 bit14 = packet[2] & 0x40;
1832 bit15 = packet[2] & 0x80;
1846 for (i = 0; i < numMeasurements; i++)
1848 LoB = packet[i * 2 + 3];
1849 HiB = packet[i * 2 + 4];
1850 laser->
range[i] = ((HiB & 0x1f) * 256 + LoB) * conversion;
1851 laser->
glare[i] = (HiB & 0x20) / 32;
1852 laser->
wfv[i] = (HiB & 0x40) / 64;
1853 laser->
sfv[i] = (HiB & 0x80) / 128;
1861 int i = 0, LoB = 0, HiB = 0, bit14, bit15, numMeasurements;
1862 int parts, mstart, mend;
1864 float conversion = 1.0;
1866 if(packet[0] == 0xf5)
1869 parts = packet[1] & 0x7;
1873 mstart = ((packet[offs + 4] << 8) + packet[offs + 3]);
1874 mend = ((packet[offs + 6] << 8) + packet[offs + 5]);
1878 numMeasurements = ((packet[offs + 8] << 8) + packet[offs + 7]) & 0x3FFF;
1882 bit14 = packet[offs + 8] & 0x40;
1883 bit15 = packet[offs + 8] & 0x80;
1897 for (i = 0; i < numMeasurements; i++)
1899 LoB = packet[i * 4 + offs + 9];
1900 HiB = packet[i * 4 + offs + 10];
1901 laser->
range[i] = (HiB * 256 + LoB) * conversion;
1902 laser->
remission[i] = packet[i * 4 + offs + 12] * 256 + packet[i * 4 + offs + 11];
1918 int bytes_available, bytes_read;
1922 #ifdef DIRECS_LASER_USE_SELECT
1925 struct timeval timer;
1926 timer.tv_sec=(long)(floor(timeout));
1927 timer.tv_usec=(long)((timeout-floor(timeout))*1000000);
1929 FD_SET(laser->
dev.
fd, &read_set);
1930 select(laser->
dev.
fd+1, &read_set, NULL, NULL, &timer);
1993 emit(
message(QString(
"Stopping Laser Scanner continuous mode for Laser Scanner %1...OK.").arg(laser->
settings.
device_name)));
1994 close(laser->
dev.
fd);
2003 if (gettimeofday(&tv, NULL) < 0)
2005 qDebug(
"direcs_get_time encountered error in gettimeofday : %s", strerror(errno));
2008 t = tv.tv_sec + tv.tv_usec/1000000.0;