assemble_laser.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright 2018 ROBOTIS CO., LTD.
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  ** Includes
19  *****************************************************************************/
20 
21 #include <string>
22 #include <sstream>
23 #include <ros/ros.h>
24 #include <std_msgs/Bool.h>
25 #include <std_msgs/String.h>
26 #include <sensor_msgs/PointCloud2.h>
27 #include <sensor_msgs/JointState.h>
28 #include <laser_assembler/AssembleScans2.h>
29 #include <pcl/point_types.h>
30 #include <pcl/filters/statistical_outlier_removal.h>
32 
34 
36 
39 
41 
42 typedef pcl::PointXYZ PointT;
43 
44 /*****************************************************************************
45  ** Implementation
46  *****************************************************************************/
47 
48 void assembleLaserScans(ros::Time before_time, ros::Time end_time)
49 {
50  ros::Time now = ros::Time::now();
51 
52  laser_assembler::AssembleScans2 service;
53  service.request.begin = before_time;
54  service.request.end = end_time;
55 
56  if (g_assemble_chest_laser_client.call(service))
57  {
58  ros::Time assemble_time = ros::Time::now();
59  sensor_msgs::PointCloud2 assembler_output = service.response.cloud;
60  if (assembler_output.data.size() == 0)
61  {
62  // ROS_INFO("No scan data");
63  return;
64  }
65 
66  ROS_INFO(" --- publish pointcloud data!! --- %f", (ros::Time::now() - assemble_time).toSec());
67 
68  g_point_cloud2_pub.publish(assembler_output);
69  }
70 }
71 
72 void lidarTurnCallBack(const std_msgs::String::ConstPtr& msg)
73 {
74  ros::Time now = ros::Time::now();
75 
76  if (msg->data == "start")
77  {
78  g_lidar_move_start_time = now;
79  }
80  else if (msg->data == "end")
81  {
82  // assemble laser
83  assembleLaserScans(g_lidar_move_start_time, now);
84  g_lidar_move_start_time = now;
85  }
86 }
87 
88 int main(int argc, char** argv)
89 {
90  ros::init(argc, argv, "thor_lidar_assembler");
91  ros::NodeHandle nh;
92 
93  // Add your ros communications here.
94  g_lidar_turn_end_sub = nh.subscribe("/robotis/sensor/move_lidar", 1, &lidarTurnCallBack);
95  g_point_cloud2_pub = nh.advertise<sensor_msgs::PointCloud2>("/robotis/sensor/assembled_scan", 0);
96  g_assemble_chest_laser_client = nh.serviceClient<laser_assembler::AssembleScans2>("/robotis/sensor/service/assemble_scans2");
97 
98  g_lidar_move_start_time = ros::Time::now();
99 
100  ros::spin();
101 
102  return 0;
103 }
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void assembleLaserScans(ros::Time before_time, ros::Time end_time)
void lidarTurnCallBack(const std_msgs::String::ConstPtr &msg)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool call(MReq &req, MRes &res)
ros::Subscriber g_lidar_turn_end_sub
ros::ServiceClient g_assemble_chest_laser_client
ROSCPP_DECL void spin(Spinner &spinner)
#define ROS_INFO(...)
ros::Publisher g_point_cloud2_pub
pcl::PointXYZ PointT
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
static Time now()
ros::Subscriber g_lidar_turn_start_sub
int main(int argc, char **argv)
ros::Time g_lidar_move_start_time


thormang3_sensors
Author(s): Zerom , SCH , Kayman , Jay Song
autogenerated on Mon Jun 10 2019 15:39:38