51 #pragma warning(disable: 4267)
54 #define _CRT_SECURE_NO_WARNINGS
55 #define _USE_MATH_DEFINES
62 #include "sick_scan/rosconsole_simu.hpp"
100 numberOfLayers = _layerNum;
111 return (numberOfLayers);
123 numberOfShots = _shots;
134 return (numberOfShots);
145 this->numberOfMaximumEchos = _maxEchos;
157 return (numberOfMaximumEchos);
168 currentParamSet = _ptr;
179 angleDegressResolution = _res;
189 return (angleDegressResolution);
199 expectedFrequency = _freq;
210 return (expectedFrequency);
221 this->elevationDegreeResolution = _elevRes;
232 return (this->elevationDegreeResolution);
242 this->useBinaryProtocol = _useBinary;
252 deviceIsRadar = _deviceIsRadar;
262 return (deviceIsRadar);
272 scanMirroredAndShifted = _scannMirroredAndShifted;
282 return (scanMirroredAndShifted);
292 return (this->useBinaryProtocol);
302 this->IntensityResolutionIs16Bit = _IntensityResolutionIs16Bit;
312 return (IntensityResolutionIs16Bit);
322 this->useSafetyPasWD = _useSafetyPasWD;
332 return (useSafetyPasWD);
337 return this->useEvalFields;
342 this->useEvalFields = _useEvalFields;
347 return this->maxEvalFields;
352 this->maxEvalFields = _maxEvalFields;
357 this->scanAngleShift = _scanAngleShift;
362 return this->scanAngleShift;
371 : numberOfLayers(0), numberOfShots(0), numberOfMaximumEchos(0), elevationDegreeResolution(0), angleDegressResolution(0), expectedFrequency(0),
372 useBinaryProtocol(false), IntensityResolutionIs16Bit(false), deviceIsRadar(false), useSafetyPasWD(false), encoderMode(0),
373 CartographerCompatibility(false), scanMirroredAndShifted(false), useEvalFields(
EVAL_FIELD_UNSUPPORTED), maxEvalFields(0)
407 override_range_min_((float) 0.05),
408 override_range_max_((float) 100.0),
409 override_time_increment_((float) -1.0)
475 basicParams[i].setAngularDegreeResolution(1.00000);
653 basicParams[i].setAngularDegreeResolution(0.33333333333);
668 if (scannerIdx == -1)
671 throw new std::string(
"scanner type " +
scannerType +
" not supported.");
729 int &rssiNum, std::vector<float> &distVal, std::vector<float> &rssiVal,
740 unsigned short int number_of_data = 0;
741 if (strstr(fields[baseOffset],
"DIST") != fields[baseOffset])
743 ROS_WARN(
"Field 20 of received data does not start with DIST (is: %s). Unexpected data, ignoring scan",
751 bool distFnd =
false;
752 bool rssiFnd =
false;
753 if (strlen(fields[offset]) == 5)
755 if (strstr(fields[offset],
"DIST") == fields[offset])
760 if (1 == sscanf(fields[offset],
"DIST%d", &distId))
762 distMask |= (1 << (distId - 1));
765 if (strstr(fields[offset],
"RSSI") == fields[offset])
771 if (rssiFnd || distFnd)
774 if (offset >= (
int) fields.size())
776 ROS_WARN(
"Missing RSSI or DIST data");
780 sscanf(fields[offset],
"%hx", &number_of_data);
781 if (number_of_data != expected_number_of_data)
783 ROS_WARN(
"number of dist or rssi values mismatching.");
788 for (
int i = 0; i < number_of_data; i++)
792 unsigned short iRange;
794 sscanf(fields[offset + i],
"%hx", &iRange);
795 range = iRange / 1000.0;
796 distVal.push_back(range);
800 unsigned short iRSSI;
801 sscanf(fields[offset + i],
"%hx", &iRSSI);
802 rssiVal.push_back((
float) iRSSI);
805 offset += number_of_data;
811 }
while (offset < (
int) fields.size());
824 float expected_time_increment =
825 fabs(this->
getCurrentParamPtr()->getNumberOfLayers() * scan_time * angle_increment / (2.0 * M_PI));
826 if (fabs(expected_time_increment - time_increment) > 0.00001)
829 "The time_increment, scan_time and angle_increment values reported by the scanner are inconsistent! "
830 "Expected time_increment: %.9f, reported time_increment: %.9f. "
831 "Perhaps you should set the parameter time_increment to the expected value. This message will print every 60 seconds.",
832 expected_time_increment, time_increment);
848 sensor_msgs::LaserScan &msg,
int &numEchos,
int &echoMask)
852 bool dumpData =
false;
853 int verboseLevel = 0;
856 int HEADER_FIELDS = 32;
862 std::vector<char *> fields;
863 fields.reserve(datagram_length / 2);
866 std::vector<char> datagram_copy_vec;
867 datagram_copy_vec.resize(datagram_length + 1);
868 char *datagram_copy = &(datagram_copy_vec[0]);
870 if (verboseLevel > 0)
872 ROS_WARN(
"Verbose LEVEL activated. Only for DEBUG.");
875 if (verboseLevel > 0)
878 char szDumpFileName[511] = {0};
879 char szDir[255] = {0};
881 strcpy(szDir,
"C:\\temp\\");
883 strcpy(szDir,
"/tmp/");
885 sprintf(szDumpFileName,
"%stmp%06d.bin", szDir, cnt);
890 ftmp = fopen(szDumpFileName,
"wb");
893 fwrite(datagram, datagram_length, 1, ftmp);
900 strncpy(datagram_copy, datagram, datagram_length);
901 datagram_copy[datagram_length] = 0;
905 cur_field = strtok(datagram,
" ");
907 while (cur_field != NULL)
909 fields.push_back(cur_field);
911 cur_field = strtok(NULL,
" ");
916 count = fields.size();
919 if (verboseLevel > 0)
922 char szDumpFileName[511] = {0};
923 char szDir[255] = {0};
925 strcpy(szDir,
"C:\\temp\\");
927 strcpy(szDir,
"/tmp/");
929 sprintf(szDumpFileName,
"%stmp%06d.txt", szDir, cnt);
930 ROS_WARN(
"Verbose LEVEL activated. Only for DEBUG.");
932 ftmp = fopen(szDumpFileName,
"w");
936 for (i = 0; i < count; i++)
938 fprintf(ftmp,
"%3d: %s\n", i, fields[i]);
948 if (count < HEADER_FIELDS)
951 "received less fields than minimum fields (actual: %d, minimum: %d), ignoring scan", (
int) count,
954 "are you using the correct node? (124 --> sick_tim310_1130000m01, > 33 --> sick_tim551_2050001, 580 --> sick_tim310s01, 592 --> sick_tim310)");
959 if (
basicParams[scannerIdx].getNumberOfLayers() == 1)
961 if (strcmp(fields[15],
"0"))
963 ROS_WARN(
"Field 15 of received data is not equal to 0 (%s). Unexpected data, ignoring scan", fields[15]);
974 if (strcmp(fields[20],
"DIST1"))
976 ROS_WARN(
"Field 20 of received data is not equal to DIST1i (%s). Unexpected data, ignoring scan", fields[20]);
982 unsigned short int number_of_data = 0;
983 sscanf(fields[25],
"%hx", &number_of_data);
985 int numOfExpectedShots =
basicParams[scannerIdx].getNumberOfShots();
986 if (number_of_data < 1 || number_of_data > numOfExpectedShots)
988 ROS_WARN(
"Data length is outside acceptable range 1-%d (%d). Ignoring scan", numOfExpectedShots, number_of_data);
991 if (count < HEADER_FIELDS + number_of_data)
993 ROS_WARN(
"Less fields than expected for %d data points (%zu). Ignoring scan", number_of_data, count);
996 ROS_DEBUG(
"Number of data: %d", number_of_data);
999 size_t rssi_idx = 26 + number_of_data;
1001 if (strcmp(fields[rssi_idx],
"RSSI1") == 0)
1005 unsigned short int number_of_rssi_data = 0;
1008 sscanf(fields[rssi_idx + 5],
"%hx", &number_of_rssi_data);
1011 if (number_of_rssi_data != number_of_data)
1013 ROS_WARN(
"Number of RSSI data is lower than number of range data (%d vs %d", number_of_data,
1014 number_of_rssi_data);
1020 if (count < HEADER_FIELDS + number_of_data + number_of_rssi_data + 6)
1022 ROS_WARN(
"Less fields than expected for %d data points (%zu). Ignoring scan", number_of_data, count);
1026 if (strcmp(fields[rssi_idx],
"RSSI1"))
1028 ROS_WARN(
"Field %zu of received data is not equal to RSSI1 (%s). Unexpected data, ignoring scan", rssi_idx + 1,
1029 fields[rssi_idx + 1]);
1033 if (
basicParams[scannerIdx].getNumberOfLayers() > 1)
1036 sscanf(fields[15],
"%hx", &layer);
1037 msg.header.seq = layer;
1040 msg.header.frame_id = config.frame_id;
1078 unsigned short scanning_freq = -1;
1079 sscanf(fields[16],
"%hx", &scanning_freq);
1080 msg.scan_time = 1.0 / (scanning_freq / 100.0);
1084 unsigned short measurement_freq = -1;
1085 sscanf(fields[17],
"%hx", &measurement_freq);
1086 msg.time_increment = 1.0 / (measurement_freq * 100.0);
1108 int starting_angle = -1;
1109 sscanf(fields[23],
"%x", &starting_angle);
1114 unsigned short angular_step_width = -1;
1115 sscanf(fields[24],
"%hx", &angular_step_width);
1116 msg.angle_increment = (angular_step_width / 10000.0) / 180.0 * M_PI;
1117 msg.angle_max =
msg.angle_min + (number_of_data - 1) *
msg.angle_increment;
1129 if (config.intensity)
1137 ROS_WARN_ONCE(
"Intensity parameter is enabled, but the scanner is not configured to send RSSI values! "
1138 "Please read the section 'Enabling intensity (RSSI) output' here: http://wiki.ros.org/sick_tim.");
1153 if (
basicParams[scannerIdx].getNumberOfLayers() > 1)
1155 char szDummy[255] = {0};
1156 sprintf(szDummy,
"%s_%+04d", config.frame_id.c_str(),
msg.header.seq);
1157 msg.header.frame_id = szDummy;
1161 #ifndef _MSC_VER // TIMING in Simulation not correct