lidar_listener.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 /* Authors: Taehun Lim (Darby) */
19 
20 #include <gazebo/transport/transport.hh>
21 #include <gazebo/msgs/msgs.hh>
22 #include <gazebo/gazebo_client.hh>
23 
24 #include <iostream>
25 
27 // Function is called everytime a message is received.
28 void laserScanCallbackMsg(ConstLaserScanStampedPtr &msg)
29 {
30  std::cout << "min angle : " << msg->scan().angle_min() << std::endl;
31  std::cout << "max angle : " << msg->scan().angle_max() << std::endl;
32  std::cout << "min range : " << msg->scan().range_min() << std::endl;
33  std::cout << "max range : " << msg->scan().range_max() << std::endl;
34 
35  std::cout << "scan data : [";
36  for (int angle = 0; angle < msg->scan().ranges_size(); angle++)
37  {
38  std::cout << msg->scan().ranges(angle) << ", ";
39  }
40 
41  std::cout << "]" << std::endl;
42 
43  // Add your code
44 }
45 
47 int main(int _argc, char **_argv)
48 {
49  // Load gazebo
50  gazebo::client::setup(_argc, _argv);
51 
52  // Create our node for communication
53  gazebo::transport::NodePtr node(new gazebo::transport::Node());
54  node->Init();
55 
56  if (_argc < 2)
57  {
58  std::cerr << "Please put a tb3 model(`burger`, `waffle` or `waffle_pi`)" << std::endl;
59  exit(0);
60  }
61 
62  char* tb3_model = _argv[1];
63  std::string topic_name = "/gazebo/default/user/turtlebot3_" + std::string(tb3_model) + "/lidar/hls_lfcd_lds/scan";
64 
65  std::cout << "topic name is " << topic_name << std::endl;
66 
67  // Listen to Gazebo world_stats topic
68  gazebo::transport::SubscriberPtr sub = node->Subscribe(topic_name, laserScanCallbackMsg);
69 
70  // Busy wait loop...replace with your own code as needed.
71  while (true)
72  gazebo::common::Time::MSleep(10);
73 
74  // Make sure to shut everything down.
75  gazebo::client::shutdown();
76 }
void laserScanCallbackMsg(ConstLaserScanStampedPtr &msg)
int main(int _argc, char **_argv)


turtlebot3_gazebo_plugin
Author(s): Pyo , Darby Lim
autogenerated on Tue Mar 13 2018 02:56:08