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


psen_scan_v2
Author(s): Pilz GmbH + Co. KG
autogenerated on Sat Jun 22 2024 02:46:11