ParseMeasurementData.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 
24 // -- END LICENSE BLOCK ------------------------------------------------
25 
26 //----------------------------------------------------------------------
33 //----------------------------------------------------------------------
34 
36 
37 namespace sick {
38 namespace data_processing {
39 
41 
44  datastructure::Data& data)
45 {
46  datastructure::MeasurementData measurement_data;
47  if (!checkIfPreconditionsAreMet(data))
48  {
49  measurement_data.setIsEmpty(true);
50  return measurement_data;
51  }
52  // Keep our own copy of the shared_ptr to keep the iterators valid
53  const std::shared_ptr<std::vector<uint8_t> const> vec_ptr = buffer.getBuffer();
54  std::vector<uint8_t>::const_iterator data_ptr =
55  vec_ptr->begin() + data.getDataHeaderPtr()->getMeasurementDataBlockOffset();
56 
57 
59  setDataInMeasurementData(data_ptr, measurement_data);
60  return measurement_data;
61 }
62 
64 {
66  {
67  return false;
68  }
70  {
71  return false;
72  }
73  return true;
74 }
75 
77 {
78  return !(data.getDataHeaderPtr()->getMeasurementDataBlockOffset() == 0 &&
79  data.getDataHeaderPtr()->getMeasurementDataBlockSize() == 0);
80 }
81 
83  const datastructure::Data& data) const
84 {
85  if (data.getDataHeaderPtr()->isEmpty())
86  {
87  return false;
88  }
89  if (data.getDerivedValuesPtr()->isEmpty())
90  {
91  return false;
92  }
93  return true;
94 }
95 
96 
98  std::vector<uint8_t>::const_iterator data_ptr, datastructure::MeasurementData& measurement_data)
99 {
100  setNumberOfBeamsInMeasurementData(data_ptr, measurement_data);
101  setScanPointsInMeasurementData(data_ptr, measurement_data);
102 }
103 
105  std::vector<uint8_t>::const_iterator data_ptr,
106  datastructure::MeasurementData& measurement_data) const
107 {
108  measurement_data.setNumberOfBeams(read_write_helper::readUint32LittleEndian(data_ptr + 0));
109 }
110 
112 {
113  m_angle = data.getDerivedValuesPtr()->getStartAngle();
114  m_angle_delta = data.getDerivedValuesPtr()->getAngularBeamResolution();
115 }
116 
118  std::vector<uint8_t>::const_iterator data_ptr, datastructure::MeasurementData& measurement_data)
119 {
120  uint32_t numBeams = measurement_data.getNumberOfBeams();
121 
122  uint32_t maxexpectedbeams = 2751;
123  if (numBeams > maxexpectedbeams)
124  {
125  ROS_WARN("Field Number Beams has a value larger then the expected Number of Beams for the "
126  "laserscanners. Skipping this measurement.");
127  ROS_WARN("Max expected beams: %i", maxexpectedbeams);
128  ROS_WARN("Number beams according to the datafield: %i", numBeams);
129  measurement_data.setNumberOfBeams(0);
130  measurement_data.setIsEmpty(true);
131  return;
132  }
133 
134  for (uint32_t i = 0; i < numBeams; i++)
135  {
136  addScanPointToMeasurementData(i, data_ptr, measurement_data);
138  }
139 }
140 
142  const uint16_t offset,
143  std::vector<uint8_t>::const_iterator data_ptr,
144  datastructure::MeasurementData& measurement_data) const
145 {
146  int16_t distance = read_write_helper::readUint16LittleEndian(data_ptr + (4 + offset * 4));
147  uint8_t reflectivity = read_write_helper::readUint8LittleEndian(data_ptr + (6 + offset * 4));
148  uint8_t status = read_write_helper::readUint8LittleEndian(data_ptr + (7 + offset * 4));
149  bool valid = static_cast<bool>(status & (0x01 << 0));
150  bool infinite = static_cast<bool>(status & (0x01 << 1));
151  bool glare = static_cast<bool>(status & (0x01 << 2));
152  bool reflector = static_cast<bool>(status & (0x01 << 3));
153  bool contamination = static_cast<bool>(status & (0x01 << 4));
154  bool contamination_warning = static_cast<bool>(status & (0x01 << 5));
156  distance,
157  reflectivity,
158  valid,
159  infinite,
160  glare,
161  reflector,
162  contamination,
163  contamination_warning));
164 }
165 
166 } // namespace data_processing
167 } // namespace sick
bool checkIfPreconditionsAreMet(const datastructure::Data &data) const
bool checkIfDataContainsNeededParsedBlocks(const datastructure::Data &data) const
A packetbuffer for the raw data from the sensor.
Definition: PacketBuffer.h:61
std::shared_ptr< std::vector< uint8_t > const > getBuffer() const
Getter to return a copy of the data saved in the PacketBuffer.
bool checkIfMeasurementDataIsPublished(const datastructure::Data &data) const
Class containing the data of a single scan point.
Definition: ScanPoint.h:46
uint32_t getNumberOfBeams() const
Getter for the number of beams.
#define ROS_WARN(...)
uint8_t readUint8LittleEndian(std::vector< uint8_t >::const_iterator it)
Read an unsigned 8-bit integer at offset in big little encoding.
The data class containing all data blocks of a measurement.
Definition: Data.h:55
void setScanPointsInMeasurementData(std::vector< uint8_t >::const_iterator data_ptr, datastructure::MeasurementData &measurement_data)
void setIsEmpty(bool is_empty)
Set if measurement data is enabled.
uint32_t readUint32LittleEndian(std::vector< uint8_t >::const_iterator it)
Read an unsigned 32-bit integer at offset in little endian encoding.
void addScanPointToMeasurementData(uint16_t offset, std::vector< uint8_t >::const_iterator data_ptr, datastructure::MeasurementData &measurement_data) const
void setStartAngleAndDelta(const datastructure::Data &data)
void setNumberOfBeams(const uint32_t &number_of_beams)
Setter for the number of beams.
Class containing all scanpoints of a single measurement.
void setNumberOfBeamsInMeasurementData(std::vector< uint8_t >::const_iterator data_ptr, datastructure::MeasurementData &measurement_data) const
void setDataInMeasurementData(std::vector< uint8_t >::const_iterator data_ptr, datastructure::MeasurementData &measurement_data)
datastructure::MeasurementData parseUDPSequence(const datastructure::PacketBuffer &buffer, datastructure::Data &data)
Parses the measurement data if it is enabled.
std::shared_ptr< DataHeader > getDataHeaderPtr() const
Gets the data header.
Definition: Data.cpp:42
void addScanPoint(ScanPoint scan_point)
Add a single scanpoint to the vector of scanpoints.
uint16_t readUint16LittleEndian(std::vector< uint8_t >::const_iterator it)
Read an unsigned 16-bit integer at offset in little endian encoding.
std::shared_ptr< DerivedValues > getDerivedValuesPtr() const
Gets the derived values.
Definition: Data.cpp:64


sick_safetyscanners
Author(s): Lennart Puck
autogenerated on Fri Apr 2 2021 02:45:41