tools/test_server/src/test_server.cpp
Go to the documentation of this file.
1 /*
2  * @brief sick_scan2 test_server implements a simple tcp server,
3  * simulating a lidar device for unittests.
4  *
5  * Note: sick_scan2 test_server does not implement the functions of lidar sensor,
6  * it just implements a simple tcp server, accepting tcp connections from clients
7  * and generating telegrams to test the sick_scan2 ros drivers.
8  *
9  * Copyright (C) 2020 Ing.-Buero Dr. Michael Lehning, Hildesheim
10  * Copyright (C) 2020 SICK AG, Waldkirch
11  *
12  * Licensed under the Apache License, Version 2.0 (the "License");
13  * you may not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  * http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  *
24  * All rights reserved.
25  *
26  * Redistribution and use in source and binary forms, with or without
27  * modification, are permitted provided that the following conditions are met:
28  *
29  * * Redistributions of source code must retain the above copyright
30  * notice, this list of conditions and the following disclaimer.
31  * * Redistributions in binary form must reproduce the above copyright
32  * notice, this list of conditions and the following disclaimer in the
33  * documentation and/or other materials provided with the distribution.
34  * * Neither the name of SICK AG nor the names of its
35  * contributors may be used to endorse or promote products derived from
36  * this software without specific prior written permission
37  * * Neither the name of Ing.-Buero Dr. Michael Lehning nor the names of its
38  * contributors may be used to endorse or promote products derived from
39  * this software without specific prior written permission
40  *
41  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
42  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
45  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
46  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
47  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
48  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
49  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
51  * POSSIBILITY OF SUCH DAMAGE.
52  *
53  * Authors:
54  * Michael Lehning <michael.lehning@lehning.de>
55  *
56  * Copyright 2020 SICK AG
57  * Copyright 2020 Ing.-Buero Dr. Michael Lehning
58  *
59  */
60 #include <signal.h>
64 
65 int main(int argc, char** argv)
66 {
67  // Ros configuration and initialization, pass command line arguments to rclcpp.
68 #if defined __ROS_VERSION && __ROS_VERSION == 2
69  rclcpp::init(argc, argv);
70  rclcpp::NodeOptions node_options;
71  node_options.allow_undeclared_parameters(true);
72  rclcpp::Node::SharedPtr node = rclcpp::Node::make_shared("sick_test_server", "", node_options);
73 #else
74  ros::init(argc, argv, "sick_test_server", ros::init_options::NoSigintHandler); // scannerName holds the node-name
75  signal(SIGINT, rosSignalHandler);
76  ros::NodeHandle nh("~");
77  rosNodePtr node = &nh;
78 #endif
79 
80  if(!parseLaunchfileSetParameter(node, argc, argv))
81  {
82  ROS_ERROR_STREAM("## ERROR sick_test_server: parseLaunchfileSetParameter() failed, aborting\n");
83  exit(-1);
84  }
85 
86  std::string scanner_name = "undefined";
87  int port = 2112;
88  double send_scan_data_rate = 1/20.0; // frequency to generate and send scan data (default: 20 Hz)
89  rosDeclareParam(node, "scanner_name", scanner_name);
90  rosDeclareParam(node, "port", port);
91  rosDeclareParam(node, "send_scan_data_rate", send_scan_data_rate);
92  rosGetParam(node, "scanner_name", scanner_name);
93  rosGetParam(node, "port", port);
94  rosGetParam(node, "send_scan_data_rate", send_scan_data_rate);
95  ROS_INFO_STREAM("sick_scan_test_server started, simulating scanner type \"" << scanner_name << "\" on tcp port " << port);
96 
97  // Start a tcp test server to simulate a lidar device
98  sick_scan_xd::test::TestServerThread test_server_thread(node, scanner_name, port);
99  test_server_thread.start();
100 
101  // Run ros event loop
102  ROS_INFO("sick_scan_test_server is running event loop");
103  rosSpin(node);
104  // Cleanup and exit
105  ROS_INFO("sick_scan_test_server finished.");
106  test_server_thread.stop();
107  ROS_INFO("sick_scan_test_server exits.");
108  return 0;
109 }
sick_scan_xd::test::TestServerThread
Definition: tools/test_server/include/sick_scan/test_server/test_server_thread.h:83
sick_generic_laser.h
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
alternate ROS initialization function.
sick_scan_xd::test::TestServerThread::start
virtual bool start(void)
Definition: tools/test_server/src/test_server_thread.cpp:98
sick_ros_wrapper.h
roswrap::param::init
void init(const M_string &remappings)
Definition: param_modi.cpp:809
ROS_INFO_STREAM
#define ROS_INFO_STREAM(...)
Definition: sick_scan_ros2_example.cpp:71
polar_to_cartesian_pointcloud_ros1.node
node
Definition: polar_to_cartesian_pointcloud_ros1.py:81
sick_scan_xd::test::TestServerThread::stop
virtual bool stop(void)
Definition: tools/test_server/src/test_server_thread.cpp:109
ros::NodeHandle
test_server_thread.h
rosGetParam
bool rosGetParam(rosNodePtr nh, const std::string &param_name, T &param_value)
Definition: sick_ros_wrapper.h:167
ROS_INFO
#define ROS_INFO(...)
Definition: sick_scan_logging.h:117
rosSpin
void rosSpin(rosNodePtr nh)
Definition: sick_ros_wrapper.h:207
main
int main(int argc, char **argv)
Definition: tools/test_server/src/test_server.cpp:65
ROS_ERROR_STREAM
#define ROS_ERROR_STREAM(...)
Definition: sick_scan_ros2_example.cpp:72
parseLaunchfileSetParameter
bool parseLaunchfileSetParameter(rosNodePtr nhPriv, int argc, char **argv)
Parses an optional launchfile and sets all parameters. This function is used at startup to enable sys...
Definition: sick_generic_laser.cpp:352
rosDeclareParam
void rosDeclareParam(rosNodePtr nh, const std::string &param_name, const T &param_value)
Definition: sick_ros_wrapper.h:166
ros::init_options::NoSigintHandler
NoSigintHandler
rosSignalHandler
void rosSignalHandler(int signalRecv)
Definition: sick_generic_laser.cpp:211
ros::NodeHandle


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