13 #include <network_interface/TCPFrame.h> 15 #include <unordered_map> 28 std::unordered_map<int64_t, ros::Publisher>
pub_list;
31 int main(
int argc,
char **argv)
34 string ip_address =
"192.168.0.1";
36 string frame_id =
"ibeo_lux";
37 bool is_fusion =
false;
38 int buf_size = AS::Drivers::Ibeo::IBEO_PAYLOAD_SIZE;
39 std::deque<uint8_t> grand_buffer;
40 std::queue<std::vector<uint8_t>> messages;
48 if (priv.
getParam(
"ip_address", ip_address))
50 ROS_INFO(
"Ibeo LUX - Got ip_address: %s", ip_address.c_str());
54 ROS_ERROR(
"Ibeo LUX - IP Address Invalid");
61 ROS_INFO(
"Ibeo LUX - Got port: %d", port);
70 if (priv.
getParam(
"is_fusion", is_fusion))
72 ROS_INFO(
"Ibeo LUX - Is Fusion ECU: %s", (is_fusion) ?
"true" :
"false");
75 if (priv.
getParam(
"sensor_frame_id", frame_id))
77 ROS_INFO(
"Ibeo LUX - Got sensor frame ID: %s", frame_id.c_str());
87 ros::Publisher object_contour_points_pub = n.
advertise<visualization_msgs::Marker>(
"as_tx/object_contour_points", 1);
89 ros::Publisher scan_data_pub, object_data_pub, vehicle_state_pub, error_warn_pub;
92 fusion_object_2225_pub,
93 fusion_object_2280_pub,
95 fusion_vehicle_2806_pub,
96 fusion_vehicle_2807_pub;
101 scan_data_pub = n.
advertise<ibeo_msgs::ScanData2202>(
"parsed_tx/scan_data_2202", 1);
102 object_data_pub = n.
advertise<ibeo_msgs::ObjectData2221>(
"parsed_tx/object_data_2221", 1);
103 vehicle_state_pub = n.
advertise<ibeo_msgs::HostVehicleState2805>(
"parsed_tx/host_vehicle_state_2805", 1);
104 error_warn_pub = n.
advertise<ibeo_msgs::ErrorWarning>(
"parsed_tx/error_warning", 1);
106 pub_list.insert(std::make_pair(ErrorWarning::DATA_TYPE, error_warn_pub));
107 pub_list.insert(std::make_pair(ScanData2202::DATA_TYPE, scan_data_pub));
108 pub_list.insert(std::make_pair(ObjectData2221::DATA_TYPE, object_data_pub));
109 pub_list.insert(std::make_pair(HostVehicleState2805::DATA_TYPE, vehicle_state_pub));
113 fusion_scan_2204_pub = n.
advertise<ibeo_msgs::ScanData2204>(
"parsed_tx/scan_data_2204", 1);
114 fusion_scan_2205_pub = n.
advertise<ibeo_msgs::ScanData2205>(
"parsed_tx/scan_data_2205", 1);
115 fusion_object_2225_pub = n.
advertise<ibeo_msgs::ObjectData2225>(
"parsed_tx/object_data_2225", 1);
116 fusion_object_2280_pub = n.
advertise<ibeo_msgs::ObjectData2280>(
"parsed_tx/object_data_2280", 1);
117 fusion_img_2403_pub = n.
advertise<ibeo_msgs::CameraImage>(
"parsed_tx/camera_image", 1);
118 fusion_vehicle_2806_pub = n.
advertise<ibeo_msgs::HostVehicleState2806>(
"parsed_tx/host_vehicle_state_2806", 1);
119 fusion_vehicle_2807_pub = n.
advertise<ibeo_msgs::HostVehicleState2807>(
"parsed_tx/host_vehicle_state_2807", 1);
121 pub_list.insert(std::make_pair(ScanData2204::DATA_TYPE, fusion_scan_2204_pub));
122 pub_list.insert(std::make_pair(ScanData2205::DATA_TYPE, fusion_scan_2205_pub));
123 pub_list.insert(std::make_pair(ObjectData2225::DATA_TYPE, fusion_object_2225_pub));
124 pub_list.insert(std::make_pair(ObjectData2280::DATA_TYPE, fusion_object_2280_pub));
125 pub_list.insert(std::make_pair(CameraImage::DATA_TYPE, fusion_img_2403_pub));
126 pub_list.insert(std::make_pair(HostVehicleState2806::DATA_TYPE, fusion_vehicle_2806_pub));
127 pub_list.insert(std::make_pair(HostVehicleState2807::DATA_TYPE, fusion_vehicle_2807_pub));
133 network_interface::TCPFrame tcp_raw_msg;
135 ReturnStatuses status;
140 bool fusion_filter_sent =
false;
147 fusion_filter_sent =
false;
149 status = tcp_interface.
open(ip_address.c_str(), port);
151 if (status != ReturnStatuses::OK)
152 ROS_WARN(
"Ibeo LUX - Unable to connect to sensor at %s: %d - %s",
160 if (is_fusion && !fusion_filter_sent)
162 std::vector<uint8_t> set_filter_cmd =
163 {0xaf, 0xfe, 0xc0, 0xc2,
164 0x00, 0x00, 0x00, 0x00,
165 0x00, 0x00, 0x00, 0x08,
166 0x00, 0x00, 0x20, 0x10,
167 0x00, 0x00, 0x00, 0x00,
168 0x00, 0x00, 0x00, 0x00,
169 0x00, 0x05, 0x00, 0x02,
170 0x00, 0x00, 0xff, 0xff};
172 ROS_INFO_THROTTLE(3,
"Ibeo LUX - Sending Fusion filter command to begin transmission.");
174 status = tcp_interface.
write(set_filter_cmd);
176 if (status != ReturnStatuses::OK)
179 fusion_filter_sent =
true;
185 buf_size = IBEO_PAYLOAD_SIZE;
186 std::vector<uint8_t> msg_buf;
187 msg_buf.reserve(buf_size);
189 status = tcp_interface.
read(&msg_buf);
191 if (status != ReturnStatuses::OK && status != ReturnStatuses::NO_MESSAGES_RECEIVED)
193 ROS_WARN(
"Ibeo ScaLa - Failed to read from socket: %d - %s",
194 static_cast<int>(status),
197 else if (status == ReturnStatuses::OK)
199 buf_size = msg_buf.size();
200 grand_buffer.insert(grand_buffer.end(), msg_buf.begin(), msg_buf.end());
216 grand_buffer.begin(),
217 grand_buffer.begin() + first_mw);
221 IbeoDataHeader header;
222 header.parse(std::vector<uint8_t>(grand_buffer.begin(), grand_buffer.begin() + IBEO_HEADER_SIZE));
224 auto total_msg_size = IBEO_HEADER_SIZE + header.message_size;
226 if (grand_buffer.size() < total_msg_size)
229 std::vector<uint8_t> msg(
230 grand_buffer.begin(),
231 grand_buffer.begin() + total_msg_size);
234 grand_buffer.begin(),
235 grand_buffer.begin() + total_msg_size);
243 while (!messages.empty())
245 auto message = messages.front();
247 network_interface::TCPFrame raw_frame;
248 raw_frame.address = ip_address;
249 raw_frame.port = port;
250 raw_frame.size = message.size();
251 raw_frame.data.insert(raw_frame.data.end(), message.begin(), message.end());
252 raw_frame.header.frame_id = frame_id;
255 raw_tcp_pub.
publish(raw_frame);
257 IbeoDataHeader ibeo_header;
258 ibeo_header.parse(message);
261 auto class_parser = IbeoTxMessage::make_message(ibeo_header.data_type_id);
263 auto pub =
pub_list.find(ibeo_header.data_type_id);
266 if (class_parser != NULL && pub !=
pub_list.end())
269 class_parser->parse(message);
271 handler.
fillAndPublish(ibeo_header.data_type_id, frame_id, pub->second, class_parser.get());
273 if (class_parser->has_scan_points)
275 pcl::PointCloud<pcl::PointXYZL> pcl_cloud;
276 pcl_cloud.header.frame_id = frame_id;
279 std::vector<Point3DL> scan_points = class_parser->get_scan_points();
281 pointcloud_pub.publish(pcl_cloud);
284 if (class_parser->has_contour_points)
286 visualization_msgs::Marker marker;
287 marker.header.frame_id = frame_id;
289 std::vector<Point3D> contour_points = class_parser->get_contour_points();
291 if (contour_points.size() > 0)
294 object_contour_points_pub.publish(marker);
298 if (class_parser->has_objects)
300 std::vector<IbeoObject> objects = class_parser->get_objects();
301 visualization_msgs::MarkerArray marker_array;
304 for (visualization_msgs::Marker m : marker_array.markers)
306 m.header.frame_id = frame_id;
309 object_markers_pub.publish(marker_array);
322 status = tcp_interface.
close();
324 if (status != ReturnStatuses::OK)
326 "Ibeo LUX - Closing the connection to the LUX failed: %i - %s",
327 static_cast<int>(status),
void fillPointcloud(const std::vector< Point3DL > &points, pcl::PointCloud< pcl::PointXYZL > *new_msg)
void publish(const boost::shared_ptr< M > &message) const
int main(int argc, char **argv)
void fillAndPublish(const uint8_t &type_id, const std::string &frame_id, const ros::Publisher &pub, IbeoTxMessage *parser_class)
void fillContourPoints(const std::vector< Point3D > &points, visualization_msgs::Marker *new_msg, const std::string &frame_id)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void fillMarkerArray(const std::vector< IbeoObject > &objects, visualization_msgs::MarkerArray *new_msg, const std::string &frame_id)
return_statuses open(const char *ip_address, const int &port)
#define ROS_ERROR_THROTTLE(rate,...)
std::string return_status_desc(const return_statuses &ret)
std::unordered_map< int64_t, ros::Publisher > pub_list
TCPInterface tcp_interface
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
IbeoLuxRosMsgHandler handler
int32_t find_magic_word(uint8_t *in, uint32_t buf_size, size_t magic_word)
bool getParam(const std::string &key, std::string &s) const
#define ROS_INFO_THROTTLE(rate,...)
static bool waitForValid()
void toPCL(const ros::Time &stamp, pcl::uint64_t &pcl_stamp)
return_statuses write(unsigned char *msg, const size_t &msg_size)
return_statuses read(unsigned char *msg, const size_t &buf_size, size_t &bytes_read, int timeout_ms=0)