msgpack_converter.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_converter runs a background thread to unpack and parses msgpack data for the sick 3D lidar multiScan136.
4  * msgpack_converter pops binary msgpack data from an input fifo, converts the data to scanlines using MsgPackParser::Parse()
5  * and pushes the ScanSegmentParserOutput to an output fifo.
6  *
7  * Usage example:
8  *
9  * sick_scansegment_xd::UdpReceiver udp_receiver;
10  * udp_receiver.Init("127.0.0.1", 2115, -1, true);
11  * sick_scansegment_xd::MsgPackConverter msgpack_converter(udp_receiver.Fifo(), -1, true);
12  * msgpack_converter.Start()
13  * udp_receiver.Start();
14  *
15  * Copyright (C) 2020 Ing.-Buero Dr. Michael Lehning, Hildesheim
16  * Copyright (C) 2020 SICK AG, Waldkirch
17  *
18  * Licensed under the Apache License, Version 2.0 (the "License");
19  * you may not use this file except in compliance with the License.
20  * You may obtain a copy of the License at
21  *
22  * http://www.apache.org/licenses/LICENSE-2.0
23  *
24  * Unless required by applicable law or agreed to in writing, software
25  * distributed under the License is distributed on an "AS IS" BASIS,
26  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27  * See the License for the specific language governing permissions and
28  * limitations under the License.
29  *
30  * All rights reserved.
31  *
32  * Redistribution and use in source and binary forms, with or without
33  * modification, are permitted provided that the following conditions are met:
34  *
35  * * Redistributions of source code must retain the above copyright
36  * notice, this list of conditions and the following disclaimer.
37  * * Redistributions in binary form must reproduce the above copyright
38  * notice, this list of conditions and the following disclaimer in the
39  * documentation and/or other materials provided with the distribution.
40  * * Neither the name of SICK AG nor the names of its
41  * contributors may be used to endorse or promote products derived from
42  * this software without specific prior written permission
43  * * Neither the name of Ing.-Buero Dr. Michael Lehning nor the names of its
44  * contributors may be used to endorse or promote products derived from
45  * this software without specific prior written permission
46  *
47  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
48  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
51  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
52  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
53  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
54  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
55  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
56  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
57  * POSSIBILITY OF SUCH DAMAGE.
58  *
59  * Authors:
60  * Michael Lehning <michael.lehning@lehning.de>
61  *
62  * Copyright 2020 SICK AG
63  * Copyright 2020 Ing.-Buero Dr. Michael Lehning
64  *
65  */
66 #ifndef __SICK_SCANSEGMENT_XD_MSGPACK_CONVERTER_H
67 #define __SICK_SCANSEGMENT_XD_MSGPACK_CONVERTER_H
68 
76 
77 namespace sick_scansegment_xd
78 {
79  /*
80  * @brief class MsgPackConverter runs a background thread to unpack and parses msgpack data for the sick 3D lidar multiScan136.
81  * msgpack_converter pops binary msgpack data from an input fifo, converts the data to scanlines using MsgPackParser::Parse()
82  * and pushes the ScanSegmentParserOutput to an output fifo.
83  */
85  {
86  public:
87 
88  /*
89  * @brief Default constructor.
90  */
92 
93  /*
94  * @brief Initializing constructor
95  * @param[in] parser_config configuration and settings for multiScan and picoScan parser
96  * @param[in] add_transform_xyz_rpy Apply an additional transform to the cartesian pointcloud, default: "0,0,0,0,0,0" (i.e. no transform)
97  * @param[in] input_fifo input fifo buffering udp packages
98  * @param[in] scandataformat ScanDataFormat: 1 for msgpack or 2 for compact scandata, default: 2
99  * @param[in] msgpack_output_fifolength max. output fifo length (-1: unlimited, default: 20 for buffering 1 second at 20 Hz), elements will be removed from front if number of elements exceeds the fifo_length
100  * @param[in] verbose true: enable debug output, false: quiet mode (default)
101  */
102  MsgPackConverter(const ScanSegmentParserConfig& parser_config, const sick_scan_xd::SickCloudTransform& add_transform_xyz_rpy, sick_scansegment_xd::PayloadFifo* input_fifo, int scandataformat = 2, int msgpack_output_fifolength = 20, bool verbose = false);
103 
104  /*
105  * @brief Default destructor.
106  */
108 
109  /*
110  * @brief Starts a background thread, pops msgpack data packages from input fifo, converts them
111  * and pushes ScanSegmentParserOutput data to the output fifo.
112  */
113  bool Start(void);
114 
115  /*
116  * @brief Stops the converter thread
117  */
118  void Close(void);
119 
120  /*
121  * @brief Configures msgpack validation, see MsgPackValidator for details
122  * @param[in] msgpack_validator the msgpack validator
123  * @param[in] msgpack_validator_enabled true: check msgpack data for out of bounds and missing scan data, false: no msgpack validation
124  * @param[in] discard_msgpacks_not_validated true: msgpacks are discarded if scan data out of bounds detected, false: error message if a msgpack is not validated
125  * @param[in] msgpack_validator_check_missing_scandata_interval check msgpack for missing scandata after collecting N msgpacks, default: N = 12 segments. Increase this value to tolerate udp packet drops. Use 12 to check each full scan.
126  */
127  void SetValidator(sick_scansegment_xd::MsgPackValidator& msgpack_validator, bool msgpack_validator_enabled, bool discard_msgpacks_not_validated, int msgpack_validator_check_missing_scandata_interval);
128 
129  /*
130  * @brief Returns the output fifo storing the multiScan136 scanlines.
131  */
133 
134  protected:
135 
136  /*
137  * @brief Thread callback, runs the converter. Pops msgpack data from the input fifo, converts them und pushes ScanSegmentParserOutput data to the output fifo.
138  */
139  bool Run(void);
140 
141  /*
142  * Configuration and parameter
143  */
144  bool m_verbose; // true: enable debug output, false: quiet mode (default)
145  ScanSegmentParserConfig m_parser_config; // configuration and settings for multiScan and picoScan parser
146 
147  /*
148  * Member data to run the converter
149  */
150  PayloadFifo* m_input_fifo; // input fifo for msgpack data
151  int m_scandataformat; // ScanDataFormat: 1 for msgpack or 2 for compact scandata, default: 1
152  sick_scansegment_xd::Fifo<ScanSegmentParserOutput>* m_output_fifo; // output fifo for ScanSegmentParserOutput data converted from msgpack data
153  std::thread* m_converter_thread; // background thread to convert msgpack to ScanSegmentParserOutput data
154  bool m_run_converter_thread; // flag to start and stop the udp converter thread
155  bool m_msgpack_validator_enabled; // true: check msgpack data for out of bounds and missing scan data, false: no msgpack validation
156  sick_scansegment_xd::MsgPackValidator m_msgpack_validator; // msgpack validation, see MsgPackValidator for details
157  bool m_discard_msgpacks_not_validated; // true: msgpacks are discarded if scan data out of bounds detected, false: error message if a msgpack is not validated
158  int m_msgpack_validator_check_missing_scandata_interval; // check msgpack for missing scandata after collecting N msgpacks, default: N = 12 segments. Increase this value to tolerate udp packet drops. Use 12 to check each full scan.
159  sick_scan_xd::SickCloudTransform m_add_transform_xyz_rpy; // Apply an additional transform to the cartesian pointcloud, default: "0,0,0,0,0,0" (i.e. no transform)
160  }; // class MsgPackConverter
161 
162 } // namespace sick_scansegment_xd
163 #endif // __SICK_SCANSEGMENT_XD_MSGPACK_CONVERTER_H
common.h
sick_scansegment_xd::PayloadFifo
Definition: fifo.h:187
sick_cloud_transform.h
sick_scansegment_xd::MsgPackConverter::m_converter_thread
std::thread * m_converter_thread
Definition: msgpack_converter.h:153
sick_scan_xd::SickCloudTransform
Definition: sick_cloud_transform.h:85
sick_scansegment_xd
Definition: include/sick_scansegment_xd/common.h:138
fifo.h
sick_scansegment_xd::MsgPackConverter::SetValidator
void SetValidator(sick_scansegment_xd::MsgPackValidator &msgpack_validator, bool msgpack_validator_enabled, bool discard_msgpacks_not_validated, int msgpack_validator_check_missing_scandata_interval)
Definition: msgpack_converter.cpp:144
sick_scansegment_xd::MsgPackConverter::~MsgPackConverter
~MsgPackConverter()
Definition: msgpack_converter.cpp:97
sick_scansegment_xd::MsgPackConverter::m_output_fifo
sick_scansegment_xd::Fifo< ScanSegmentParserOutput > * m_output_fifo
Definition: msgpack_converter.h:152
sick_scansegment_xd::MsgPackConverter::m_msgpack_validator
sick_scansegment_xd::MsgPackValidator m_msgpack_validator
Definition: msgpack_converter.h:156
sick_scansegment_xd::MsgPackConverter::m_run_converter_thread
bool m_run_converter_thread
Definition: msgpack_converter.h:154
sick_range_filter.h
sick_ros_wrapper.h
multiscan_pcap_player.verbose
int verbose
Definition: multiscan_pcap_player.py:142
sick_scansegment_xd::MsgPackConverter::m_msgpack_validator_enabled
bool m_msgpack_validator_enabled
Definition: msgpack_converter.h:155
msgpack_parser.h
msgpack_validator.h
sick_scansegment_xd::MsgPackConverter::m_add_transform_xyz_rpy
sick_scan_xd::SickCloudTransform m_add_transform_xyz_rpy
Definition: msgpack_converter.h:159
sick_scansegment_xd::MsgPackConverter::Fifo
sick_scansegment_xd::Fifo< ScanSegmentParserOutput > * Fifo(void)
Definition: msgpack_converter.h:132
sick_scansegment_xd::Fifo
Definition: fifo.h:75
sick_scansegment_xd::MsgPackConverter::MsgPackConverter
MsgPackConverter()
Definition: msgpack_converter.cpp:73
sick_scansegment_xd::MsgPackConverter::m_verbose
bool m_verbose
Definition: msgpack_converter.h:144
sick_scansegment_xd::MsgPackConverter::m_input_fifo
PayloadFifo * m_input_fifo
Definition: msgpack_converter.h:150
sick_scansegment_xd::MsgPackConverter::m_discard_msgpacks_not_validated
bool m_discard_msgpacks_not_validated
Definition: msgpack_converter.h:157
sick_scansegment_xd::MsgPackConverter::m_parser_config
ScanSegmentParserConfig m_parser_config
Definition: msgpack_converter.h:145
sick_scansegment_xd::MsgPackConverter::m_scandataformat
int m_scandataformat
Definition: msgpack_converter.h:151
sick_scansegment_xd::MsgPackConverter::Run
bool Run(void)
Definition: msgpack_converter.cpp:156
sick_scansegment_xd::MsgPackConverter::Start
bool Start(void)
Definition: msgpack_converter.cpp:106
sick_scansegment_xd::MsgPackConverter
Definition: msgpack_converter.h:84
sick_scan_base.h
sick_scansegment_xd::MsgPackValidator
Definition: msgpack_validator.h:201
sick_scansegment_xd::MsgPackConverter::m_msgpack_validator_check_missing_scandata_interval
int m_msgpack_validator_check_missing_scandata_interval
Definition: msgpack_converter.h:158
sick_scansegment_xd::ScanSegmentParserConfig
Definition: scansegment_parser_output.h:91
sick_scansegment_xd::MsgPackConverter::Close
void Close(void)
Definition: msgpack_converter.cpp:116


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