sick_ldmrs_node.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015, DFKI GmbH
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of DFKI GmbH nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Created on: 20.11.2015
30  *
31  * Authors:
32  * Martin Günther <martin.guenther@dfki.de>
33  * Jochen Sprickerhof <jochen@sprickerhof.de>
34  *
35  * Modified and ported to ROS2: 02.10.2020 by Ing.-Buero Dr. Michael Lehning, Hildesheim
36  * Integrated into sick_scan2: 13.10.2020 by Ing.-Buero Dr. Michael Lehning, Hildesheim
37  */
38 #if defined LDMRS_SUPPORT && LDMRS_SUPPORT > 0
39 
41 
42 sick_scan_xd::SickLdmrsNode::SickLdmrsNode()
43 : m_nh(0), m_diagnostics(0), m_manager(0), m_app(0), m_ldmrs(0)
44 {
45 }
46 
47 sick_scan_xd::SickLdmrsNode::~SickLdmrsNode()
48 {
49  delete(m_manager);
50  delete(m_app);
51  delete(m_ldmrs);
52 }
53 
54 int sick_scan_xd::SickLdmrsNode::init(rosNodePtr nh, const std::string & hostName, const std::string & frameId)
55 {
56  m_nh = nh;
57 #if __ROS_VERSION == 1
58  m_diagnostics = std::make_shared<diagnostic_updater::Updater>(*m_nh);
59 #elif __ROS_VERSION == 2
60  m_diagnostics = std::make_shared<diagnostic_updater::Updater>(m_nh);
61 #endif
62 
63  // The MRS-App connects to an MRS, reads its configuration and receives all incoming data.
64  // First, create the manager object. The manager handles devices, collects
65  // device data and forwards it to the application(s).
66  ROS_INFO_STREAM("Creating the manager.");
67  m_manager = new Manager();
68 
69  // Add the application. As the devices may send configuration data only once
70  // at startup, the applications must be present before the devices are
71  // started.
72  // Sourcetype type;
73  ROS_INFO_STREAM("Adding the application SickLDMRS.");
74  std::string name = "Sick LDMRS ROS Driver App";
75  UINT16 id = 1356;
76 
77  m_app = new sick_ldmrs_driver::SickLDMRS(m_nh, m_manager, m_diagnostics);
78  m_app->setApplicationName(name);
79 
80  bool result = m_manager->addApplication(m_app, id);
81  if (result == false)
82  {
83  ROS_ERROR_STREAM("Failed to add application " << name << ", aborting!");
85  }
86  ROS_INFO_STREAM("Application is running.");
87 
88  //
89  // Add and run the sensor
90  //
91  // The MRS device could be configured like this:
92  // m_weWantScanData: true
93  // m_weWantObjectData: true
94  // m_weWantFieldData: false
95  // m_weWantScanDataFromSopas: false
96  ROS_INFO_STREAM("Adding the LDMRS device.");
97  m_ldmrs = new devices::LDMRS(m_manager);
98  m_ldmrs->setWeWantObjectData(true);
99  std::string hostname;
100  sick_ldmrs_driver::param<std::string>(m_nh, "hostname", hostname, "192.168.0.1");
101  ROS_INFO_STREAM("Set IP address to " << hostname);
102  m_ldmrs->setIpAddress(hostname);
103  name = "LDMRS-1";
104  id = 1;
105  result = m_manager->addAndRunDevice(m_ldmrs, name, id);
106  if (result == false)
107  {
108  ROS_ERROR_STREAM("Failed to add device " << name << ", aborting!");
110  }
111 
112  std::string serial_number = m_ldmrs->getSerialNumber();
113  if(m_diagnostics)
114  {
115  m_diagnostics->setHardwareID(serial_number);
116 #if __ROS_VERSION == 2
117  m_diagnostics->setPeriod(0.1); // publish diagnostic messages with 10 Hz, not available on ROS1
118 #endif
119  }
120 
121  ROS_INFO_STREAM("LD-MRS Firmware version is " << m_ldmrs->getFirmwareVersion());
122 
123  // we need to initialize the app after setting up the ldmrs device
124  m_app->init();
125 
126  ROS_INFO_STREAM("sick_ldmrs_driver is initialized.");
128 }
129 
131 {
132  rosSpin(m_nh);
134 }
135 
136 #endif // LDMRS_SUPPORT && LDMRS_SUPPORT > 0
UINT16
uint16_t UINT16
Definition: BasicDatatypes.hpp:73
roswrap::message_traits::frameId
std::string * frameId(M &m)
returns FrameId<M>::pointer(m);
Definition: message_traits.h:299
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
api.setup.name
name
Definition: python/api/setup.py:12
sick_scan_xd::ExitSuccess
@ ExitSuccess
Definition: abstract_parser.h:46
ros::NodeHandle
rosSpin
void rosSpin(rosNodePtr nh)
Definition: sick_ros_wrapper.h:207
sick_ldmrs_node.h
ROS_ERROR_STREAM
#define ROS_ERROR_STREAM(...)
Definition: sick_scan_ros2_example.cpp:72
sick_scan_xd::ExitError
@ ExitError
Definition: abstract_parser.h:47
sick_ldmrs_driver::SickLDMRS
Definition: sick_ldmrs_driver.hpp:101
sick_scansegment_xd::run
int run(rosNodePtr node, const std::string &scannerName)
Definition: scansegment_threads.cpp:74


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