lidar3d_multiscan_recv.cpp
Go to the documentation of this file.
1 /*
2  * @brief lidar3d_multiscan_recv implements a ROS node to receive and publish data from the new sick 3D lidar multiScan136.
3  *
4  * Copyright (C) 2020 Ing.-Buero Dr. Michael Lehning, Hildesheim
5  * Copyright (C) 2020 SICK AG, Waldkirch
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * All rights reserved.
20  *
21  * Redistribution and use in source and binary forms, with or without
22  * modification, are permitted provided that the following conditions are met:
23  *
24  * * Redistributions of source code must retain the above copyright
25  * notice, this list of conditions and the following disclaimer.
26  * * Redistributions in binary form must reproduce the above copyright
27  * notice, this list of conditions and the following disclaimer in the
28  * documentation and/or other materials provided with the distribution.
29  * * Neither the name of SICK AG nor the names of its
30  * contributors may be used to endorse or promote products derived from
31  * this software without specific prior written permission
32  * * Neither the name of Ing.-Buero Dr. Michael Lehning nor the names of its
33  * contributors may be used to endorse or promote products derived from
34  * this software without specific prior written permission
35  *
36  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
37  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
39  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
40  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
41  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
42  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
43  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
44  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
46  * POSSIBILITY OF SUCH DAMAGE.
47  *
48  * Authors:
49  * Michael Lehning <michael.lehning@lehning.de>
50  *
51  * Copyright 2020 SICK AG
52  * Copyright 2020 Ing.-Buero Dr. Michael Lehning
53  *
54  */
56 #include "sick_scansegment_xd/scansegement_threads.h"
57 
58 /*
59  * main runs lidar3d_multiscan_recv:
60  * - Initialize udp receiver, msgpack converter and ros publisher,
61  * - Run threads to receive, convert, export and publish msgpack data,
62  * - Optionally save to csv-file,
63  * - Optionally read and convert msgpack files,
64  * - Report cpu times and possible data lost.
65  */
66 int main(int argc, char** argv)
67 {
68  // Configuration
70  if (!config.Init(argc, argv))
71  ROS_ERROR_STREAM("## ERROR lidar3d_multiscan_recv: Config::Init() failed, using default values.");
72  ROS_INFO_STREAM("lidar3d_multiscan_recv started.");
73 
75  if(!msgpack_threads.start(config))
76  {
77  ROS_ERROR_STREAM("## ERROR lidar3d_multiscan_recv: sick_scansegment_xd::MsgPackThreads::start() failed");
78  }
79 
80  // Run event loop
81 #if defined __ROS_VERSION && __ROS_VERSION > 1
82  rclcpp::spin(config.node);
83  ROS_INFO_STREAM("lidar3d_multiscan_recv finishing, ros shutdown.");
84 #elif defined __ROS_VERSION && __ROS_VERSION > 0
85  ros::spin();
86  ROS_INFO_STREAM("lidar3d_multiscan_recv finishing, ros shutdown.");
87 #else // Run background task until ENTER key pressed
88  while(true)
89  {
90  std::this_thread::sleep_for(std::chrono::seconds(1));
91  int c;
92  if (KBHIT() && ((c = GETCH()) == 27 || c == 'q' || c == 'Q'))
93  {
94  ROS_INFO_STREAM("lidar3d_multiscan_recv: key " << c << " pressed, aborting...");
95  break;
96  }
97  }
98 #endif
99  rosShutdown();
100 
101  if(!msgpack_threads.stop())
102  {
103  ROS_ERROR_STREAM("## ERROR lidar3d_multiscan_recv: sick_scansegment_xd::MsgPackThreads::stop() failed");
104  }
105  ROS_INFO_STREAM("lidar3d_multiscan_recv finished.");
106  return 0;
107 }
sick_scansegment_xd::MsgPackThreads::stop
bool stop(bool do_join)
Definition: scansegment_threads.cpp:143
roswrap::spin
ROSCPP_DECL void spin()
Enter simple event loop.
Definition: rossimu.cpp:260
KBHIT
#define KBHIT()
Definition: include/sick_scansegment_xd/common.h:86
sick_ros_wrapper.h
ROS_INFO_STREAM
#define ROS_INFO_STREAM(...)
Definition: sick_scan_ros2_example.cpp:71
GETCH
#define GETCH()
Definition: include/sick_scansegment_xd/common.h:87
sick_scansegment_xd::MsgPackThreads::start
bool start(const sick_scansegment_xd::Config &config)
Definition: scansegment_threads.cpp:132
main
int main(int argc, char **argv)
Definition: lidar3d_multiscan_recv.cpp:66
sick_scansegment_xd::Config
Definition: config.h:84
rosShutdown
void rosShutdown(void)
Definition: sick_ros_wrapper.h:209
sick_scan_xd_api_test.c
c
Definition: sick_scan_xd_api_test.py:445
sick_scansegment_xd::MsgPackThreads
Definition: scansegment_threads.h:76
ROS::seconds
double seconds(ROS::Duration duration)
Definition: ros_wrapper.cpp:180
ros::spin
ROSCPP_DECL void spin()
Enter simple event loop.
Definition: rossimu.cpp:260
ROS_ERROR_STREAM
#define ROS_ERROR_STREAM(...)
Definition: sick_scan_ros2_example.cpp:72
config
config


sick_scan_xd
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Fri Oct 25 2024 02:47:08