ibeo_lux_ros_msg_handler.cpp
Go to the documentation of this file.
1 /*
2  * Unpublished Copyright (c) 2009-2019 AutonomouStuff, LLC, All Rights Reserved.
3  *
4  * This file is part of the ibeo_lux ROS 1.0 driver which is released under the MIT license.
5  * See file LICENSE included with this software or go to https://opensource.org/licenses/MIT for full license details.
6  */
7 
9 
10 #include <string>
11 #include <vector>
12 
13 #define NTP_TO_UTC 2208988800
14 
15 using namespace AS::Drivers::Ibeo;
16 using namespace AS::Drivers::IbeoLux;
17 
18 void IbeoLuxRosMsgHandler::fillAndPublish(
19  const uint8_t& type_id,
20  const std::string& frame_id,
21  const ros::Publisher& pub,
22  IbeoTxMessage * parser_class)
23 {
24  if (type_id == ErrorWarning::DATA_TYPE)
25  {
26  ibeo_msgs::ErrorWarning new_msg;
27  fill2030(parser_class, &new_msg, frame_id);
28  pub.publish(new_msg);
29  }
30  else if (type_id == ScanData2202::DATA_TYPE)
31  {
32  ibeo_msgs::ScanData2202 new_msg;
33  fill2202(parser_class, &new_msg, frame_id);
34  pub.publish(new_msg);
35  }
36  else if (type_id == ScanData2204::DATA_TYPE)
37  {
38  ibeo_msgs::ScanData2204 new_msg;
39  fill2204(parser_class, &new_msg, frame_id);
40  pub.publish(new_msg);
41  }
42  else if (type_id == ScanData2205::DATA_TYPE)
43  {
44  ibeo_msgs::ScanData2205 new_msg;
45  fill2205(parser_class, &new_msg, frame_id);
46  pub.publish(new_msg);
47  }
48  else if (type_id == ObjectData2221::DATA_TYPE)
49  {
50  ibeo_msgs::ObjectData2221 new_msg;
51  fill2221(parser_class, &new_msg, frame_id);
52  pub.publish(new_msg);
53  }
54  else if (type_id == ObjectData2225::DATA_TYPE)
55  {
56  ibeo_msgs::ObjectData2225 new_msg;
57  fill2225(parser_class, &new_msg, frame_id);
58  pub.publish(new_msg);
59  }
60  else if (type_id == ObjectData2280::DATA_TYPE)
61  {
62  ibeo_msgs::ObjectData2280 new_msg;
63  fill2280(parser_class, &new_msg, frame_id);
64  pub.publish(new_msg);
65  }
66  else if (type_id == CameraImage::DATA_TYPE)
67  {
68  ibeo_msgs::CameraImage new_msg;
69  fill2403(parser_class, &new_msg, frame_id);
70  pub.publish(new_msg);
71  }
72  else if (type_id == HostVehicleState2805::DATA_TYPE)
73  {
74  ibeo_msgs::HostVehicleState2805 new_msg;
75  fill2805(parser_class, &new_msg, frame_id);
76  pub.publish(new_msg);
77  }
78  else if (type_id == HostVehicleState2806::DATA_TYPE)
79  {
80  ibeo_msgs::HostVehicleState2806 new_msg;
81  fill2806(parser_class, &new_msg, frame_id);
82  pub.publish(new_msg);
83  }
84  else if (type_id == HostVehicleState2807::DATA_TYPE)
85  {
86  ibeo_msgs::HostVehicleState2807 new_msg;
87  fill2807(parser_class, &new_msg, frame_id);
88  pub.publish(new_msg);
89  }
90 }
91 
92 void IbeoLuxRosMsgHandler::fillPointcloud(
93  const std::vector<Point3DL>& points,
94  pcl::PointCloud<pcl::PointXYZL> * new_msg)
95 {
96  for (Point3DL p : points)
97  {
98  pcl::PointXYZL pclp;
99  pclp.x = p.x;
100  pclp.y = p.y;
101  pclp.z = p.z;
102  pclp.label = p.label;
103  new_msg->push_back(pclp);
104  }
105 }
106 
107 void IbeoLuxRosMsgHandler::fillContourPoints(
108  const std::vector<Point3D>& points,
109  visualization_msgs::Marker * new_msg,
110  const std::string& frame_id)
111 {
112  new_msg->ns = frame_id;
113  new_msg->type = visualization_msgs::Marker::POINTS;
114  new_msg->color.r = 0.0;
115  new_msg->color.g = 1.0;
116  new_msg->color.b = 0.0;
117  new_msg->color.a = 1.0;
118  new_msg->scale.x = 0.05;
119  new_msg->scale.y = 0.05;
120  new_msg->scale.z = 0.05;
121 
122  for (Point3D p : points)
123  {
124  geometry_msgs::Point point;
125  point.x = p.x;
126  point.y = p.y;
127  point.z = p.z;
128  new_msg->points.push_back(point);
129  }
130 }
131 
132 void IbeoLuxRosMsgHandler::fillMarkerArray(
133  const std::vector<IbeoObject>& objects,
134  visualization_msgs::MarkerArray * new_msg,
135  const std::string& frame_id)
136 {
137  for (IbeoObject o : objects)
138  {
140  o.object_box_orientation); // Should already be in radians.
141  visualization_msgs::Marker object_marker = createWireframeMarker(
142  o.object_box_center.x,
143  o.object_box_center.y,
144  o.object_box_size.size_x,
145  o.object_box_size.size_y,
146  0.75);
147  object_marker.id = o.id;
148  object_marker.pose.orientation.x = quaternion.x();
149  object_marker.pose.orientation.y = quaternion.y();
150  object_marker.pose.orientation.z = quaternion.z();
151  object_marker.pose.orientation.w = quaternion.w();
152  object_marker.lifetime = ros::Duration(0.5);
153  object_marker.color.a = 0.5;
154  object_marker.color.r = object_marker.color.g = object_marker.color.b = 1.0;
155  object_marker.frame_locked = false;
156 
157  std::string label;
158  switch (o.classification)
159  {
160  case UNCLASSIFIED:
161  label = "Unclassified";
162  // Unclassified - white
163  break;
164  case UNKNOWN_SMALL:
165  label = "Unknown Small";
166  // Unknown small - blue
167  object_marker.color.r = object_marker.color.g = 0;
168  break;
169  case UNKNOWN_BIG:
170  label = "Unknown Big";
171  // Unknown big - dark blue
172  object_marker.color.r = object_marker.color.g = 0;
173  object_marker.color.b = 0.5;
174  break;
175  case PEDESTRIAN:
176  label = "Pedestrian";
177  // Pedestrian - red
178  object_marker.color.g = object_marker.color.b = 0;
179  break;
180  case BIKE:
181  label = "Bike";
182  // Bike - dark red
183  object_marker.color.g = object_marker.color.b = 0;
184  object_marker.color.r = 0.5;
185  break;
186  case CAR:
187  label = "Car";
188  // Car - green
189  object_marker.color.b = object_marker.color.r = 0;
190  break;
191  case TRUCK:
192  label = "Truck";
193  // Truck - dark green
194  object_marker.color.b = object_marker.color.r = 0;
195  object_marker.color.g = 0.5;
196  break;
197  default:
198  label = "Unknown";
199  object_marker.color.r = object_marker.color.b = object_marker.color.g = 0.0;
200  break;
201  }
202 
203  object_marker.ns = label;
204  object_marker.scale.x = 0.05;
205  object_marker.scale.y = 0.05;
206  object_marker.scale.z = 0.05;
207  object_marker.type = visualization_msgs::Marker::LINE_LIST;
208  object_marker.action = visualization_msgs::Marker::MODIFY;
209  object_marker.header.stamp = ros::Time::now();
210  object_marker.header.frame_id = frame_id;
211 
212  visualization_msgs::Marker object_label;
213  object_label.id = o.id + 1000;
214  object_label.ns = label;
215  object_label.type = visualization_msgs::Marker::TEXT_VIEW_FACING;
216  object_label.action = visualization_msgs::Marker::MODIFY;
217  object_label.pose.position.x = o.object_box_center.x;
218  object_label.pose.position.y = o.object_box_center.y;
219  object_label.pose.position.z = 0.5;
220  object_label.text = label;
221  object_label.scale.x = 0.1;
222  object_label.scale.y = 0.1;
223  object_label.scale.z = 0.5;
224  object_label.lifetime = object_marker.lifetime;
225  object_label.color.r = object_label.color.g = object_label.color.b = 1;
226  object_label.color.a = 0.5;
227  object_label.header.stamp = ros::Time::now();
228  object_label.header.frame_id = frame_id;
229 
230  new_msg->markers.push_back(object_marker);
231  new_msg->markers.push_back(object_label);
232  }
233 }
234 
235 ros::Time IbeoLuxRosMsgHandler::ntp_to_ros_time(const NTPTime& time)
236 {
237  return ros::Time(((time >> 32) - NTP_TO_UTC), (time & 0x0000FFFF));
238 }
239 
240 void IbeoLuxRosMsgHandler::fillIbeoHeader(
241  const IbeoDataHeader& class_header,
242  ibeo_msgs::IbeoDataHeader * msg_header)
243 {
244  msg_header->previous_message_size = class_header.previous_message_size;
245  msg_header->message_size = class_header.message_size;
246  msg_header->device_id = class_header.device_id;
247  msg_header->data_type_id = class_header.data_type_id;
248  msg_header->stamp = ntp_to_ros_time(class_header.time);
249 }
250 
251 void IbeoLuxRosMsgHandler::fill2030(
252  IbeoTxMessage * parser_class,
253  ibeo_msgs::ErrorWarning * new_msg,
254  const std::string& frame_id)
255 {
256  auto dc_parser = dynamic_cast<ErrorWarning*>(parser_class);
257 
258  fillIbeoHeader(dc_parser->ibeo_header, &(new_msg->ibeo_header));
259 
260  new_msg->err_internal_error = dc_parser->err_internal_error;
261  new_msg->err_motor_1_fault = dc_parser->err_motor_1_fault;
262  new_msg->err_buffer_error_xmt_incomplete = dc_parser->err_buffer_error_xmt_incomplete;
263  new_msg->err_buffer_error_overflow = dc_parser->err_buffer_error_overflow;
264  new_msg->err_apd_over_temperature = dc_parser->err_apd_over_temperature;
265  new_msg->err_apd_under_temperature = dc_parser->err_apd_under_temperature;
266  new_msg->err_apd_temperature_sensor_defect = dc_parser->err_apd_temperature_sensor_defect;
267  new_msg->err_motor_2_fault = dc_parser->err_motor_2_fault;
268  new_msg->err_motor_3_fault = dc_parser->err_motor_3_fault;
269  new_msg->err_motor_4_fault = dc_parser->err_motor_4_fault;
270  new_msg->err_motor_5_fault = dc_parser->err_motor_5_fault;
271  new_msg->err_int_no_scan_data = dc_parser->err_int_no_scan_data;
272  new_msg->err_int_communication_error = dc_parser->err_int_communication_error;
273  new_msg->err_int_incorrect_scan_data = dc_parser->err_int_incorrect_scan_data;
274  new_msg->err_config_fpga_not_configurable = dc_parser->err_config_fpga_not_configurable;
275  new_msg->err_config_incorrect_config_data = dc_parser->err_config_incorrect_config_data;
276  new_msg->err_config_contains_incorrect_params = dc_parser->err_config_contains_incorrect_params;
277  new_msg->err_timeout_data_processing = dc_parser->err_timeout_data_processing;
278  new_msg->err_timeout_env_model_computation_reset = dc_parser->err_timeout_env_model_computation_reset;
279  new_msg->wrn_int_communication_error = dc_parser->wrn_int_communication_error;
280  new_msg->wrn_low_temperature = dc_parser->wrn_low_temperature;
281  new_msg->wrn_high_temperature = dc_parser->wrn_high_temperature;
282  new_msg->wrn_int_motor_1 = dc_parser->wrn_int_motor_1;
283  new_msg->wrn_sync_error = dc_parser->wrn_sync_error;
284  new_msg->wrn_laser_1_start_pulse_missing = dc_parser->wrn_laser_1_start_pulse_missing;
285  new_msg->wrn_laser_2_start_pulse_missing = dc_parser->wrn_laser_2_start_pulse_missing;
286  new_msg->wrn_can_interface_blocked = dc_parser->wrn_can_interface_blocked;
287  new_msg->wrn_eth_interface_blocked = dc_parser->wrn_eth_interface_blocked;
288  new_msg->wrn_incorrect_can_data_rcvd = dc_parser->wrn_incorrect_can_data_rcvd;
289  new_msg->wrn_int_incorrect_scan_data = dc_parser->wrn_int_incorrect_scan_data;
290  new_msg->wrn_eth_unkwn_incomplete_data = dc_parser->wrn_eth_unkwn_incomplete_data;
291  new_msg->wrn_incorrect_or_forbidden_cmd_rcvd = dc_parser->wrn_incorrect_or_forbidden_cmd_rcvd;
292  new_msg->wrn_memory_access_failure = dc_parser->wrn_memory_access_failure;
293  new_msg->wrn_int_overflow = dc_parser->wrn_int_overflow;
294  new_msg->wrn_ego_motion_data_missing = dc_parser->wrn_ego_motion_data_missing;
295  new_msg->wrn_incorrect_mounting_params = dc_parser->wrn_incorrect_mounting_params;
296  new_msg->wrn_no_obj_comp_due_to_scan_freq = dc_parser->wrn_no_obj_comp_due_to_scan_freq;
297 
298  new_msg->header.frame_id = frame_id;
299  new_msg->header.stamp = ros::Time::now();
300 }
301 
302 void IbeoLuxRosMsgHandler::fill2202(
303  IbeoTxMessage * parser_class,
304  ibeo_msgs::ScanData2202 * new_msg,
305  const std::string& frame_id)
306 {
307  auto dc_parser = dynamic_cast<ScanData2202*>(parser_class);
308 
309  fillIbeoHeader(dc_parser->ibeo_header, &(new_msg->ibeo_header));
310 
311  new_msg->scan_number = dc_parser->scan_number;
312  new_msg->scanner_status = dc_parser->scanner_status;
313  new_msg->sync_phase_offset = dc_parser->sync_phase_offset;
314  new_msg->scan_start_time = ntp_to_ros_time(dc_parser->scan_start_time);
315  new_msg->scan_end_time = ntp_to_ros_time(dc_parser->scan_end_time);
316  new_msg->angle_ticks_per_rotation = dc_parser->angle_ticks_per_rotation;
317  new_msg->start_angle_ticks = dc_parser->start_angle_ticks;
318  new_msg->end_angle_ticks = dc_parser->end_angle_ticks;
319  new_msg->mounting_yaw_angle_ticks = dc_parser->mounting_yaw_angle_ticks;
320  new_msg->mounting_pitch_angle_ticks = dc_parser->mounting_pitch_angle_ticks;
321  new_msg->mounting_roll_angle_ticks = dc_parser->mounting_roll_angle_ticks;
322  new_msg->mounting_position_x = dc_parser->mounting_position_x;
323  new_msg->mounting_position_y = dc_parser->mounting_position_y;
324  new_msg->mounting_position_z = dc_parser->mounting_position_z;
325  new_msg->ground_labeled = dc_parser->ground_labeled;
326  new_msg->dirt_labeled = dc_parser->dirt_labeled;
327  new_msg->rain_labeled = dc_parser->rain_labeled;
328  new_msg->mirror_side = static_cast<uint8_t>(dc_parser->mirror_side);
329 
330  for (auto scan_point : dc_parser->scan_point_list)
331  {
332  ibeo_msgs::ScanPoint2202 scan_point_msg;
333 
334  scan_point_msg.layer = scan_point.layer;
335  scan_point_msg.echo = scan_point.echo;
336  scan_point_msg.transparent_point = scan_point.transparent_point;
337  scan_point_msg.clutter_atmospheric = scan_point.clutter_atmospheric;
338  scan_point_msg.ground = scan_point.ground;
339  scan_point_msg.dirt = scan_point.dirt;
340  scan_point_msg.horizontal_angle = scan_point.horizontal_angle;
341  scan_point_msg.radial_distance = scan_point.radial_distance;
342  scan_point_msg.echo_pulse_width = scan_point.echo_pulse_width;
343 
344  new_msg->scan_point_list.push_back(scan_point_msg);
345  }
346 
347  new_msg->header.frame_id = frame_id;
348  new_msg->header.stamp = ros::Time::now();
349 }
350 
351 void IbeoLuxRosMsgHandler::fill2204(
352  IbeoTxMessage * parser_class,
353  ibeo_msgs::ScanData2204 * new_msg,
354  const std::string& frame_id)
355 {
356  auto dc_parser = dynamic_cast<ScanData2204*>(parser_class);
357 
358  fillIbeoHeader(dc_parser->ibeo_header, &(new_msg->ibeo_header));
359 
360  new_msg->scan_start_time = dc_parser->scan_start_time;
361  new_msg->scan_end_time_offset = dc_parser->scan_end_time_offset;
362  new_msg->ground_labeled = dc_parser->ground_labeled;
363  new_msg->dirt_labeled = dc_parser->dirt_labeled;
364  new_msg->rain_labeled = dc_parser->rain_labeled;
365  new_msg->mirror_side = static_cast<uint8_t>(dc_parser->mirror_side);
366  new_msg->coordinate_system = static_cast<uint8_t>(dc_parser->coordinate_system);
367  new_msg->scan_number = dc_parser->scan_number;
368  new_msg->scan_points = dc_parser->scan_points;
369  new_msg->number_of_scanner_infos = dc_parser->number_of_scanner_infos;
370 
371  ibeo_msgs::ScannerInfo2204 scan_info_msg;
372  ScannerInfo2204 info_tx;
373 
374  for (int k = 0; k < new_msg->number_of_scanner_infos; k++)
375  {
376  info_tx = dc_parser->scanner_info_list[k];
377  scan_info_msg.device_id = info_tx.device_id;
378  scan_info_msg.scanner_type = info_tx.scanner_type;
379  scan_info_msg.scan_number = info_tx.scan_number;
380  scan_info_msg.start_angle = info_tx.start_angle;
381  scan_info_msg.end_angle = info_tx.end_angle;
382  scan_info_msg.yaw_angle = info_tx.yaw_angle;
383  scan_info_msg.pitch_angle = info_tx.pitch_angle;
384  scan_info_msg.roll_angle = info_tx.roll_angle;
385  scan_info_msg.offset_x = info_tx.offset_x;
386  scan_info_msg.offset_y = info_tx.offset_y;
387  scan_info_msg.offset_z = info_tx.offset_z;
388 
389  new_msg->scanner_info_list.push_back(scan_info_msg);
390  }
391 
392  ibeo_msgs::ScanPoint2204 scan_point_msg;
393  ScanPoint2204 point_tx;
394 
395  for (int k = 0; k < new_msg->scan_points; k++)
396  {
397  point_tx = dc_parser->scan_point_list[k];
398  scan_point_msg.x_position = point_tx.x_position;
399  scan_point_msg.y_position = point_tx.y_position;
400  scan_point_msg.z_position = point_tx.z_position;
401  scan_point_msg.echo_width = point_tx.echo_width;
402  scan_point_msg.device_id = point_tx.device_id;
403  scan_point_msg.layer = point_tx.layer;
404  scan_point_msg.echo = point_tx.echo;
405  scan_point_msg.time_offset = point_tx.time_offset;
406  scan_point_msg.ground = point_tx.ground;
407  scan_point_msg.dirt = point_tx.dirt;
408  scan_point_msg.precipitation = point_tx.precipitation;
409 
410  new_msg->scan_point_list.push_back(scan_point_msg);
411  }
412 
413  new_msg->header.frame_id = frame_id;
414  new_msg->header.stamp = ros::Time::now();
415 }
416 
417 void IbeoLuxRosMsgHandler::fill2205(
418  IbeoTxMessage * parser_class,
419  ibeo_msgs::ScanData2205 * new_msg,
420  const std::string& frame_id)
421 {
422  auto dc_parser = dynamic_cast<ScanData2205*>(parser_class);
423 
424  fillIbeoHeader(dc_parser->ibeo_header, &(new_msg->ibeo_header));
425 
426  new_msg->scan_start_time = ntp_to_ros_time(dc_parser->scan_start_time);
427  new_msg->scan_end_time_offset = dc_parser->scan_end_time_offset;
428  new_msg->fused_scan = dc_parser->fused_scan;
429 
430  if (dc_parser->mirror_side == FRONT)
431  new_msg->mirror_side = ibeo_msgs::ScanData2205::FRONT;
432  else
433  new_msg->mirror_side = ibeo_msgs::ScanData2205::REAR;
434 
435  if (dc_parser->coordinate_system == SCANNER)
436  new_msg->coordinate_system = ibeo_msgs::ScanData2205::SCANNER;
437  else
438  new_msg->coordinate_system = ibeo_msgs::ScanData2205::VEHICLE;
439 
440  new_msg->scan_number = dc_parser->scan_number;
441  new_msg->scan_points = dc_parser->scan_points;
442  new_msg->number_of_scanner_infos = dc_parser->number_of_scanner_infos;
443 
444  for (auto scanner_info : dc_parser->scanner_info_list)
445  {
446  ibeo_msgs::ScannerInfo2205 scanner_info_msg;
447 
448  scanner_info_msg.device_id = scanner_info.device_id;
449  scanner_info_msg.scanner_type = scanner_info.scanner_type;
450  scanner_info_msg.scan_number = scanner_info.scan_number;
451  scanner_info_msg.start_angle = scanner_info.start_angle;
452  scanner_info_msg.end_angle = scanner_info.end_angle;
453  scanner_info_msg.scan_start_time = ntp_to_ros_time(scanner_info.scan_start_time);
454  scanner_info_msg.scan_end_time = ntp_to_ros_time(scanner_info.scan_end_time);
455  scanner_info_msg.scan_start_time_from_device = ntp_to_ros_time(scanner_info.scan_start_time_from_device);
456  scanner_info_msg.scan_end_time_from_device = ntp_to_ros_time(scanner_info.scan_end_time_from_device);
457  scanner_info_msg.scan_frequency = scanner_info.scan_frequency;
458  scanner_info_msg.beam_tilt = scanner_info.beam_tilt;
459  scanner_info_msg.scan_flags = scanner_info.scan_flags;
460 
461  scanner_info_msg.mounting_position.yaw_angle = scanner_info.mounting_position.yaw_angle;
462  scanner_info_msg.mounting_position.pitch_angle = scanner_info.mounting_position.pitch_angle;
463  scanner_info_msg.mounting_position.roll_angle = scanner_info.mounting_position.roll_angle;
464  scanner_info_msg.mounting_position.x_position = scanner_info.mounting_position.x_position;
465  scanner_info_msg.mounting_position.y_position = scanner_info.mounting_position.y_position;
466  scanner_info_msg.mounting_position.z_position = scanner_info.mounting_position.z_position;
467  for (int i = 0; i < 8; i++)
468  {
469  scanner_info_msg.resolutions[i].resolution_start_angle =
470  scanner_info.resolutions[i].resolution_start_angle;
471  scanner_info_msg.resolutions[i].resolution = scanner_info.resolutions[i].resolution;
472  }
473 
474  new_msg->scanner_info_list.push_back(scanner_info_msg);
475  }
476 
477  for (auto scan_point : dc_parser->scan_point_list)
478  {
479  ibeo_msgs::ScanPoint2205 scan_point_msg;
480 
481  scan_point_msg.x_position = scan_point.x_position;
482  scan_point_msg.y_position = scan_point.y_position;
483  scan_point_msg.z_position = scan_point.z_position;
484  scan_point_msg.echo_width = scan_point.echo_width;
485  scan_point_msg.device_id = scan_point.device_id;
486  scan_point_msg.layer = scan_point.layer;
487  scan_point_msg.echo = scan_point.echo;
488  scan_point_msg.time_offset = scan_point.time_offset;
489  scan_point_msg.ground = scan_point.ground;
490  scan_point_msg.dirt = scan_point.dirt;
491  scan_point_msg.precipitation = scan_point.precipitation;
492  scan_point_msg.transparent = scan_point.transparent;
493 
494  new_msg->scan_point_list.push_back(scan_point_msg);
495  }
496 
497  new_msg->header.frame_id = frame_id;
498  new_msg->header.stamp = ros::Time::now();
499 }
500 
501 void IbeoLuxRosMsgHandler::fill2221(
502  IbeoTxMessage * parser_class,
503  ibeo_msgs::ObjectData2221 * new_msg,
504  const std::string& frame_id)
505 {
506  auto dc_parser = dynamic_cast<ObjectData2221*>(parser_class);
507 
508  fillIbeoHeader(dc_parser->ibeo_header, &(new_msg->ibeo_header));
509 
510  new_msg->scan_start_timestamp = ntp_to_ros_time(dc_parser->scan_start_timestamp);
511  new_msg->number_of_objects = dc_parser->number_of_objects;
512 
513  ibeo_msgs::Object2221 object_msg;
514  Object2221 object_tx;
515  ibeo_msgs::Point2Di object_point_msg;
516  Point2Di point_tx;
517 
518  for (int k = 0; k < dc_parser->number_of_objects; k++)
519  {
520  object_tx = dc_parser->object_list[k];
521  object_msg.id = object_tx.id;
522  object_msg.age = object_tx.age;
523  object_msg.prediction_age = object_tx.prediction_age;
524  object_msg.relative_timestamp = object_tx.relative_timestamp;
525  object_msg.reference_point.x = object_tx.reference_point.x;
526  object_msg.reference_point.y = object_tx.reference_point.y;
527  object_msg.reference_point_sigma.x = object_tx.reference_point_sigma.x;
528  object_msg.reference_point_sigma.y = object_tx.reference_point_sigma.y;
529  object_msg.closest_point.x = object_tx.closest_point.x;
530  object_msg.closest_point.y = object_tx.closest_point.y;
531  object_msg.bounding_box_center.x = 0.01 * object_tx.bounding_box_center.x;
532  object_msg.bounding_box_center.y = 0.01 * object_tx.bounding_box_center.y;
533  object_msg.bounding_box_width = 0.01 * object_tx.bounding_box_width;
534  object_msg.bounding_box_length = 0.01 * object_tx.bounding_box_length;
535  object_msg.object_box_center.x = 0.01 * object_tx.object_box_center.x;
536  object_msg.object_box_center.y = 0.01 * object_tx.object_box_center.y;
537  object_msg.object_box_size.size_x = 0.01 * object_tx.object_box_size.size_x;
538  object_msg.object_box_size.size_y = 0.01 * object_tx.object_box_size.size_y;
539  object_msg.object_box_orientation = static_cast<float>(object_tx.object_box_orientation);
540  object_msg.absolute_velocity.x = object_tx.absolute_velocity.x;
541  object_msg.absolute_velocity.y = object_tx.absolute_velocity.y;
542  object_msg.absolute_velocity_sigma.size_x = object_tx.absolute_velocity_sigma.size_x;
543  object_msg.absolute_velocity_sigma.size_y = object_tx.absolute_velocity_sigma.size_y;
544  object_msg.relative_velocity.x = object_tx.relative_velocity.x;
545  object_msg.relative_velocity.y = object_tx.relative_velocity.y;
546  object_msg.classification = static_cast<uint8_t>(object_tx.classification);
547  object_msg.classification_age = object_tx.classification_age;
548  object_msg.classification_certainty = object_tx.classification_certainty;
549  object_msg.number_of_contour_points = object_tx.number_of_contour_points;
550 
551  for (int j = 0; j < object_msg.number_of_contour_points; j++)
552  {
553  point_tx.x = object_tx.contour_point_list[k].x;
554  point_tx.y = object_tx.contour_point_list[k].y;
555  object_point_msg.x = 0.01 * point_tx.x;
556  object_point_msg.y = 0.01 * point_tx.y;
557 
558  object_msg.contour_point_list.push_back(object_point_msg);
559  }
560 
561  new_msg->object_list.push_back(object_msg);
562  }
563 
564  new_msg->header.frame_id = frame_id;
565  new_msg->header.stamp = ros::Time::now();
566 }
567 
568 void IbeoLuxRosMsgHandler::fill2225(
569  IbeoTxMessage * parser_class,
570  ibeo_msgs::ObjectData2225 * new_msg,
571  const std::string& frame_id)
572 {
573  auto dc_parser = dynamic_cast<ObjectData2225*>(parser_class);
574 
575  fillIbeoHeader(dc_parser->ibeo_header, &(new_msg->ibeo_header));
576 
577  new_msg->mid_scan_timestamp = ntp_to_ros_time(dc_parser->mid_scan_timestamp);
578  new_msg->number_of_objects = dc_parser->number_of_objects;
579 
580  for (auto object : dc_parser->object_list)
581  {
582  ibeo_msgs::Object2225 object_msg;
583 
584  object_msg.id = object.id;
585  object_msg.age = object.age;
586  object_msg.timestamp = ntp_to_ros_time(object.timestamp);
587  object_msg.hidden_status_age = object.hidden_status_age;
588 
589  switch (object.classification)
590  {
591  case UNCLASSIFIED:
592  object_msg.classification = ibeo_msgs::Object2225::UNCLASSIFIED;
593  break;
594  case UNKNOWN_SMALL:
595  object_msg.classification = ibeo_msgs::Object2225::UNKNOWN_SMALL;
596  break;
597  case UNKNOWN_BIG:
598  object_msg.classification = ibeo_msgs::Object2225::UNKNOWN_BIG;
599  break;
600  case PEDESTRIAN:
601  object_msg.classification = ibeo_msgs::Object2225::PEDESTRIAN;
602  break;
603  case BIKE:
604  object_msg.classification = ibeo_msgs::Object2225::BIKE;
605  break;
606  case CAR:
607  object_msg.classification = ibeo_msgs::Object2225::CAR;
608  break;
609  case TRUCK:
610  object_msg.classification = ibeo_msgs::Object2225::TRUCK;
611  break;
612  default:
613  object_msg.classification = ibeo_msgs::Object2225::UNCLASSIFIED;
614  break;
615  }
616 
617  object_msg.classification_certainty = object.classification_certainty;
618  object_msg.classification_age = object.classification_age;
619  object_msg.bounding_box_center.x = object.bounding_box_center.x;
620  object_msg.bounding_box_center.y = object.bounding_box_center.y;
621  object_msg.bounding_box_size.x = object.bounding_box_size.x;
622  object_msg.bounding_box_size.y = object.bounding_box_size.y;
623  object_msg.object_box_center.x = object.object_box_center.x;
624  object_msg.object_box_center.y = object.object_box_center.y;
625  object_msg.object_box_center_sigma.x = object.object_box_center_sigma.x;
626  object_msg.object_box_center_sigma.y = object.object_box_center_sigma.y;
627  object_msg.object_box_size.x = object.object_box_size.x;
628  object_msg.object_box_size.y = object.object_box_size.y;
629  object_msg.yaw_angle = object.yaw_angle;
630  object_msg.relative_velocity.x = object.relative_velocity.x;
631  object_msg.relative_velocity.y = object.relative_velocity.y;
632  object_msg.relative_velocity_sigma.x = object.relative_velocity_sigma.x;
633  object_msg.relative_velocity_sigma.y = object.relative_velocity_sigma.y;
634  object_msg.absolute_velocity.x = object.absolute_velocity.x;
635  object_msg.absolute_velocity.y = object.absolute_velocity.y;
636  object_msg.absolute_velocity_sigma.x = object.absolute_velocity_sigma.x;
637  object_msg.absolute_velocity_sigma.y = object.absolute_velocity_sigma.y;
638  object_msg.number_of_contour_points = object.number_of_contour_points;
639  object_msg.closest_point_index = object.closest_point_index;
640 
641  for (auto contour_point : object.contour_point_list)
642  {
643  ibeo_msgs::Point2Df contour_point_msg;
644 
645  contour_point_msg.x = contour_point.x;
646  contour_point_msg.y = contour_point.y;
647 
648  object_msg.contour_point_list.push_back(contour_point_msg);
649  }
650 
651  new_msg->object_list.push_back(object_msg);
652  }
653 
654  new_msg->header.frame_id = frame_id;
655  new_msg->header.stamp = ros::Time::now();
656 }
657 
658 void IbeoLuxRosMsgHandler::fill2280(
659  IbeoTxMessage * parser_class,
660  ibeo_msgs::ObjectData2280 * new_msg,
661  const std::string& frame_id)
662 {
663  auto dc_parser = dynamic_cast<ObjectData2280*>(parser_class);
664 
665  fillIbeoHeader(dc_parser->ibeo_header, &(new_msg->ibeo_header));
666 
667  new_msg->mid_scan_timestamp = ntp_to_ros_time(dc_parser->mid_scan_timestamp);
668  new_msg->number_of_objects = dc_parser->number_of_objects;
669 
670  for (auto object : dc_parser->object_list)
671  {
672  ibeo_msgs::Object2280 object_msg;
673 
674  object_msg.id = object.id;
675 
676  if (object.tracking_model == DYNAMIC)
677  {
678  object_msg.tracking_model = object_msg.DYNAMIC_MODEL;
679  }
680  else
681  {
682  object_msg.tracking_model = object_msg.STATIC_MODEL;
683  }
684 
685  object_msg.mobility_of_dyn_object_detected = object.mobility_of_dyn_object_detected;
686  object_msg.motion_model_validated = object.motion_model_validated;
687  object_msg.object_age = object.object_age;
688  object_msg.timestamp = ntp_to_ros_time(object.timestamp);
689  object_msg.object_prediction_age = object.object_prediction_age;
690 
691  switch (object.classification)
692  {
693  case UNCLASSIFIED:
694  object_msg.classification = object_msg.UNCLASSIFIED;
695  break;
696  case UNKNOWN_SMALL:
697  object_msg.classification = object_msg.UNKNOWN_SMALL;
698  break;
699  case UNKNOWN_BIG:
700  object_msg.classification = object_msg.UNKNOWN_BIG;
701  break;
702  case PEDESTRIAN:
703  object_msg.classification = object_msg.PEDESTRIAN;
704  break;
705  case BIKE:
706  object_msg.classification = object_msg.BIKE;
707  break;
708  case CAR:
709  object_msg.classification = object_msg.CAR;
710  break;
711  case TRUCK:
712  object_msg.classification = object_msg.TRUCK;
713  break;
714  }
715 
716  object_msg.classification_certainty = object.classification_certainty;
717  object_msg.classification_age = object.classification_age;
718 
719  object_msg.object_box_center.x = object.object_box_center.x;
720  object_msg.object_box_center.y = object.object_box_center.y;
721 
722  object_msg.object_box_center_sigma.x = object.object_box_center_sigma.x;
723  object_msg.object_box_center_sigma.y = object.object_box_center_sigma.y;
724 
725  object_msg.object_box_size.x = object.object_box_size.x;
726  object_msg.object_box_size.y = object.object_box_size.y;
727 
728  object_msg.object_box_orientation_angle = object.object_box_orientation_angle;
729  object_msg.object_box_orientation_angle_sigma = object.object_box_orientation_angle_sigma;
730 
731  object_msg.relative_velocity.x = object.relative_velocity.x;
732  object_msg.relative_velocity.y = object.relative_velocity.y;
733 
734  object_msg.relative_velocity_sigma.x = object.relative_velocity_sigma.x;
735  object_msg.relative_velocity_sigma.y = object.relative_velocity_sigma.y;
736 
737  object_msg.absolute_velocity.x = object.absolute_velocity.x;
738  object_msg.absolute_velocity.y = object.absolute_velocity.y;
739 
740  object_msg.absolute_velocity_sigma.x = object.absolute_velocity_sigma.x;
741  object_msg.absolute_velocity_sigma.y = object.absolute_velocity_sigma.y;
742 
743  object_msg.closest_point_index = object.closest_point_index;
744 
745  object_msg.reference_point_location = (uint16_t) object.reference_point_location;
746  switch (object.reference_point_location)
747  {
748  case COG:
749  object_msg.reference_point_location = object_msg.CENTER_OF_GRAVITY;
750  break;
752  object_msg.reference_point_location = object_msg.FRONT_LEFT;
753  break;
755  object_msg.reference_point_location = object_msg.FRONT_RIGHT;
756  break;
758  object_msg.reference_point_location = object_msg.REAR_RIGHT;
759  break;
761  object_msg.reference_point_location = object_msg.REAR_LEFT;
762  break;
764  object_msg.reference_point_location = object_msg.FRONT_CENTER;
765  break;
767  object_msg.reference_point_location = object_msg.RIGHT_CENTER;
768  break;
770  object_msg.reference_point_location = object_msg.REAR_CENTER;
771  break;
772  case CENTER_OF_LEFT_EDGE:
773  object_msg.reference_point_location = object_msg.LEFT_CENTER;
774  break;
775  case BOX_CENTER:
776  object_msg.reference_point_location = object_msg.OBJECT_CENTER;
777  break;
778  case INVALID:
779  object_msg.reference_point_location = object_msg.UNKNOWN;
780  break;
781  }
782 
783  object_msg.reference_point_coordinate.x = object.reference_point_coordinate.x;
784  object_msg.reference_point_coordinate.y = object.reference_point_coordinate.y;
785 
786  object_msg.reference_point_coordinate_sigma.x = object.reference_point_coordinate_sigma.x;
787  object_msg.reference_point_coordinate_sigma.y = object.reference_point_coordinate_sigma.y;
788 
789  object_msg.object_priority = object.object_priority;
790  object_msg.reference_point_position_correction_coefficient =
791  object.reference_point_position_correction_coefficient;
792  object_msg.object_priority = object.object_priority;
793  object_msg.object_existence_measurement = object.object_existence_measurement;
794 
795  object_msg.absolute_velocity.x = object.absolute_velocity.x;
796  object_msg.absolute_velocity.y = object.absolute_velocity.y;
797  object_msg.number_of_contour_points = object.number_of_contour_points;
798  for (auto contour_point : object.contour_point_list)
799  {
800  ibeo_msgs::Point2Df msg_cp;
801  msg_cp.x = contour_point.x;
802  msg_cp.y = contour_point.y;
803 
804  object_msg.contour_point_list.push_back(msg_cp);
805  }
806 
807  new_msg->objects.push_back(object_msg);
808  }
809 
810  new_msg->header.frame_id = frame_id;
811  new_msg->header.stamp = ros::Time::now();
812 }
813 
814 void IbeoLuxRosMsgHandler::fill2403(
815  IbeoTxMessage * parser_class,
816  ibeo_msgs::CameraImage * new_msg,
817  const std::string& frame_id)
818 {
819  auto dc_parser = dynamic_cast<CameraImage*>(parser_class);
820 
821  fillIbeoHeader(dc_parser->ibeo_header, &(new_msg->ibeo_header));
822 
823  switch (dc_parser->image_format)
824  {
825  case JPEG:
826  new_msg->image_format = new_msg->JPEG;
827  break;
828  case MJPEG:
829  new_msg->image_format = new_msg->MJPEG;
830  break;
831  case GRAY8:
832  new_msg->image_format = new_msg->GRAY8;
833  break;
834  case YUV420:
835  new_msg->image_format = new_msg->YUV420;
836  break;
837  case YUV422:
838  new_msg->image_format = new_msg->YUV422;
839  break;
840  }
841 
842  new_msg->us_since_power_on = dc_parser->us_since_power_on;
843  new_msg->timestamp = ntp_to_ros_time(dc_parser->timestamp);
844  new_msg->device_id = dc_parser->device_id;
845 
846  new_msg->mounting_position.yaw_angle = dc_parser->mounting_position.yaw_angle;
847  new_msg->mounting_position.pitch_angle = dc_parser->mounting_position.pitch_angle;
848  new_msg->mounting_position.roll_angle = dc_parser->mounting_position.roll_angle;
849  new_msg->mounting_position.x_position = dc_parser->mounting_position.x_position;
850  new_msg->mounting_position.y_position = dc_parser->mounting_position.y_position;
851  new_msg->mounting_position.z_position = dc_parser->mounting_position.z_position;
852 
853  new_msg->horizontal_opening_angle = dc_parser->horizontal_opening_angle;
854  new_msg->vertical_opening_angle = dc_parser->vertical_opening_angle;
855  new_msg->image_width = dc_parser->image_width;
856  new_msg->image_height = dc_parser->image_height;
857  new_msg->compressed_size = dc_parser->compressed_size;
858 
859  for (int i = 0; i < dc_parser->image_width * dc_parser->image_height; i++)
860  {
861  new_msg->image_buffer[i] = dc_parser->image_buffer[i];
862  }
863 
864  new_msg->header.frame_id = frame_id;
865  new_msg->header.stamp = ros::Time::now();
866 }
867 
868 void IbeoLuxRosMsgHandler::fill2805(
869  IbeoTxMessage * parser_class,
870  ibeo_msgs::HostVehicleState2805 * new_msg,
871  const std::string& frame_id)
872 {
873  auto dc_parser = dynamic_cast<HostVehicleState2805*>(parser_class);
874 
875  fillIbeoHeader(dc_parser->ibeo_header, &(new_msg->ibeo_header));
876 
877  new_msg->timestamp = ntp_to_ros_time(dc_parser->timestamp);
878  new_msg->scan_number = dc_parser->scan_number;
879  new_msg->error_flags = dc_parser->error_flags;
880  new_msg->longitudinal_velocity = dc_parser->longitudinal_velocity;
881  new_msg->steering_wheel_angle = dc_parser->steering_wheel_angle;
882  new_msg->front_wheel_angle = dc_parser->front_wheel_angle;
883  new_msg->x_position = dc_parser->x_position;
884  new_msg->y_position = dc_parser->y_position;
885  new_msg->course_angle = dc_parser->course_angle;
886  new_msg->time_difference = dc_parser->time_difference;
887  new_msg->x_difference = dc_parser->x_difference;
888  new_msg->y_difference = dc_parser->y_difference;
889  new_msg->heading_difference = dc_parser->heading_difference;
890  new_msg->current_yaw_rate = dc_parser->current_yaw_rate;
891 
892  new_msg->header.frame_id = frame_id;
893  new_msg->header.stamp = ros::Time::now();
894 }
895 
896 void IbeoLuxRosMsgHandler::fill2806(
897  IbeoTxMessage * parser_class,
898  ibeo_msgs::HostVehicleState2806 * new_msg,
899  const std::string& frame_id)
900 {
901  auto dc_parser = dynamic_cast<HostVehicleState2806*>(parser_class);
902 
903  fillIbeoHeader(dc_parser->ibeo_header, &(new_msg->ibeo_header));
904 
905  new_msg->timestamp = ntp_to_ros_time(dc_parser->timestamp);
906 
907  new_msg->distance_x = dc_parser->distance_x;
908  new_msg->distance_y = dc_parser->distance_y;
909  new_msg->course_angle = dc_parser->course_angle;
910  new_msg->longitudinal_velocity = dc_parser->longitudinal_velocity;
911  new_msg->yaw_rate = dc_parser->yaw_rate;
912  new_msg->steering_wheel_angle = dc_parser->steering_wheel_angle;
913  new_msg->cross_acceleration = dc_parser->cross_acceleration;
914  new_msg->front_wheel_angle = dc_parser->front_wheel_angle;
915  new_msg->vehicle_width = dc_parser->vehicle_width;
916  new_msg->vehicle_front_to_front_axle = dc_parser->vehicle_front_to_front_axle;
917  new_msg->rear_axle_to_front_axle = dc_parser->rear_axle_to_front_axle;
918  new_msg->rear_axle_to_vehicle_rear = dc_parser->rear_axle_to_vehicle_rear;
919  new_msg->steer_ratio_poly_0 = dc_parser->steer_ratio_poly_0;
920  new_msg->steer_ratio_poly_1 = dc_parser->steer_ratio_poly_1;
921  new_msg->steer_ratio_poly_2 = dc_parser->steer_ratio_poly_2;
922  new_msg->steer_ratio_poly_3 = dc_parser->steer_ratio_poly_3;
923 
924  new_msg->header.frame_id = frame_id;
925  new_msg->header.stamp = ros::Time::now();
926 }
927 
928 void IbeoLuxRosMsgHandler::fill2807(
929  IbeoTxMessage * parser_class,
930  ibeo_msgs::HostVehicleState2807 * new_msg,
931  const std::string& frame_id)
932 {
933  auto dc_parser = dynamic_cast<HostVehicleState2807*>(parser_class);
934 
935  fillIbeoHeader(dc_parser->ibeo_header, &(new_msg->ibeo_header));
936 
937  new_msg->timestamp = ntp_to_ros_time(dc_parser->timestamp);
938 
939  new_msg->distance_x = dc_parser->distance_x;
940  new_msg->distance_y = dc_parser->distance_y;
941  new_msg->course_angle = dc_parser->course_angle;
942  new_msg->longitudinal_velocity = dc_parser->longitudinal_velocity;
943  new_msg->yaw_rate = dc_parser->yaw_rate;
944  new_msg->steering_wheel_angle = dc_parser->steering_wheel_angle;
945  new_msg->cross_acceleration = dc_parser->cross_acceleration;
946  new_msg->front_wheel_angle = dc_parser->front_wheel_angle;
947  new_msg->vehicle_width = dc_parser->vehicle_width;
948  new_msg->vehicle_front_to_front_axle = dc_parser->vehicle_front_to_front_axle;
949  new_msg->rear_axle_to_front_axle = dc_parser->rear_axle_to_front_axle;
950  new_msg->rear_axle_to_vehicle_rear = dc_parser->rear_axle_to_vehicle_rear;
951  new_msg->steer_ratio_poly_0 = dc_parser->steer_ratio_poly_0;
952  new_msg->steer_ratio_poly_1 = dc_parser->steer_ratio_poly_1;
953  new_msg->steer_ratio_poly_2 = dc_parser->steer_ratio_poly_2;
954  new_msg->steer_ratio_poly_3 = dc_parser->steer_ratio_poly_3;
955  new_msg->longitudinal_acceleration = dc_parser->longitudinal_acceleration;
956 
957  new_msg->header.frame_id = frame_id;
958  new_msg->header.stamp = ros::Time::now();
959 }
960 
961 visualization_msgs::Marker IbeoLuxRosMsgHandler::createWireframeMarker(
962  const float& center_x,
963  const float& center_y,
964  float size_x,
965  float size_y,
966  const float& size_z)
967 {
968  visualization_msgs::Marker box;
969  box.pose.position.x = center_x;
970  box.pose.position.y = center_y;
971  geometry_msgs::Point p1, p2, p3, p4, p5, p6, p7, p8;
972 
973  size_y = (size_y <= 0.1f) ? 0.1f : size_y;
974  size_x = (size_x <= 0.1f) ? 0.1f : size_x;
975 
976  float half_x = (0.5) * size_x;
977  float half_y = (0.5) * size_y;
978 
979  p1.x = half_x;
980  p1.y = half_y;
981  p1.z = size_z;
982  p2.x = half_x;
983  p2.y = -half_y;
984  p2.z = size_z;
985  p3.x = -half_x;
986  p3.y = -half_y;
987  p3.z = size_z;
988  p4.x = -half_x;
989  p4.y = half_y;
990  p4.z = size_z;
991  p5 = p1;
992  p5.z = -size_z;
993  p6 = p2;
994  p6.z = -size_z;
995  p7 = p3;
996  p7.z = -size_z;
997  p8 = p4;
998  p8.z = -size_z;
999 
1000  box.points.reserve(24);
1001 
1002  box.points.push_back(p1);
1003  box.points.push_back(p2);
1004 
1005  box.points.push_back(p2);
1006  box.points.push_back(p3);
1007 
1008  box.points.push_back(p3);
1009  box.points.push_back(p4);
1010 
1011  box.points.push_back(p4);
1012  box.points.push_back(p1);
1013 
1014  box.points.push_back(p1);
1015  box.points.push_back(p5);
1016 
1017  box.points.push_back(p2);
1018  box.points.push_back(p6);
1019 
1020  box.points.push_back(p3);
1021  box.points.push_back(p7);
1022 
1023  box.points.push_back(p4);
1024  box.points.push_back(p8);
1025 
1026  box.points.push_back(p5);
1027  box.points.push_back(p6);
1028 
1029  box.points.push_back(p6);
1030  box.points.push_back(p7);
1031 
1032  box.points.push_back(p7);
1033  box.points.push_back(p8);
1034 
1035  box.points.push_back(p8);
1036  box.points.push_back(p5);
1037 
1038  return box;
1039 }
#define NTP_TO_UTC
void publish(const boost::shared_ptr< M > &message) const
f
static const int32_t DATA_TYPE
static const int32_t DATA_TYPE
static const int32_t DATA_TYPE
static const int32_t DATA_TYPE
static Quaternion createQuaternionFromYaw(double yaw)
static const int32_t DATA_TYPE
static const int32_t DATA_TYPE
uint64_t NTPTime
static const int32_t DATA_TYPE
static const int32_t DATA_TYPE
static Time now()
std::vector< Point2Di > contour_point_list


ibeo_lux
Author(s): Joe Kale , Joshua Whitley
autogenerated on Sat Jun 8 2019 04:47:04