98 y = -range * std::cos(angle_rad);
99 x = range * std::sin(angle_rad);
119 points_y[1] = -rectWidthMeter;
120 points_x[2] = rectLengthMeter;
121 points_y[2] = -rectWidthMeter;
122 points_x[3] = rectLengthMeter;
125 float sin_angle = sinf(rotAngleRad);
126 float cos_angle = cosf(rotAngleRad);
127 for(
int n = 0; n < 4; n++)
129 float x = points_x[n], y = points_y[n];
130 points_x[n] = x * cos_angle - y * sin_angle;
131 points_y[n] = x * sin_angle + y * cos_angle;
134 float refPointX = 0, refPointY = 0;
136 for(
int n = 0; n < 4; n++)
138 points_x[n] += refPointX;
139 points_y[n] += refPointY;
161 float field1_points_x[4], field1_points_y[4], field2_points_x[4], field2_points_y[4];
162 rectangularFieldToCarthesian(distRefPointMeter, angleRefPointRad, rotAngleRad, rectWidthMeter, maxLengthMeter, field1_points_x, field1_points_y);
163 rectangularFieldToCarthesian(distRefPointMeter, angleRefPointRad, rotAngleRad, rectWidthMeter, rectLengthMeter, field2_points_x, field2_points_y);
164 for(
int n = 0; n < 4; n++)
166 points_x[n + 0] = field1_points_x[n];
167 points_y[n + 0] = field1_points_y[n];
168 points_x[n + 4] = field2_points_x[n];
169 points_y[n + 4] = field2_points_y[n];
188 this->monFields.resize(48);
190 this->active_mon_fieldset = 0;
200 ROS_ERROR(
"SickScanFieldMonSingleton::parseAsciiLIDinputstateMsg not implemented.");
213 if(datagram_length > 36)
216 for(
int offset = 35; offset >= 32; offset--)
218 fieldset = (fieldset << 1);
219 fieldset |= ((datagramm[offset] != 0) ? 1 : 0);
221 setActiveFieldset(fieldset);
237 ROS_ERROR(
"SickScanFieldMonSingleton::parseAsciiDatagram not implemented.");
245 int fieldNumberFromCMD=0;
246 std::string sDatagramm( datagram.begin()+8, datagram.end() );
247 sscanf(sDatagramm.c_str(),
"sRA field%d", &fieldNumberFromCMD);
248 float distScaleFactor;
249 float distScaleFactorOffset;
250 uint32_t angScaleFactor;
251 int32_t angScaleFactorOffset;
254 uint16_t segmentedFieldConfigured = 0;
255 uint16_t rectangularFieldConfigured = 0;
256 uint16_t dynamicFieldConfigured = 0;
257 uint32_t dataPtrOffset = 0;
259 unsigned char *dataPtr= &(datagram[0]);
260 memcpy(&distScaleFactor, dataPtr + 21, 4);
261 memcpy(&distScaleFactorOffset, dataPtr + 25, 4);
262 memcpy(&angScaleFactor, dataPtr + 29, 4);
263 memcpy(&angScaleFactorOffset, dataPtr + 33, 4);
264 memcpy(&fieldType, dataPtr + 37, 1);
265 memcpy(&fieldNumber, dataPtr + 38, 1);
266 memcpy(&segmentedFieldConfigured, dataPtr + 39, 2);
267 swap_endian((
unsigned char *) &distScaleFactor, 4);
268 swap_endian((
unsigned char *) &distScaleFactorOffset, 4);
270 swap_endian((
unsigned char *) &angScaleFactorOffset, 4);
273 swap_endian((
unsigned char *) &segmentedFieldConfigured, 2);
276 if(segmentedFieldConfigured==1)
278 uint16_t numOfFieldPoints;
280 uint16_t startDist,stopDist;
281 memcpy(&numOfFieldPoints, dataPtr + 41, 2);
282 swap_endian((
unsigned char *) &numOfFieldPoints, 2);
283 monFields[fieldNumberFromCMD].pushFieldPointCarthesian(0, 0);
284 for(uint16_t point=0;point<numOfFieldPoints;point++)
286 memcpy(&angIDX, dataPtr + 43+point*6, 2);
287 memcpy(&startDist, dataPtr + 45+point*6, 2);
288 memcpy(&stopDist, dataPtr + 47+point*6, 2);
292 float angRad=(angIDX*angScaleFactor/1e4+angScaleFactorOffset/1e4)*
deg2rad;
293 float distMeter=(stopDist*distScaleFactor+distScaleFactorOffset)/1000.0
f;
294 float point_x = 0, point_y = 0;
296 monFields[fieldNumberFromCMD].pushFieldPointCarthesian(point_x, point_y);
298 dataPtrOffset = 43 + numOfFieldPoints * 6;
300 memcpy(&rectangularFieldConfigured, dataPtr + dataPtrOffset, 2);
301 swap_endian((
unsigned char *) &rectangularFieldConfigured, 2);
303 if(rectangularFieldConfigured==1)
305 int32_t angleRefPoint;
306 uint16_t distRefPoint;
308 uint32_t rectWidth, rectLength;
309 memcpy(&angleRefPoint, dataPtr + dataPtrOffset + 0, 4);
310 memcpy(&distRefPoint, dataPtr + dataPtrOffset + 4, 2);
311 memcpy(&rotAngle, dataPtr + dataPtrOffset + 6, 4);
312 memcpy(&rectWidth, dataPtr + dataPtrOffset + 10, 4);
313 memcpy(&rectLength, dataPtr + dataPtrOffset + 14, 4);
320 float angleRefPointRad=(angleRefPoint/1e4+angScaleFactorOffset/1e4)*
deg2rad;
321 float distRefPointMeter=(distRefPoint*distScaleFactor+distScaleFactorOffset)/1000.0
f;
322 float rotAngleRad=(rotAngle/1e4)*
deg2rad;
323 float rectWidthMeter=(rectWidth)/1000.0
f;
324 float rectLengthMeter=(rectLength)/1000.0
f;
325 float points_x[4] = {0}, points_y[4] = {0};
327 for(
int n = 0; n < 4; n++)
328 monFields[fieldNumberFromCMD].pushFieldPointCarthesian(points_x[n], points_y[n]);
331 memcpy(&dynamicFieldConfigured, dataPtr + dataPtrOffset, 2);
332 swap_endian((
unsigned char *) &dynamicFieldConfigured, 2);
334 if(dynamicFieldConfigured==1)
336 int32_t angleRefPoint;
337 uint16_t distRefPoint;
339 uint32_t rectWidth, rectLength;
342 memcpy(&angleRefPoint, dataPtr + dataPtrOffset + 0, 4);
343 memcpy(&distRefPoint, dataPtr + dataPtrOffset + 4, 2);
344 memcpy(&rotAngle, dataPtr + dataPtrOffset + 6, 4);
345 memcpy(&rectWidth, dataPtr + dataPtrOffset + 10, 4);
346 memcpy(&rectLength, dataPtr + dataPtrOffset + 14, 4);
347 memcpy(&maxSpeed, dataPtr + dataPtrOffset + 18, 2);
348 memcpy(&maxLength, dataPtr + dataPtrOffset + 20, 4);
357 float angleRefPointRad=(angleRefPoint/1e4+angScaleFactorOffset/1e4)*
deg2rad;
358 float distRefPointMeter=(distRefPoint*distScaleFactor+distScaleFactorOffset)/1000.0
f;
359 float rotAngleRad=(rotAngle/1e4)*
deg2rad;
360 float rectWidthMeter=(rectWidth)/1000.0
f;
361 float rectLengthMeter=(rectLength)/1000.0
f;
362 float maxSpeedMeterPerSec=(maxSpeed)/1000.0
f;
363 float maxLengthMeter=(maxLength)/1000.0
f;
364 float points_x[8] = {0}, points_y[8] = {0};
366 for(
int n = 0; n < 8; n++)
367 monFields[fieldNumberFromCMD].pushFieldPointCarthesian(points_x[n], points_y[n]);
void swap_endian(unsigned char *ptr, int numBytes)
Universal swapping function.
static SickScanFieldMonSingleton * getInstance()
static void rectangularFieldToCarthesian(float distRefPointMeter, float angleRefPointRad, float rotAngleRad, float rectWidthMeter, float rectLengthMeter, float points_x[4], float points_y[4])
static void dynamicFieldPointToCarthesian(float distRefPointMeter, float angleRefPointRad, float rotAngleRad, float rectWidthMeter, float rectLengthMeter, float maxSpeedMeterPerSec, float maxLengthMeter, float points_x[8], float points_y[8])
static void segmentedFieldPointToCarthesian(float range, float angle_rad, float &x, float &y)
int parseAsciiDatagram(std::vector< unsigned char > datagramm)
Parsing Ascii datagram.
int parseAsciiLIDinputstateMsg(unsigned char *datagram, int datagram_length)
Parse binary LIDinputstate message and set active field set.
int parseBinaryLIDinputstateMsg(unsigned char *datagram, int datagram_length)
Parse binary LIDinputstate message and set active field set.
SickScanFieldMonSingleton()
int parseBinaryDatagram(std::vector< unsigned char > datagramm)
static SickScanFieldMonSingleton * instance