laserscan.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 <algorithm>
17 #include <ostream>
18 #include <stdexcept>
19 
20 #include <fmt/format.h>
21 #include <fmt/ostream.h>
22 
27 
29 {
31 
33  const util::TenthOfDegree& min_scan_angle,
34  const util::TenthOfDegree& max_scan_angle,
35  const uint32_t scan_counter,
36  const uint8_t active_zoneset,
37  const int64_t timestamp)
38  : resolution_(resolution)
39  , min_scan_angle_(min_scan_angle)
40  , max_scan_angle_(max_scan_angle)
41  , scan_counter_(scan_counter)
42  , active_zoneset_(active_zoneset)
43  , timestamp_(timestamp)
44 {
46  {
47  throw std::invalid_argument("Resolution must not be 0");
48  }
49 
51  {
52  throw std::invalid_argument("Resolution out of possible angle range");
53  }
54 
55  if (minScanAngle() > maxScanAngle())
56  {
57  throw std::invalid_argument("Attention: Start angle has to be smaller or equal to the end angle!");
58  }
59 }
60 
62 {
63  return resolution_;
64 }
65 
66 // LCOV_EXCL_START
68 {
69  return this->scanResolution();
70 }
71 
73 {
74  return this->minScanAngle();
75 }
76 
78 {
79  return this->maxScanAngle();
80 }
81 
83 {
84  return this->measurements();
85 }
86 
87 uint32_t LaserScan::getScanCounter() const
88 {
89  return this->scanCounter();
90 }
91 
92 int64_t LaserScan::getTimestamp() const
93 {
94  return this->timestamp();
95 }
96 
98 {
99  return this->activeZoneset();
100 }
101 
103 {
104  this->measurements(measurements);
105 }
106 
108 {
109  return this->measurements();
110 }
111 
113 {
114  return this->intensities();
115 }
116 
118 {
119  this->intensities(intensities);
120 }
121 // LCOV_EXCL_STOP
122 
124 {
125  return min_scan_angle_;
126 }
127 
129 {
130  return max_scan_angle_;
131 }
132 
134 {
135  return measurements_;
136 }
137 
138 uint32_t LaserScan::scanCounter() const
139 {
140  return scan_counter_;
141 }
142 
144 {
145  return active_zoneset_;
146 }
147 
148 int64_t LaserScan::timestamp() const
149 {
150  return timestamp_;
151 }
152 
154 {
156 }
157 
159 {
160  return measurements_;
161 }
162 
164 {
165  return intensities_;
166 }
167 
169 {
171 }
172 
173 // LCOV_EXCL_START
174 void LaserScan::setIOStates(const IOData& io_states)
175 {
176  ioStates(io_states);
177 }
178 
180 {
181  return ioStates();
182 }
183 // LCOV_EXCL_STOP
184 
185 void LaserScan::ioStates(const IOData& io_states)
186 {
187  io_states_ = io_states;
188 }
189 
191 {
192  return io_states_;
193 }
194 
195 std::ostream& operator<<(std::ostream& os, const LaserScan& scan)
196 {
197  os << fmt::format("LaserScan(timestamp = {} nsec, scanCounter = {}, minScanAngle = {} deg, maxScanAngle = {} deg, "
198  "resolution = {} deg, active_zoneset = {}, measurements = {}, intensities = {}, io_states = {})",
199  scan.timestamp(),
200  scan.scanCounter(),
201  scan.minScanAngle().value() / 10.,
202  scan.maxScanAngle().value() / 10.,
203  scan.scanResolution().value() / 10.,
204  scan.activeZoneset(),
207  util::formatRange(scan.ioStates()));
208  return os;
209 }
210 
211 } // namespace psen_scan_v2_standalone
const IOData & getIOStates() const
Definition: laserscan.cpp:179
const util::TenthOfDegree & getMinScanAngle() const
Definition: laserscan.cpp:72
const util::TenthOfDegree & maxScanAngle() const
Definition: laserscan.cpp:128
void setIOStates(const IOData &io_states)
Definition: laserscan.cpp:174
std::vector< double > IntensityData
Definition: laserscan.h:50
std::vector< double > MeasurementData
Definition: laserscan.h:49
const uint32_t scan_counter_
Number of the scan round this data belongs to.
Definition: laserscan.h:134
IOData io_states_
States of the I/O pins.
Definition: laserscan.h:126
static const util::TenthOfDegree MAX_X_AXIS_ROTATION
Definition: laserscan.cpp:30
const MeasurementData & measurements() const
Definition: laserscan.cpp:133
const util::TenthOfDegree resolution_
Distance of angle between the measurements.
Definition: laserscan.h:128
const IntensityData & intensities() const
Definition: laserscan.cpp:163
void setMeasurements(const MeasurementData &measurements)
Definition: laserscan.cpp:102
void setIntensities(const IntensityData &intensities)
Definition: laserscan.cpp:117
const util::TenthOfDegree & minScanAngle() const
Definition: laserscan.cpp:123
std::ostream & operator<<(std::ostream &os, const PinState &pin_state)
Definition: io_state.cpp:59
const uint8_t active_zoneset_
The currently active zoneset of the scanner.
Definition: laserscan.h:136
const MeasurementData & getMeasurements() const
Definition: laserscan.cpp:82
IntensityData intensities_
Stores the received normalized signal intensities.
Definition: laserscan.h:124
MeasurementData measurements_
Measurement data of the laserscan (in Millimeters).
Definition: laserscan.h:122
const util::TenthOfDegree & getScanResolution() const
Definition: laserscan.cpp:67
const util::TenthOfDegree max_scan_angle_
Highest angle the scanner is scanning.
Definition: laserscan.h:132
Root namespace in which the software components to communicate with the scanner (firmware-version: 2)...
Definition: udp_client.h:41
const int64_t timestamp_
Time of the first ray in this scan round (or fragment if fragmented_scans is enabled).
Definition: laserscan.h:138
const IOData & ioStates() const
Definition: laserscan.cpp:190
const util::TenthOfDegree & getMaxScanAngle() const
Definition: laserscan.cpp:77
std::string formatRange(const T &range)
Definition: format_range.h:38
const IntensityData & getIntensities() const
Definition: laserscan.cpp:112
const util::TenthOfDegree min_scan_angle_
Lowest angle the scanner is scanning.
Definition: laserscan.h:130
std::vector< IOState > IOData
Definition: laserscan.h:51
const util::TenthOfDegree & scanResolution() const
Definition: laserscan.cpp:61
LaserScan(const util::TenthOfDegree &resolution, const util::TenthOfDegree &min_scan_angle, const util::TenthOfDegree &max_scan_angle, const uint32_t scan_counter, const uint8_t active_zoneset, const int64_t timestamp)
Definition: laserscan.cpp:32
This class represents a single laser scan in the <tf_prefix> target frame.
Definition: laserscan.h:46
Helper class representing angles in tenth of degree.


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