Skip to content

Commit 32831ae

Browse files
FlorinBuica-luxonisalex-luxonis
authored andcommitted
adding bindings for ToF
1 parent bddb42e commit 32831ae

File tree

5 files changed

+132
-3
lines changed

5 files changed

+132
-3
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,11 @@ pybind11_add_module(${TARGET_NAME}
124124
src/pipeline/node/IMUBindings.cpp
125125
src/pipeline/node/EdgeDetectorBindings.cpp
126126
src/pipeline/node/FeatureTrackerBindings.cpp
127+
src/pipeline/node/ToFBindings.cpp
127128
src/pipeline/node/AprilTagBindings.cpp
128129
src/pipeline/node/DetectionParserBindings.cpp
129130
src/pipeline/node/WarpBindings.cpp
131+
src/pipeline/node/ToFBindings.cpp
130132

131133
src/pipeline/datatype/ADatatypeBindings.cpp
132134
src/pipeline/datatype/AprilTagConfigBindings.cpp
@@ -135,6 +137,7 @@ pybind11_add_module(${TARGET_NAME}
135137
src/pipeline/datatype/CameraControlBindings.cpp
136138
src/pipeline/datatype/EdgeDetectorConfigBindings.cpp
137139
src/pipeline/datatype/FeatureTrackerConfigBindings.cpp
140+
src/pipeline/datatype/ToFConfigBindings.cpp
138141
src/pipeline/datatype/ImageManipConfigBindings.cpp
139142
src/pipeline/datatype/ImgDetectionsBindings.cpp
140143
src/pipeline/datatype/ImgFrameBindings.cpp
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include "DatatypeBindings.hpp"
2+
#include "pipeline/CommonBindings.hpp"
3+
#include <unordered_map>
4+
#include <memory>
5+
6+
// depthai
7+
#include "depthai/pipeline/datatype/ToFConfig.hpp"
8+
9+
//pybind
10+
#include <pybind11/chrono.h>
11+
#include <pybind11/numpy.h>
12+
13+
// #include "spdlog/spdlog.h"
14+
15+
void bind_tofconfig(pybind11::module& m, void* pCallstack){
16+
17+
using namespace dai;
18+
19+
py::class_<RawToFConfig, RawBuffer, std::shared_ptr<RawToFConfig>> rawToFConfig(m, "RawToFConfig", DOC(dai, RawToFConfig));
20+
py::class_<RawToFConfig::DepthParams> depthParams(rawToFConfig, "DepthParams", DOC(dai, RawToFConfig, DepthParams));
21+
py::enum_<RawToFConfig::DepthParams::TypeFMod> depthParamsTypeFMod(depthParams, "TypeFMod", DOC(dai, RawToFConfig, DepthParams, TypeFMod));
22+
py::class_<ToFConfig, Buffer, std::shared_ptr<ToFConfig>> toFConfig(m, "ToFConfig", DOC(dai, ToFConfig));
23+
24+
///////////////////////////////////////////////////////////////////////
25+
///////////////////////////////////////////////////////////////////////
26+
///////////////////////////////////////////////////////////////////////
27+
// Call the rest of the type defines, then perform the actual bindings
28+
Callstack* callstack = (Callstack*) pCallstack;
29+
auto cb = callstack->top();
30+
callstack->pop();
31+
cb(m, pCallstack);
32+
// Actual bindings
33+
///////////////////////////////////////////////////////////////////////
34+
///////////////////////////////////////////////////////////////////////
35+
///////////////////////////////////////////////////////////////////////
36+
37+
// Metadata / raw
38+
rawToFConfig
39+
.def(py::init<>())
40+
.def_readwrite("depthParams", &RawToFConfig::depthParams, DOC(dai, RawToFConfig, depthParams))
41+
;
42+
43+
depthParamsTypeFMod
44+
.value("ALL", RawToFConfig::DepthParams::TypeFMod::F_MOD_ALL)
45+
.value("MIN", RawToFConfig::DepthParams::TypeFMod::F_MOD_MIN)
46+
.value("MAX", RawToFConfig::DepthParams::TypeFMod::F_MOD_MAX)
47+
;
48+
49+
depthParams
50+
.def(py::init<>())
51+
.def_readwrite("enable", &RawToFConfig::DepthParams::enable, DOC(dai, RawToFConfig, DepthParams, enable))
52+
.def_readwrite("freqModUsed", &RawToFConfig::DepthParams::freqModUsed, DOC(dai, RawToFConfig, DepthParams, freqModUsed))
53+
.def_readwrite("avgPhaseShuffle", &RawToFConfig::DepthParams::avgPhaseShuffle, DOC(dai, RawToFConfig, DepthParams, avgPhaseShuffle))
54+
.def_readwrite("minimumAmplitude", &RawToFConfig::DepthParams::minimumAmplitude, DOC(dai, RawToFConfig, DepthParams, minimumAmplitude))
55+
;
56+
57+
// Message
58+
toFConfig
59+
.def(py::init<>())
60+
.def(py::init<std::shared_ptr<RawToFConfig>>())
61+
62+
.def("setDepthParams", static_cast<ToFConfig&(ToFConfig::*)(dai::ToFConfig::DepthParams)>(&ToFConfig::setDepthParams), py::arg("config"), DOC(dai, ToFConfig, setDepthParams, 2))
63+
64+
.def("set", &ToFConfig::set, py::arg("config"), DOC(dai, ToFConfig, set))
65+
.def("get", &ToFConfig::get, DOC(dai, ToFConfig, get))
66+
;
67+
68+
// add aliases
69+
m.attr("ToFConfig").attr("DepthParams") = m.attr("RawToFConfig").attr("DepthParams");
70+
71+
}

src/pipeline/node/ToFBindings.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include "NodeBindings.hpp"
2+
#include "Common.hpp"
3+
4+
#include "depthai/pipeline/Pipeline.hpp"
5+
#include "depthai/pipeline/Node.hpp"
6+
#include "depthai/pipeline/node/ToF.hpp"
7+
8+
void bind_tof(pybind11::module& m, void* pCallstack){
9+
10+
using namespace dai;
11+
using namespace dai::node;
12+
13+
// Node and Properties declare upfront
14+
py::class_<ToFProperties> tofProperties(m, "ToFProperties", DOC(dai, ToFProperties));
15+
auto tof = ADD_NODE(ToF);
16+
17+
///////////////////////////////////////////////////////////////////////
18+
///////////////////////////////////////////////////////////////////////
19+
///////////////////////////////////////////////////////////////////////
20+
// Call the rest of the type defines, then perform the actual bindings
21+
Callstack* callstack = (Callstack*) pCallstack;
22+
auto cb = callstack->top();
23+
callstack->pop();
24+
cb(m, pCallstack);
25+
// Actual bindings
26+
///////////////////////////////////////////////////////////////////////
27+
///////////////////////////////////////////////////////////////////////
28+
///////////////////////////////////////////////////////////////////////
29+
30+
// Properties
31+
tofProperties
32+
.def_readwrite("initialConfig", &ToFProperties::initialConfig)
33+
;
34+
35+
// Node
36+
tof
37+
.def_readonly("input", &ToF::input, DOC(dai, node, ToF, input), DOC(dai, node, ToF, input))
38+
.def_readonly("inputConfig", &ToF::inputConfig, DOC(dai, node, ToF, inputConfig), DOC(dai, node, ToF, inputConfig))
39+
.def_readonly("depth", &ToF::depth, DOC(dai, node, ToF, depth), DOC(dai, node, ToF, depth))
40+
.def_readonly("amplitude", &ToF::amplitude, DOC(dai, node, ToF, amplitude), DOC(dai, node, ToF, amplitude))
41+
.def_readonly("error", &ToF::error, DOC(dai, node, ToF, error), DOC(dai, node, ToF, error))
42+
.def_readonly("initialConfig", &ToF::initialConfig, DOC(dai, node, ToF, initialConfig), DOC(dai, node, ToF, initialConfig))
43+
;
44+
// ALIAS
45+
daiNodeModule.attr("ToF").attr("Properties") = tofProperties;
46+
47+
}

utilities/cam_test.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
from itertools import cycle
4646
from pathlib import Path
4747
import sys
48-
import cam_test_gui
48+
#import cam_test_gui
4949
import signal
5050

5151

@@ -181,6 +181,9 @@ def get(self):
181181
control = pipeline.createXLinkIn()
182182
control.setStreamName('control')
183183

184+
xinTofConfig = pipeline.createXLinkIn()
185+
xinTofConfig.setStreamName('tofConfig')
186+
184187
cam = {}
185188
tof = {}
186189
xout = {}
@@ -199,6 +202,11 @@ def get(self):
199202
tof[c] = pipeline.create(dai.node.ToF)
200203
cam[c].raw.link(tof[c].input)
201204
tof[c].depth.link(xout[c].input)
205+
xinTofConfig.out.link(tof[c].inputConfig)
206+
tofConfig = tof[c].initialConfig.get()
207+
tofConfig.setFreqModUsed(dai.ToFConfig.DepthParams.TypeFMod.F_MOD_MIN)
208+
tofConfig.SetAvgPhaseShuffle(True)
209+
tofConfig.setMinAmplitude(20.0)
202210
elif cam_type_color[c]:
203211
cam[c] = pipeline.createColorCamera()
204212
cam[c].setResolution(color_res_opts[args.color_resolution])
@@ -230,7 +238,7 @@ def get(self):
230238
xout_raw[c] = pipeline.create(dai.node.XLinkOut)
231239
xout_raw[c].setStreamName(raw_name)
232240
streams.append(raw_name)
233-
cam[c].raw.link(xout_raw[c].input)
241+
tof[c].amplitude.link(xout_raw[c].input)
234242
cam[c].setRawOutputPacked(False)
235243

236244
if args.camera_tuning:

0 commit comments

Comments
 (0)