point_cloud_publisher.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * Software License Agreement (BSD License)
4 *
5 * Copyright (c) 2009, Willow Garage, Inc.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * * Neither the name of Willow Garage, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 *
35 * Author: Eitan Marder-Eppstein
36 *********************************************************************/
37 #include <ros/ros.h>
38 #include <sensor_msgs/PointCloud.h>
39 
40 int main(int argc, char** argv){
41  ros::init(argc, argv, "point_cloud_publisher");
42 
44  ros::Publisher cloud_pub = n.advertise<sensor_msgs::PointCloud>("cloud", 50);
45 
46  unsigned int num_points = 100;
47 
48  int count = 0;
49  ros::Rate r(1.0);
50  while(n.ok()){
51  sensor_msgs::PointCloud cloud;
52  cloud.header.stamp = ros::Time::now();
53  cloud.header.frame_id = "sensor_frame";
54 
55  cloud.points.resize(num_points);
56 
57  //we'll also add an intensity channel to the cloud
58  cloud.channels.resize(1);
59  cloud.channels[0].name = "intensities";
60  cloud.channels[0].values.resize(num_points);
61 
62  //generate some fake data for our point cloud
63  for(unsigned int i = 0; i < num_points; ++i){
64  cloud.points[i].x = 1 + count;
65  cloud.points[i].y = 2 + count;
66  cloud.points[i].z = 3 + count;
67  cloud.channels[0].values[i] = 100 + count;
68  }
69 
70  cloud_pub.publish(cloud);
71  ++count;
72  r.sleep();
73  }
74 }
void publish(const boost::shared_ptr< M > &message) const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
bool sleep()
int main(int argc, char **argv)
static Time now()
bool ok() const


point_cloud_publisher_tutorial
Author(s): Eitan Marder-Eppstein
autogenerated on Sun Jul 12 2020 03:52:53