msgpack_exporter.h
Go to the documentation of this file.
1 #include "sick_scan/sick_scan_base.h" /* Base definitions included in all header files, added by add_sick_scan_base_header.py. Do not edit this line. */
2 /*
3  * @brief msgpack_exporter runs a background thread to consume and export msgpack data from the sick 3D lidar multiScan136
4  * to optionally csv file or plotted diagram
5  *
6  * Copyright (C) 2020 Ing.-Buero Dr. Michael Lehning, Hildesheim
7  * Copyright (C) 2020 SICK AG, Waldkirch
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * All rights reserved.
22  *
23  * Redistribution and use in source and binary forms, with or without
24  * modification, are permitted provided that the following conditions are met:
25  *
26  * * Redistributions of source code must retain the above copyright
27  * notice, this list of conditions and the following disclaimer.
28  * * Redistributions in binary form must reproduce the above copyright
29  * notice, this list of conditions and the following disclaimer in the
30  * documentation and/or other materials provided with the distribution.
31  * * Neither the name of SICK AG nor the names of its
32  * contributors may be used to endorse or promote products derived from
33  * this software without specific prior written permission
34  * * Neither the name of Ing.-Buero Dr. Michael Lehning 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  *
38  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
39  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
41  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
42  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
43  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
44  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
45  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
46  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
47  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
48  * POSSIBILITY OF SUCH DAMAGE.
49  *
50  * Authors:
51  * Michael Lehning <michael.lehning@lehning.de>
52  *
53  * Copyright 2020 SICK AG
54  * Copyright 2020 Ing.-Buero Dr. Michael Lehning
55  *
56  */
57 #ifndef __SICK_SCANSEGMENT_XD_MSGPACK_EXPORTER_H
58 #define __SICK_SCANSEGMENT_XD_MSGPACK_EXPORTER_H
59 
64 
65 namespace sick_scansegment_xd
66 {
67  /*
68  * @brief class MsgPackExportListenerIF is an interface to listen to exported msgpack data.
69  * Instances implementing the interface MsgPackExportListenerIF can be added to a MsgPackExporter
70  * and will be notified whenever msgpack data have been received, successfully converted and
71  * are ready to publish (or any other possible action with msgpack data)
72  */
74  {
75  public:
76  /*
77  * Callback function of MsgPackExportListenerIF. HandleMsgPackData() will be called in MsgPackExporter
78  * for each registered listener after msgpack data have been received and converted.
79  */
80  virtual void HandleMsgPackData(const sick_scansegment_xd::ScanSegmentParserOutput& msgpack_data) = 0;
81  };
82 
83  /*
84  * @brief class MsgPackExporter runs a background thread to consume and export msgpack data from the sick 3D lidar multiScan136
85  * to optionally csv file or plotted diagram
86  */
88  {
89  public:
90 
91  /*
92  * @brief Default constructor.
93  */
95 
96  /*
97  * @brief Initializing constructor
98  * @param[in] udp_fifo fifo buffering udp packages (for informational messages only)
99  * @param[in] msgpack_fifo fifo buffering ScanSegmentParserOutput data from multiScan136 (for csv export and visualization)
100  * @param[in] logfolder output folder for optional csv-files
101  * @param[in] export_csv true: export ScanSegmentParserOutput data to csv files
102  * @param[in] verbose true: enable debug output, false: quiet mode (default)
103  * @param[in] measure_timing true: duration and latency of msgpack conversion and export is measured, default: false
104  */
105  MsgPackExporter(sick_scansegment_xd::PayloadFifo* udp_fifo, sick_scansegment_xd::Fifo<ScanSegmentParserOutput>* msgpack_fifo, const std::string& logfolder, bool export_csv, bool verbose = false, bool measure_timing = false);
106 
107  /*
108  * @brief Default destructor.
109  */
111 
112  /*
113  * @brief Starts a background thread to pops msgpack data packages from the input fifo and optionally export them to csv and/or plot the lidar points.
114  */
115  bool Start(void);
116 
117  /*
118  * @brief Stops the background thread
119  */
120  void Stop(void);
121 
122  /*
123  * @brief Stops, joins and deletes the background thread
124  */
125  void Close(void);
126 
127  /*
128  * @brief Registers a listener to msgpack export data. MsgPackExporter will notify registered listeners
129  * whenever msgpack data have been received and successfully converted by calling listener->HandleMsgPackData().
130  */
132 
133  /*
134  * @brief Removes a registered listener.
135  */
137 
138  protected:
139 
140  /*
141  * @brief Plots lidar points (x, y, z) and intensity i using matplotlib via Python-API
142  */
143  static void PlotXYZI(const std::vector<float>& x, const std::vector<float>& y, const std::vector<float>& z, const std::vector<int>& i);
144 
145  /*
146  * @brief Thread callback, runs the exporter. Pops msgpack data packages from the input fifo and optionally export them to csv and/or plot the lidar points.
147  */
148  bool RunCb(void);
149 
150  /*
151  * @brief Returns the list of registered listeners
152  */
153  std::list<sick_scansegment_xd::MsgPackExportListenerIF*> GetExportListener();
154 
155  /*
156  * Configuration and parameter
157  */
158  std::string m_logfolder; // output folder for optional csv-files
159  bool m_export_csv; // true: export ScanSegmentParserOutput data to csv files
160  bool m_verbose; // true: enable debug output, false: quiet mode (default)
161  bool m_measure_timing; // true: duration and latency of msgpack conversion and export is measured, default: false
162 
163  /*
164  * Member data to run the exporter
165  */
166  sick_scansegment_xd::PayloadFifo* m_udp_fifo; // fifo buffering udp packages (for informational messages only)
167  sick_scansegment_xd::Fifo<ScanSegmentParserOutput>* m_msgpack_fifo; // input fifo buffering ScanSegmentParserOutput data from multiScan136 (for csv export and visualization)
168  std::thread* m_exporter_thread; // background thread to export ScanSegmentParserOutput data
169  bool m_run_exporter_thread; // flag to start and stop the exporter thread
170  std::list< sick_scansegment_xd::MsgPackExportListenerIF*> m_listener; // list of export listener, which will be notified calling listener->HandleMsgPackData() after successful conversion of received msgpack data
171  std::mutex m_listener_mutex; // mutex to protect m_listener access
172 
173 
174  }; // class MsgPackExporter
175 
176 } // namespace sick_scansegment_xd
177 #endif // __SICK_SCANSEGMENT_XD_MSGPACK_EXPORTER_H
common.h
sick_scansegment_xd::PayloadFifo
Definition: fifo.h:187
sick_scansegment_xd::MsgPackExporter::~MsgPackExporter
~MsgPackExporter()
Definition: msgpack_exporter.cpp:83
sick_scansegment_xd
Definition: include/sick_scansegment_xd/common.h:138
sick_scansegment_xd::MsgPackExporter::m_listener_mutex
std::mutex m_listener_mutex
Definition: msgpack_exporter.h:171
sick_scansegment_xd::MsgPackExporter::PlotXYZI
static void PlotXYZI(const std::vector< float > &x, const std::vector< float > &y, const std::vector< float > &z, const std::vector< int > &i)
sick_scansegment_xd::MsgPackExporter::m_msgpack_fifo
sick_scansegment_xd::Fifo< ScanSegmentParserOutput > * m_msgpack_fifo
Definition: msgpack_exporter.h:167
fifo.h
sick_scansegment_xd::MsgPackExporter::m_logfolder
std::string m_logfolder
Definition: msgpack_exporter.h:158
sick_scansegment_xd::MsgPackExporter::AddExportListener
void AddExportListener(sick_scansegment_xd::MsgPackExportListenerIF *listener)
Definition: msgpack_exporter.cpp:92
sick_scansegment_xd::MsgPackExportListenerIF::HandleMsgPackData
virtual void HandleMsgPackData(const sick_scansegment_xd::ScanSegmentParserOutput &msgpack_data)=0
sick_ros_wrapper.h
multiscan_pcap_player.verbose
int verbose
Definition: multiscan_pcap_player.py:142
sick_scansegment_xd::MsgPackExporter::m_measure_timing
bool m_measure_timing
Definition: msgpack_exporter.h:161
sick_scansegment_xd::MsgPackExporter::Start
bool Start(void)
Definition: msgpack_exporter.cpp:127
sick_scansegment_xd::MsgPackExporter::m_listener
std::list< sick_scansegment_xd::MsgPackExportListenerIF * > m_listener
Definition: msgpack_exporter.h:170
sick_scansegment_xd::ScanSegmentParserOutput
Definition: scansegment_parser_output.h:118
sick_scansegment_xd::MsgPackExporter::m_export_csv
bool m_export_csv
Definition: msgpack_exporter.h:159
msgpack_parser.h
sick_scansegment_xd::Fifo
Definition: fifo.h:75
sick_scansegment_xd::MsgPackExporter::m_exporter_thread
std::thread * m_exporter_thread
Definition: msgpack_exporter.h:168
sick_scansegment_xd::MsgPackExporter::RemoveExportListener
void RemoveExportListener(sick_scansegment_xd::MsgPackExportListenerIF *listener)
Definition: msgpack_exporter.cpp:101
sick_scansegment_xd::MsgPackExporter
Definition: msgpack_exporter.h:87
sick_scansegment_xd::MsgPackExporter::GetExportListener
std::list< sick_scansegment_xd::MsgPackExportListenerIF * > GetExportListener()
Definition: msgpack_exporter.cpp:116
sick_scansegment_xd::MsgPackExporter::RunCb
bool RunCb(void)
Definition: msgpack_exporter.cpp:160
sick_scansegment_xd::MsgPackExporter::m_run_exporter_thread
bool m_run_exporter_thread
Definition: msgpack_exporter.h:169
sick_scansegment_xd::MsgPackExporter::Stop
void Stop(void)
Definition: msgpack_exporter.cpp:137
sick_scansegment_xd::MsgPackExportListenerIF
Definition: msgpack_exporter.h:73
sick_scansegment_xd::MsgPackExporter::Close
void Close(void)
Definition: msgpack_exporter.cpp:145
sick_scan_base.h
sick_scansegment_xd::MsgPackExporter::m_verbose
bool m_verbose
Definition: msgpack_exporter.h:160
sick_scansegment_xd::MsgPackExporter::MsgPackExporter
MsgPackExporter()
Definition: msgpack_exporter.cpp:62
sick_scansegment_xd::MsgPackExporter::m_udp_fifo
sick_scansegment_xd::PayloadFifo * m_udp_fifo
Definition: msgpack_exporter.h:166


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