adsd3500_mode_selector.cpp
Go to the documentation of this file.
1 /*
2  * BSD 3-Clause License
3  *
4  * Copyright (c) 2019, Analog Devices, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice, this
11  * list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  *
17  * 3. Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived from
19  * this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 #include "adsd3500_mode_selector.h"
33 #include <algorithm>
34 
35 Adsd3500ModeSelector::Adsd3500ModeSelector() : m_configuration("standard") {
36 
37  m_availableConfigurations.emplace_back("standard");
38  m_availableConfigurations.emplace_back("standardRaw");
39  m_availableConfigurations.emplace_back("custom");
40  m_availableConfigurations.emplace_back("customRaw");
41 
42  m_controls.emplace("imagerType", "");
43  m_controls.emplace("mode", "");
44  m_controls.emplace("mixedModes", "");
45 
46  m_controls.emplace("depthBits", "");
47  m_controls.emplace("abBits", "");
48  m_controls.emplace("confBits", "");
49 
50  m_controls.emplace("inputFormat", "");
51 }
52 
53 //functions to set which table configuration to use
56  if (std::find(m_availableConfigurations.begin(),
58  configuration) != m_availableConfigurations.end()) {
59  m_configuration = configuration;
60  return aditof::Status::OK;
61  } else {
63  }
64 }
65 
67  std::vector<DepthSensorModeDetails> &m_depthSensorModeDetails) {
68 
69  m_depthSensorModeDetails.clear();
70 
71  if (m_configuration == "standard") {
72  if (m_controls["imagerType"] == imagerType.at(ImagerType::ADSD3100)) {
73  m_depthSensorModeDetails = adsd3100_standardModes;
74  } else if (m_controls["imagerType"] ==
76  m_depthSensorModeDetails = adsd3030_standardModes;
77  } else if (m_controls["imagerType"] ==
79  m_depthSensorModeDetails = adtf3080_standardModes;
80  }
81  }
82 
83  return aditof::Status::OK;
84 }
85 
87  DepthSensorModeDetails &configurationTable) {
88 
89  if (m_configuration == "standard") {
90  if (m_controls["imagerType"] == imagerType.at(ImagerType::ADSD3100)) {
92  for (auto &modes : adsd3100_standardModes) {
93  if (m_controls["mode"] == std::to_string(modes.modeNumber)) {
94  configurationTable = modes;
95  return aditof::Status::OK;
96  }
97  }
98  } else if (m_controls["imagerType"] ==
101  for (auto &modes : adsd3030_standardModes) {
102  if (m_controls["mode"] == std::to_string(modes.modeNumber)) {
103  configurationTable = modes;
104  return aditof::Status::OK;
105  }
106  }
107  } else if (m_controls["imagerType"] ==
110  for (auto &modes : adtf3080_standardModes) {
111  if (m_controls["mode"] == std::to_string(modes.modeNumber)) {
112  configurationTable = modes;
113  return aditof::Status::OK;
114  }
115  }
116  }
117  }
118 
120 }
121 
123  DepthSensorModeDetails &configurationTable) {
124 
125  for (auto driverConf : m_adsd3500standard) {
126  if (driverConf.baseWidth ==
127  std::to_string(configurationTable.baseResolutionWidth) &&
128  driverConf.baseHeigth ==
129  std::to_string(configurationTable.baseResolutionHeight) &&
130  std::stoi(driverConf.noOfPhases) ==
131  configurationTable.numberOfPhases &&
132  driverConf.depthBits == m_controls["depthBits"] &&
133  driverConf.abBits == m_controls["abBits"] &&
134  driverConf.confBits == m_controls["confBits"] &&
135  driverConf.pixelFormat == m_controls["inputFormat"]) {
136  configurationTable.frameWidthInBytes = driverConf.driverWidth;
137  configurationTable.frameHeightInBytes = driverConf.driverHeigth;
138  configurationTable.pixelFormatIndex = driverConf.pixelFormatIndex;
139 
140  return aditof::Status::OK;
141  }
142  }
143 
144  int depth_i = std::stoi(m_controls["depthBits"]);
145  int ab_i = std::stoi(m_controls["abBits"]);
146  int conf_i = std::stoi(m_controls["confBits"]);
147  std::vector<int> depth_v = {16, 14, 12, 10, 8, 0};
148  std::vector<int> ab_v = {16, 14, 12, 10, 8, 0};
149  std::vector<int> conf_v = {8, 4, 0};
150 
151  if (std::find(depth_v.begin(), depth_v.end(), depth_i) == depth_v.end()) {
153  }
154  if (std::find(ab_v.begin(), ab_v.end(), ab_i) == ab_v.end()) {
156  }
157  if (std::find(conf_v.begin(), conf_v.end(), conf_i) == conf_v.end()) {
159  }
160 
161  int totalBits = depth_i + ab_i + conf_i;
162  int width = configurationTable.baseResolutionWidth * totalBits / 8;
163 
164  int height = configurationTable.baseResolutionHeight;
165 
166  if (configurationTable.isPCM) {
167  configurationTable.frameWidthInBytes =
168  configurationTable.baseResolutionWidth;
169  configurationTable.frameHeightInBytes =
170  configurationTable.baseResolutionHeight;
171  configurationTable.pixelFormatIndex = 1;
172 
173  //TO DO: hardcoded for now for the 9pcm usecase
174  if (configurationTable.numberOfPhases == 9) {
175  configurationTable.frameWidthInBytes = 1024;
176  configurationTable.frameHeightInBytes = 2880;
177  }
178  return aditof::Status::OK;
179  }
180  if (m_controls["imagerType"] == imagerType.at(ImagerType::ADTF3080)) {
181 
182  configurationTable.frameWidthInBytes =
183  configurationTable.baseResolutionWidth * totalBits / 8;
184  configurationTable.frameHeightInBytes =
185  configurationTable.baseResolutionHeight;
186  configurationTable.pixelFormatIndex = 0;
187  return aditof::Status::OK;
188 
189  } else {
190 
191  if ((configurationTable.modeNumber == 2 ||
192  configurationTable.modeNumber == 3 ||
193  configurationTable.modeNumber == 5 ||
194  configurationTable.modeNumber == 6) &&
195  m_controls["imagerType"] == imagerType.at(ImagerType::ADSD3100)) {
196  height = 512;
197  } else if ((configurationTable.modeNumber == 0 ||
198  configurationTable.modeNumber == 1) &&
199  m_controls["imagerType"] ==
201  height = 640;
202  } else if (configurationTable.modeNumber == 7 &&
203  m_controls["imagerType"] ==
205  width = 2560;
206  height = 640;
207  } else if (configurationTable.modeNumber >= 2 &&
208  m_controls["imagerType"] ==
210  configurationTable.frameWidthInBytes = 1280;
211  configurationTable.frameHeightInBytes = 320;
212  configurationTable.pixelFormatIndex = 0;
213  return aditof::Status::OK;
214  } else if ((configurationTable.modeNumber < 0 ||
215  configurationTable.modeNumber > 6) &&
216  m_controls["imagerType"] !=
218  m_controls["imagerType"] !=
221  }
222  }
223 
224  configurationTable.frameWidthInBytes = width;
225  configurationTable.frameHeightInBytes = height;
226  configurationTable.pixelFormatIndex = 0;
227 
228  return aditof::Status::OK;
229 }
230 
231 //Functions used to set mode, number of bits, pixel format, etc
233  const std::string &value) {
234  using namespace aditof;
235  Status status = Status::OK;
236 
237  if (m_controls.count(control) == 0) {
239  }
240 
241  m_controls[control] = value;
242 
243  //ccbm will work only with standard modes
244  if (control == "imagerType") {
247  } else if (value == imagerType.at(ImagerType::ADSD3030)) {
249  } else if (value == imagerType.at(ImagerType::ADTF3080)) {
251  }
252  }
253 
254  return status;
255 }
256 
258  std::string &value) {
259  using namespace aditof;
260  Status status = Status::OK;
261 
262  if (m_controls.count(control) == 0) {
264  }
265 
266  value = m_controls[control];
267 
268  return status;
269 }
aditof::DepthSensorModeDetails::isPCM
int isPCM
set to true if the mode is PCM
Definition: sensor_definitions.h:170
aditof::Adsd3500ModeSelector::m_configuration
std::string m_configuration
Definition: adsd3500_mode_selector.h:69
aditof::DepthSensorModeDetails::modeNumber
uint8_t modeNumber
Number associated with the mode.
Definition: sensor_definitions.h:125
height
GLint GLsizei GLsizei height
Definition: glcorearb.h:2768
aditof::DepthSensorModeDetails::frameHeightInBytes
int frameHeightInBytes
Driver height, can be used for both chipRaw and imagerRaw.
Definition: sensor_definitions.h:150
aditof::DepthSensorModeDetails::baseResolutionHeight
int baseResolutionHeight
Processed data height.
Definition: sensor_definitions.h:160
aditof::Adsd3500ModeSelector::setConfiguration
aditof::Status setConfiguration(const std::string &configuration)
Definition: adsd3500_mode_selector.cpp:55
aditof::Adsd3500ModeSelector::getAvailableModeDetails
aditof::Status getAvailableModeDetails(std::vector< DepthSensorModeDetails > &m_depthSensorModeDetails)
Definition: adsd3500_mode_selector.cpp:66
string
GLsizei const GLchar *const * string
Definition: glcorearb.h:3083
aditof::Adsd3500ModeSelector::getConfigurationTable
aditof::Status getConfigurationTable(DepthSensorModeDetails &configurationTable)
Definition: adsd3500_mode_selector.cpp:86
aditof::Adsd3500ModeSelector::m_tableInUse
std::vector< aditof::DepthSensorModeDetails > m_tableInUse
Definition: adsd3500_mode_selector.h:72
adsd3030_standardModes
const std::vector< DepthSensorModeDetails > adsd3030_standardModes
Definition: driver_configuration_table.h:146
aditof::ImagerType::ADSD3100
@ ADSD3100
The ADSD3100 imager.
adtf3080_standardModes
const std::vector< DepthSensorModeDetails > adtf3080_standardModes
Definition: driver_configuration_table.h:225
aditof
Namespace aditof.
Definition: adsd_errs.h:40
aditof::Adsd3500ModeSelector::updateConfigurationTable
aditof::Status updateConfigurationTable(DepthSensorModeDetails &configurationTable)
Definition: adsd3500_mode_selector.cpp:122
aditof::DepthSensorModeDetails::pixelFormatIndex
int pixelFormatIndex
Index of two possbile values sensor values (8bit, 12/16bit)
Definition: sensor_definitions.h:140
adsd3100_standardModes
const std::vector< DepthSensorModeDetails > adsd3100_standardModes
Definition: driver_configuration_table.h:67
aditof::ImagerType::ADTF3080
@ ADTF3080
The ADTF3080 imager.
m_adsd3500standard
const std::vector< DriverConfiguration > m_adsd3500standard
Definition: driver_configuration_table.h:51
aditof::Adsd3500ModeSelector::m_availableConfigurations
std::vector< std::string > m_availableConfigurations
Definition: adsd3500_mode_selector.h:70
aditof::Status::INVALID_ARGUMENT
@ INVALID_ARGUMENT
Invalid arguments provided.
aditof::Status
Status
Status of any operation that the TOF sdk performs.
Definition: status_definitions.h:48
aditof::DepthSensorModeDetails::baseResolutionWidth
int baseResolutionWidth
Processed data witdh.
Definition: sensor_definitions.h:155
aditof::Status::OK
@ OK
Success.
aditof::DepthSensorModeDetails
Describes the type of entire frame that a depth sensor can capture and transmit.
Definition: sensor_definitions.h:120
aditof::Adsd3500ModeSelector::getControl
aditof::Status getControl(const std::string &control, std::string &value)
Definition: adsd3500_mode_selector.cpp:257
aditof::DepthSensorModeDetails::frameWidthInBytes
int frameWidthInBytes
Driver width, can be used for both chipRaw and imagerRaw.
Definition: sensor_definitions.h:145
aditof::ImagerType::ADSD3030
@ ADSD3030
The ADSD3030 imager.
aditof::DepthSensorModeDetails::numberOfPhases
uint8_t numberOfPhases
Number of phases.
Definition: sensor_definitions.h:135
aditof::Adsd3500ModeSelector::m_controls
std::map< std::string, std::string > m_controls
Definition: adsd3500_mode_selector.h:71
value
GLsizei const GLfloat * value
Definition: glcorearb.h:3093
aditof::Adsd3500ModeSelector::setControl
aditof::Status setControl(const std::string &control, const std::string &value)
Definition: adsd3500_mode_selector.cpp:232
aditof::imagerType
const std::map< ImagerType, std::string > imagerType
Types of imagers.
Definition: camera_definitions.h:218
adsd3500_mode_selector.h
width
GLint GLsizei width
Definition: glcorearb.h:2768


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:47