33 #ifndef _READ_VELODYNE_CPP_
34 #define _READ_VELODYNE_CPP_
45 coefficients = pcl::ModelCoefficients::Ptr(
new pcl::ModelCoefficients);
46 indices = pcl::PointIndices::Ptr(
new pcl::PointIndices);
73 printf(
"%d %d %d\n",sig,SIGSEGV,SIGINT);
78 signal(SIGSEGV, SIG_DFL);
80 ROS_WARN(
"System segfaulted");
88 ROS_WARN(
"Ctrl-c pressed");
101 int main(
int argc,
char **argv)
105 "usage: example4-velodyne <logfile> <start_time> <end time>\n"
107 "start_time and end_time are given in seconds from the\n"
108 "start of the log file\n");
114 fprintf(stderr,
"error opening log file\n");
118 double start_time = strtod(argv[2], NULL);
119 double end_time = strtod(argv[3], NULL);
123 fprintf(stderr,
"couldn't find config file\n");
132 int64_t first_timestamp =
event->timestamp;
135 int64_t start_utime = first_timestamp + (int64_t)(start_time * 1000000);
136 int64_t end_utime = first_timestamp + (int64_t)(end_time * 1000000);
139 memset(&last_pose, 0,
sizeof(last_pose));
146 ros::init(argc, argv,
"point_cloud_publisher");
149 ros::Publisher cloud_pub = n.advertise<sensor_msgs::PointCloud2>(
"cloud", 1);
151 ros::Publisher pub[10];
156 sprintf(str,
"plg_%d",i);
157 pub[i] = n.advertise<sensor_msgs::PointCloud2>(str, 1);
161 ros::Publisher marker_pub = n.advertise<visualization_msgs::Marker>(
"visualization_marker", 10);
167 pcl::PointCloud<PointT> cloud;
168 sensor_msgs::PointCloud2 cloud_msg;
169 cloud.header.frame_id =
"/sensor_frame";
185 if(!strcmp(event->channel,
"POSE")) {
193 if(event->timestamp < start_utime) {
198 if(event->timestamp >= end_utime) {
202 if(!strcmp(event->channel,
"VELODYNE")) {
213 double velodyne_to_local[16];
215 velodyne_to_local, &last_pose);
227 if (vsample.
range < 0.01)
232 double sensor_xyz[4] = {vsample.
xyz[0], vsample.
xyz[1], vsample.
xyz[2], 1 };
252 cloud.width = cloud.size();
260 visualization_msgs::Marker markers;
261 markers.header.frame_id =
"/sensor_frame";
262 markers.header.stamp = ros::Time::now();
263 markers.ns =
"triangles";
264 markers.action = visualization_msgs::Marker::ADD;
265 markers.pose.orientation.w = 1.0;
266 markers.type = visualization_msgs::Marker::TRIANGLE_LIST;
277 geometry_msgs::Point p;
278 std_msgs::ColorRGBA color;
282 markers.points.push_back(p);
287 markers.colors.push_back(color);
292 markers.points.push_back(p);
297 markers.colors.push_back(color);
302 markers.points.push_back(p);
307 markers.colors.push_back(color);
309 marker_pub.publish(markers);
311 printf(
"num pts = %d\n",(
int)markers.points.size());
312 printf(
"num colors = %d\n",(
int)markers.colors.size());
315 ROS_ERROR(
"Cloud timestamp not set, problem during migration lar3 to lar4");
316 ROS_INFO(
"publishing cloud with %d points",(
int)cloud.size());
318 pcl::toROSMsg(cloud, cloud_msg);
319 cloud_pub.publish(cloud_msg);
329 sensor_msgs::PointCloud2 cloud_model_msg;
333 pcl::SACSegmentation<PointT> seg;
334 seg.setOptimizeCoefficients(
true);
335 seg.setModelType(pcl::SACMODEL_PLANE);
336 seg.setMethodType (pcl::SAC_RANSAC);
337 seg.setDistanceThreshold (0.3);
338 seg.setMaxIterations (1000);
341 pcl::ExtractIndices<PointT> extract;
344 pcl::PointCloud<PointT> cloud_tmp;
353 seg.setInputCloud(cloud_tmp.makeShared());
354 seg.segment(*plg[i]->indices, *plg[i]->coefficients);
356 if (plg[i]->indices->
indices.size () == 0)
358 ROS_ERROR(
"Could not estimate a planar model for the given dataset.");
return (-1);
364 extract.setInputCloud(cloud_tmp.makeShared());
365 extract.setIndices(plg[i]->indices);
366 extract.setNegative(
false);
367 extract.filter(plg[i]->cloud);
368 extract.setNegative(
true);
369 extract.filter(cloud_tmp);
377 plg[i]->
cloud.header.frame_id =
"/sensor_frame";
378 plg[i]->
cloud.height = 1;
379 plg[i]->
cloud.is_dense=0;
381 ROS_INFO(
"publishing cloud_model[%d] with %d points",i,(
int)plg[i]->cloud.size());
382 pcl::toROSMsg(plg[i]->cloud, cloud_model_msg);
383 pub[i].publish(cloud_model_msg);
int lcmtypes_velodyne_t_decode(const void *buf, int offset, int maxlen, lcmtypes_velodyne_t *p)
Config * config_parse_default(void)
int lcmtypes_pose_t_decode_cleanup(lcmtypes_pose_t *p)
void lcm_eventlog_destroy(lcm_eventlog_t *l)
lcm_eventlog_event_t * lcm_eventlog_read_next_event(lcm_eventlog_t *l)
velodyne_calib_t * velodyne_calib_create()
int velodyne_decoder_init(velodyne_calib_t *v, velodyne_decoder_t *vd, const void *_data, int datalen)
int lcmtypes_pose_t_decode(const void *buf, int offset, int maxlen, lcmtypes_pose_t *p)
c_polygon_representation()
Constructor. Allocate space for Ptr objecs.
static void matrix_vector_multiply_4x4_4d(const double m[16], const double v[4], double result[4])
pcl::PointIndices::Ptr indices
header file for read_velodyne.cpp
int velodyne_decoder_next(velodyne_calib_t *v, velodyne_decoder_t *vd, struct velodyne_sample *sample)
int lcmtypes_velodyne_t_decode_cleanup(lcmtypes_velodyne_t *p)
int main(int argc, char **argv)
int config_util_sensor_to_local_with_pose(Config *cfg, const char *name, double m[16], lcmtypes_pose_t *p)
~c_polygon_representation()
destructor. free space of Ptr objecs
void lcm_eventlog_free_event(lcm_eventlog_event_t *le)
void signal_handler(int sig)
pcl::ModelCoefficients::Ptr coefficients
Variables for polyplane segmentation and representation.
lcm_eventlog_t * lcm_eventlog_create(const char *path, const char *mode)
pcl::PointCloud< PointT > cloud