psen_scan_driver.cpp
Go to the documentation of this file.
1 // Copyright (c) 2020-2021 Pilz GmbH & Co. KG
2 //
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU Lesser General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public License
14 // along with this program. If not, see <https://www.gnu.org/licenses/>.
15 
16 #include <functional>
17 #include <csignal>
18 #include <future>
19 #include <string>
20 
21 #include <ros/ros.h>
22 
28 
32 
35 
36 using namespace psen_scan_v2;
37 using namespace psen_scan_v2_standalone;
38 
39 std::function<void()> NODE_TERMINATE_CALLBACK;
40 
41 const std::string PARAM_HOST_IP{ "host_ip" };
42 const std::string PARAM_HOST_DATA_PORT{ "host_udp_port_data" };
43 const std::string PARAM_HOST_CONTROL_PORT{ "host_udp_port_control" };
44 const std::string PARAM_SCANNER_IP{ "sensor_ip" };
45 const std::string PARAM_TF_PREFIX{ "tf_prefix" };
46 const std::string PARAM_ANGLE_START{ "angle_start" };
47 const std::string PARAM_ANGLE_END{ "angle_end" };
48 const std::string PARAM_X_AXIS_ROTATION{ "x_axis_rotation" };
49 const std::string PARAM_FRAGMENTED_SCANS{ "fragmented_scans" };
50 const std::string PARAM_INTENSITIES{ "intensities" };
51 const std::string PARAM_RESOLUTION{ "resolution" };
52 
53 static const std::string DEFAULT_TF_PREFIX = "laser_1";
54 
56 static const std::string DEFAULT_PUBLISH_TOPIC = "scan";
57 
59 {
61 
62  // Delay the shutdown() to get full debug output. Workaround for https://github.com/ros/ros_comm/issues/688
63  ros::Duration(0.2).sleep(); // TODO check if we can get rid of this sleep
64 
65  ros::shutdown();
66 }
67 
68 int main(int argc, char** argv)
69 {
70  ros::init(argc, argv, "psen_scan_v2_node");
71  ros::NodeHandle pnh("~");
72 
73  std::signal(SIGINT, delayed_shutdown_sig_handler);
74 
75  try
76  {
78  getOptionalParamFromServer<double>(
81  getOptionalParamFromServer<double>(
83 
84  ScannerConfiguration scanner_configuration{
85  ScannerConfigurationBuilder(getRequiredParamFromServer<std::string>(pnh, PARAM_SCANNER_IP))
86  .hostIP(getOptionalParamFromServer<std::string>(pnh, PARAM_HOST_IP, configuration::DEFAULT_HOST_IP_STRING))
87  .hostDataPort(
88  getOptionalParamFromServer<int>(pnh, PARAM_HOST_DATA_PORT, configuration::DATA_PORT_OF_HOST_DEVICE))
90  getOptionalParamFromServer<int>(pnh, PARAM_HOST_CONTROL_PORT, configuration::CONTROL_PORT_OF_HOST_DEVICE))
93  .scanRange(scan_range)
96  getOptionalParamFromServer<bool>(pnh, PARAM_FRAGMENTED_SCANS, configuration::FRAGMENTED_SCANS))
97  .enableIntensities(getOptionalParamFromServer<bool>(pnh, PARAM_INTENSITIES, configuration::INTENSITIES))
99  getOptionalParamFromServer<double>(pnh, PARAM_RESOLUTION, configuration::DEFAULT_SCAN_ANGLE_RESOLUTION)))
100  .build()
101  };
102 
103  if (scanner_configuration.fragmentedScansEnabled())
104  {
105  ROS_INFO("Using fragmented scans.");
106  }
107 
108  ROSScannerNode ros_scanner_node(pnh,
110  getOptionalParamFromServer<std::string>(pnh, PARAM_TF_PREFIX, DEFAULT_TF_PREFIX),
112  scanner_configuration);
113 
114  NODE_TERMINATE_CALLBACK = std::bind(&ROSScannerNode::terminate, &ros_scanner_node);
115 
116  ros_scanner_node.run();
117  }
118  catch (std::exception& e)
119  {
120  // The line below is needed since ROS_ERROR won't probably work during shutdown
121  std::cerr << "\x1B[91m" << e.what() << "\033[0m\n";
122  ROS_ERROR_STREAM(e.what());
123  return 1;
124  }
125 
126  return 0;
127 }
static constexpr unsigned short DATA_PORT_OF_HOST_DEVICE
ScannerConfigurationBuilder & hostIP(const std::string &host_ip)
REGISTER_ROSCONSOLE_BRIDGE
ROS Node that continuously publishes scan data of a single PSENscan laser scanner.
const std::string PARAM_ANGLE_END
const std::string PARAM_ANGLE_START
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
static TenthOfDegree fromRad(const double &angle_in_rad)
static constexpr double DEFAULT_SCAN_ANGLE_RESOLUTION(data_conversion_layer::degreeToRadian(0.1))
std::function< void()> NODE_TERMINATE_CALLBACK
Contains the events needed to define and implement the scanner protocol.
ScannerConfigurationBuilder & enableDiagnostics(const bool &enable)
static constexpr double DEFAULT_ANGLE_START(-data_conversion_layer::degreeToRadian(137.4))
Start angle of measurement.
static const std::string DEFAULT_TF_PREFIX
ScannerConfigurationBuilder & hostDataPort(const int &host_data_port)
static constexpr unsigned short CONTROL_PORT_OF_HOST_DEVICE
Higher level data type storing the configuration details of the scanner like scanner IP...
static constexpr double DEFAULT_X_AXIS_ROTATION
The 2D scan will be rotated around the z-axis.
const std::string PARAM_HOST_IP
static constexpr unsigned short CONTROL_PORT_OF_SCANNER_DEVICE
void terminate()
Terminates the fetching and publishing of scanner data.
ScannerConfigurationBuilder & scannerControlPort(const int &scanner_control_port)
void run()
Continuously fetches data from the scanner and publishes the data into the ROS network.
#define ROS_INFO(...)
Root namespace in which the software components to communicate with the scanner (firmware-version: 2)...
Definition: udp_client.h:41
Higher level data type storing the range in which the scanner takes measurements. ...
Definition: scan_range.h:31
const std::string PARAM_TF_PREFIX
Root namespace for the ROS part.
ScannerConfigurationBuilder & hostControlPort(const int &host_control_port)
ScannerConfigurationBuilder & scannerDataPort(const int &scanner_data_port)
void delayed_shutdown_sig_handler(int sig)
static const std::string DEFAULT_HOST_IP_STRING
ScannerConfigurationBuilder & enableIntensities(const bool &enable)
static constexpr double DEFAULT_ANGLE_END(data_conversion_layer::degreeToRadian(137.4))
End angle of measurement.
Helper class to simplify/improve the construction of the psen_scan_v2_standalone::ScannerConfiguratio...
static const std::string DEFAULT_PUBLISH_TOPIC
Topic on which the LaserScan data are published.
const std::string PARAM_X_AXIS_ROTATION
const std::string PARAM_RESOLUTION
const std::string PARAM_HOST_DATA_PORT
ScannerConfigurationBuilder & scanRange(const ScanRange &scan_range)
ROSCPP_DECL void shutdown()
int main(int argc, char **argv)
const std::string PARAM_FRAGMENTED_SCANS
bool sleep() const
#define ROS_ERROR_STREAM(args)
ScannerConfigurationBuilder & scanResolution(const util::TenthOfDegree &scan_resolution)
static constexpr unsigned short DATA_PORT_OF_SCANNER_DEVICE
const std::string PARAM_SCANNER_IP
const std::string PARAM_HOST_CONTROL_PORT
const std::string PARAM_INTENSITIES
ScannerConfigurationBuilder & enableFragmentedScans(const bool &enable)


psen_scan_v2
Author(s): Pilz GmbH + Co. KG
autogenerated on Sat Nov 5 2022 02:13:36