base
SonarScan.hpp
Go to the documentation of this file.
1 
5 #ifndef BASE_SAMPLES_SONARSCAN_H__
6 #define BASE_SAMPLES_SONARSCAN_H__
7 
8 #include <base/Time.hpp>
9 #include <base/Angle.hpp>
10 #include <base/samples/SonarBeam.hpp>
11 
12 namespace base { namespace samples {
13 
14  struct SonarScan
15  {
16  public:
20  SonarScan();
21 
23 
24  //makes a copy of other
25  SonarScan(const SonarScan &other,bool bcopy = true);
26 
27  SonarScan &operator=(const SonarScan &other);
28 
29  //makes a copy of other
30  void init(const SonarScan &other,bool bcopy = true);
31 
32  void init(uint16_t number_of_beams, uint16_t number_of_bins, Angle start_bearing, Angle angular_resolution,bool memory_layout_column = true, int val=-1);
33 
34  // if val is negative the sonar scan data will not be initialized
35  void reset(int const val = 0);
36 
37  //returns the index/column of the sonar beam which
38  //holds information about the given bearing
39  //returns -1 if the sonar scan has no sonar beam for the given bearing
40  int beamIndexForBearing(const Angle bearing,bool range_check=true)const;
41 
42  //returns true if a sonar beam was already added for the given
43  //bearing
44  //internally time_beams is used for checking
45  bool hasSonarBeam(const base::samples::SonarBeam &sonar_beam)const;
46 
47  bool hasSonarBeam(const Angle bearing)const;
48 
49 
50  //adds a sonar beam to the sonar scan
51  //throws an exception if the sonar scan cannot hold the sonar beam and resize is set to false
52  //otherwise the sonar scan will be resized (the start angle is not changed!)
53  //
54  //the memory layout must be one sonar beam per row otherwise the function will throw a std::runtime_error
55  void addSonarBeam(const base::samples::SonarBeam &sonar_beam,bool resize=true);
56 
57  //returns a sonar beam for a given bearing
58  //throws an exception if the sonar scans holds no information for the given bearing
59  //the memory layout must be one beam per row
60  //
61  //an exception is thrown if the sonar beam holds no information about the given bearing
62  void getSonarBeam(const Angle bearing,SonarBeam &sonar_beam)const;
63 
64  //this toggles the memory layout between one sonar beam per row and one sonar beam per column
65  //to add sonar beams the memory layout must be one sonar beam per row
66  void toggleMemoryLayout();
67 
68  void swap(SonarScan &sonar_scan);
69 
70  uint32_t getNumberOfBytes() const;
71 
76  uint32_t getBinCount() const;
77 
78  const std::vector<uint8_t> &getData() const;
79 
80 
81  Angle getEndBearing()const;
82 
83  Angle getStartBearing()const;
84 
86 
87  //calculates the spatial resolution of the sonar scan in meter
88  //this takes the sampling_interval and the speed of sound into account
89  double getSpatialResolution()const;
90 
91  void setData(const std::vector<uint8_t> &data);
92 
93  void setData(const char *data, uint32_t size);
94 
95  uint8_t *getDataPtr();
96 
97  const uint8_t *getDataConstPtr() const;
98 
99  //The time at which this sonar scan has been captured
101 
102  //The raw data of the sonar scan
103  std::vector<uint8_t> data;
104 
105  //Time stamp for each sonar beam
106  //if the time stamp is 1 January 1970
107  //the beam is regarded as not be set
108  //vector can be empty in this case time
109  //is used for all beams
110  std::vector<base::Time> time_beams;
111 
112  //number of beams
113  //this can be interpreted as image width
114  uint16_t number_of_beams;
115 
116  //number of bins
117  //this can be interpreted as image height
118  uint16_t number_of_bins;
119 
129 
130  // Angle difference between two beams in radians
131  // The beams are stored from left to right
132  // to match the memory layout of an image
133  //
134  // This value must be always positive !
136 
137  //sampling interval of each range bin in secs
139 
140  //speed of sound
141  //this takes the medium into account
143 
144  //horizontal beam width of the sonar beam in radians
146 
147  //vertical beam width of the sonar beam in radians
149 
150  //if set to true one sonar beam is stored per column
151  //otherwise per row
153 
154  //if set to true the bins are interpreted in polar coordinates
155  //otherwise in Cartesian coordinates
156  //
157  //Some imaging sonars store their data in Cartesian rather than
158  //polar coordinates (BlueView)
160  };
161 }}
162 
163 #endif
164 
uint32_t getBinCount() const
Definition: SonarScan.cpp:237
std::vector< base::Time > time_beams
Definition: SonarScan.hpp:110
Definition: SonarScan.hpp:14
bool hasSonarBeam(const base::samples::SonarBeam &sonar_beam) const
Definition: SonarScan.cpp:96
uint16_t number_of_bins
Definition: SonarScan.hpp:118
std::vector< uint8_t > data
Definition: SonarScan.hpp:103
Angle beamwidth_horizontal
Definition: SonarScan.hpp:145
Angle start_bearing
Definition: SonarScan.hpp:128
void toggleMemoryLayout()
Definition: SonarScan.cpp:167
uint32_t getNumberOfBytes() const
Definition: SonarScan.cpp:232
Angle getEndBearing() const
Definition: SonarScan.cpp:247
uint16_t number_of_beams
Definition: SonarScan.hpp:114
const uint8_t * getDataConstPtr() const
Definition: SonarScan.cpp:294
const std::vector< uint8_t > & getData() const
Definition: SonarScan.cpp:242
bool polar_coordinates
Definition: SonarScan.hpp:159
Angle getStartBearing() const
Definition: SonarScan.cpp:252
Angle beamwidth_vertical
Definition: SonarScan.hpp:148
Angle getAngularResolution() const
Definition: SonarScan.cpp:257
Definition: Time.hpp:11
void getSonarBeam(const Angle bearing, SonarBeam &sonar_beam) const
Definition: SonarScan.cpp:146
SonarScan()
Definition: SonarScan.cpp:13
void setData(const std::vector< uint8_t > &data)
Definition: SonarScan.cpp:270
bool memory_layout_column
Definition: SonarScan.hpp:152
double getSpatialResolution() const
Definition: SonarScan.cpp:262
void reset(int const val=0)
Definition: SonarScan.cpp:77
double sampling_interval
Definition: SonarScan.hpp:138
void init(const SonarScan &other, bool bcopy=true)
Definition: SonarScan.cpp:43
float speed_of_sound
Definition: SonarScan.hpp:142
uint8_t * getDataPtr()
Definition: SonarScan.cpp:289
void swap(SonarScan &sonar_scan)
Definition: SonarScan.cpp:188
Definition: LinearAngular6DCommand.hpp:8
base::Time time
Definition: SonarScan.hpp:100
Angle angular_resolution
Definition: SonarScan.hpp:135
void addSonarBeam(const base::samples::SonarBeam &sonar_beam, bool resize=true)
Definition: SonarScan.cpp:117
Definition: SonarBeam.hpp:10
Definition: Angle.hpp:19
int beamIndexForBearing(const Angle bearing, bool range_check=true) const
Definition: SonarScan.cpp:87
SonarScan & operator=(const SonarScan &other)
Definition: SonarScan.cpp:37