Skip to content

Commit cbe0c76

Browse files
authored
Added ability to set the lens position via a float, to enable a more precise movement. (#964)
* Added ability to set the lens position with a float value (more precise) * I think this also includes an rpc fix by @jakgra
1 parent 36abd80 commit cbe0c76

File tree

5 files changed

+12
-6
lines changed

5 files changed

+12
-6
lines changed

src/pipeline/datatype/CameraControlBindings.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ std::vector<const char *> camCtrlAttr;
177177
.def_readwrite("cmdMask", &RawCameraControl::cmdMask)
178178
.def_readwrite("autoFocusMode", &RawCameraControl::autoFocusMode)
179179
.def_readwrite("lensPosition", &RawCameraControl::lensPosition)
180+
.def_readwrite("lensPositionRaw", &RawCameraControl::lensPositionRaw)
180181
.def_readwrite("expManual", &RawCameraControl::expManual)
181182
.def_readwrite("afRegion", &RawCameraControl::afRegion)
182183
.def_readwrite("awbMode", &RawCameraControl::awbMode)
@@ -218,6 +219,7 @@ std::vector<const char *> camCtrlAttr;
218219
.def("setAutoFocusLensRange", &CameraControl::setAutoFocusLensRange, py::arg("infinityPosition"), py::arg("macroPosition"), DOC(dai, CameraControl, setAutoFocusLensRange))
219220
.def("setAutoFocusRegion", &CameraControl::setAutoFocusRegion, py::arg("startX"), py::arg("startY"), py::arg("width"), py::arg("height"), DOC(dai, CameraControl, setAutoFocusRegion))
220221
.def("setManualFocus", &CameraControl::setManualFocus, py::arg("lensPosition"), DOC(dai, CameraControl, setManualFocus))
222+
.def("setManualFocusRaw", &CameraControl::setManualFocusRaw, py::arg("lensPositionRaw"), DOC(dai, CameraControl, setManualFocusRaw))
221223
.def("setAutoExposureEnable", &CameraControl::setAutoExposureEnable, DOC(dai, CameraControl, setAutoExposureEnable))
222224
.def("setAutoExposureLock", &CameraControl::setAutoExposureLock, py::arg("lock"), DOC(dai, CameraControl, setAutoExposureLock))
223225
.def("setAutoExposureRegion", &CameraControl::setAutoExposureRegion, py::arg("startX"), py::arg("startY"), py::arg("width"), py::arg("height"), DOC(dai, CameraControl, setAutoExposureRegion))
@@ -246,6 +248,7 @@ std::vector<const char *> camCtrlAttr;
246248
.def("getExposureTime", &CameraControl::getExposureTime, DOC(dai, CameraControl, getExposureTime))
247249
.def("getSensitivity", &CameraControl::getSensitivity, DOC(dai, CameraControl, getSensitivity))
248250
.def("getLensPosition", &CameraControl::getLensPosition, DOC(dai, CameraControl, getLensPosition))
251+
.def("getLensPositionRaw", &CameraControl::getLensPositionRaw, DOC(dai, CameraControl, getLensPositionRaw))
249252
.def("get", &CameraControl::get, DOC(dai, CameraControl, get))
250253
;
251254
// Add also enum attributes from RawCameraControl

src/pipeline/datatype/EncodedFrameBindings.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ void bind_encodedframe(pybind11::module &m, void *pCallstack) {
9999
DOC(dai, EncodedFrame, getColorTemperature))
100100
.def("getLensPosition", &EncodedFrame::getLensPosition,
101101
DOC(dai, EncodedFrame, getLensPosition))
102+
.def("getLensPositionRaw", &EncodedFrame::getLensPositionRaw,
103+
DOC(dai, EncodedFrame, getLensPositionRaw))
102104
.def("getQuality", &EncodedFrame::getQuality,
103105
DOC(dai, EncodedFrame, getQuality))
104106
.def("getBitrate", &EncodedFrame::getBitrate,

src/pipeline/datatype/ImgFrameBindings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ void bind_imgframe(pybind11::module& m, void* pCallstack){
131131
.def("getSensitivity", &ImgFrame::getSensitivity, DOC(dai, ImgFrame, getSensitivity))
132132
.def("getColorTemperature", &ImgFrame::getColorTemperature, DOC(dai, ImgFrame, getColorTemperature))
133133
.def("getLensPosition", &ImgFrame::getLensPosition, DOC(dai, ImgFrame, getLensPosition))
134+
.def("getLensPositionRaw", &ImgFrame::getLensPositionRaw, DOC(dai, ImgFrame, getLensPositionRaw))
134135

135136
// OpenCV Support section
136137
.def("setFrame", [](dai::ImgFrame& frm, py::array arr){

utilities/cam_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,16 +354,16 @@ def exit_cleanly(signum, frame):
354354
# Manual exposure/focus set step
355355
EXP_STEP = 500 # us
356356
ISO_STEP = 50
357-
LENS_STEP = 3
357+
LENS_STEP = 1 / 1024
358358
DOT_STEP = 0.05
359359
FLOOD_STEP = 0.05
360360
DOT_MAX = 1
361361
FLOOD_MAX = 1
362362

363363
# Defaults and limits for manual focus/exposure controls
364-
lensPos = 150
365-
lensMin = 0
366-
lensMax = 255
364+
lensPos = 0.59
365+
lensMin = 0.0
366+
lensMax = 1.0
367367

368368
expTime = 20000
369369
expMin = 1
@@ -524,7 +524,7 @@ def exit_cleanly(signum, frame):
524524
lensPos = clamp(lensPos, lensMin, lensMax)
525525
print("Setting manual focus, lens position: ", lensPos)
526526
ctrl = dai.CameraControl()
527-
ctrl.setManualFocus(lensPos)
527+
ctrl.setManualFocusRaw(lensPos)
528528
controlQueue.send(ctrl)
529529
elif key in [ord('i'), ord('o'), ord('k'), ord('l')]:
530530
if key == ord('i'):

0 commit comments

Comments
 (0)