Skip to content

Commit e092ac7

Browse files
committed
PR #14059 from OhadMeir: Handle D400 calibrations that need advanced mode
(cherry picked from commit 8e1d607)
1 parent 5285193 commit e092ac7

File tree

3 files changed

+61
-35
lines changed

3 files changed

+61
-35
lines changed

src/ds/d400/d400-auto-calibration.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,13 +1390,13 @@ namespace librealsense
13901390
rs2_rs400_visual_preset old_preset = { RS2_RS400_VISUAL_PRESET_DEFAULT };
13911391

13921392
auto advanced_mode = dynamic_cast<ds_advanced_mode_base*>(this);
1393-
if (advanced_mode)
1394-
{
1395-
old_preset = (rs2_rs400_visual_preset)(int)advanced_mode->_preset_opt->query();
1396-
if (old_preset == RS2_RS400_VISUAL_PRESET_CUSTOM)
1397-
old_preset_values = advanced_mode->get_all();
1398-
advanced_mode->_preset_opt->set(RS2_RS400_VISUAL_PRESET_HIGH_ACCURACY);
1399-
}
1393+
if( !advanced_mode || !advanced_mode->is_enabled() )
1394+
throw librealsense::wrong_api_call_sequence_exception( "Camera \"Advanced Mode\" must be enabled before running this calibration" );
1395+
1396+
old_preset = (rs2_rs400_visual_preset)(int)advanced_mode->_preset_opt->query();
1397+
if (old_preset == RS2_RS400_VISUAL_PRESET_CUSTOM)
1398+
old_preset_values = advanced_mode->get_all();
1399+
advanced_mode->_preset_opt->set(RS2_RS400_VISUAL_PRESET_HIGH_ACCURACY);
14001400

14011401
std::shared_ptr<ds_advanced_mode_base> recover_preset(advanced_mode, [old_preset, advanced_mode, old_preset_values](ds_advanced_mode_base* adv)
14021402
{
@@ -1415,14 +1415,14 @@ namespace librealsense
14151415
void auto_calibrated::change_preset_and_stay()
14161416
{
14171417
auto advanced_mode = dynamic_cast<ds_advanced_mode_base*>(this);
1418-
if (advanced_mode)
1419-
{
1420-
_old_preset = (rs2_rs400_visual_preset)(int)advanced_mode->_preset_opt->query();
1421-
if (_old_preset == RS2_RS400_VISUAL_PRESET_CUSTOM)
1422-
_old_preset_values = advanced_mode->get_all();
1423-
advanced_mode->_preset_opt->set(RS2_RS400_VISUAL_PRESET_HIGH_ACCURACY);
1424-
_preset_change = true;
1425-
}
1418+
if( ! advanced_mode || ! advanced_mode->is_enabled() )
1419+
throw librealsense::wrong_api_call_sequence_exception( "Camera \"Advanced Mode\" must be enabled before running this calibration" );
1420+
1421+
_old_preset = (rs2_rs400_visual_preset)(int)advanced_mode->_preset_opt->query();
1422+
if (_old_preset == RS2_RS400_VISUAL_PRESET_CUSTOM)
1423+
_old_preset_values = advanced_mode->get_all();
1424+
advanced_mode->_preset_opt->set(RS2_RS400_VISUAL_PRESET_HIGH_ACCURACY);
1425+
_preset_change = true;
14261426
}
14271427

14281428
void auto_calibrated::restore_preset()

wrappers/python/examples/depth_auto_calibration_example.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ def main(arguments=None):
6868
print('The script is designed to run with USB3 connection type.')
6969
print('In order to enable it with USB2.1 mode the fps rates for the Focal Length and Ground Truth calculation stages should be re-adjusted')
7070
sys.exit(1)
71+
# 3. Advanced mode should be enabled
72+
# Some calibrations require changing of advanced mode presets (depends on calibration parameters/type)
73+
am_device = rs.rs400_advanced_mode(device)
74+
if not am_device or not am_device.is_enabled():
75+
print('Camera "Advanced Mode" must be enabled before calibrating.')
76+
sys.exit(1)
77+
# To enable Advanced Mode use "am_device.toggle_advanced_mode(True)". Note - causes the camera to reset (set options will return to default)
7178

7279

7380
# prepare device

wrappers/python/examples/depth_ucal_example.py

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ def on_chip_calibration_json(occ_json_file, host_assistance, interactive_mode):
2626
'"calib type": 0,\n'+\
2727
'"host assistance": ' + str(int(host_assistance)) + ',\n'+\
2828
'"keep new value after sucessful scan": 0,\n'+\
29-
'"fl data sampling": 1,\n'+\
29+
'"fl data sampling": 0,\n'+\
3030
'"adjust both sides": 0,\n'+\
3131
'"fl scan location": 0,\n'+\
3232
'"fy scan direction": 0,\n'+\
3333
'"white wall mode": 0,\n'+\
34-
'"speed": 3,\n'+\
34+
'"speed": 2,\n'+\
3535
'"scan parameter": 0,\n'+\
36-
'"apply preset": 1,\n'+\
36+
'"apply preset": 0,\n'+\
3737
'"scan only": ' + str(int(host_assistance)) + ',\n'+\
3838
'"interactive scan": ' + str(int(interactive_mode)) + ',\n'+\
3939
'"resize factor": 1\n'+\
@@ -66,7 +66,20 @@ def on_chip_calib_cb(progress):
6666
if (pp == 100):
6767
print()
6868

69+
def initialize_pipe():
70+
global config, pipeline, pipeline_wrapper, pipeline_profile, device, auto_calibrated_device
71+
config = rs.config()
72+
pipeline = rs.pipeline()
73+
pipeline_wrapper = rs.pipeline_wrapper(pipeline)
74+
pipeline_profile = config.resolve(pipeline_wrapper)
75+
device = pipeline_profile.get_device()
76+
auto_calibrated_device = rs.auto_calibrated_device(device)
77+
if not auto_calibrated_device:
78+
print("The connected device does not support auto calibration")
79+
return
80+
6981
def main(argv):
82+
global config, pipeline, pipeline_wrapper, pipeline_profile, device, auto_calibrated_device
7083
if '--help' in sys.argv or '-h' in sys.argv:
7184
print('USAGE:')
7285
print('depth_auto_calibration_example.py [--occ <json_file_name>] [--tare <json_file_name>]')
@@ -91,33 +104,22 @@ def main(argv):
91104
occ_json_file = params.get('--occ', None)
92105
tare_json_file = params.get('--tare', None)
93106

94-
pipeline = rs.pipeline()
95-
config = rs.config()
96-
97-
# Get device product line for setting a supporting resolution
98-
pipeline_wrapper = rs.pipeline_wrapper(pipeline)
99-
pipeline_profile = config.resolve(pipeline_wrapper)
100-
device = pipeline_profile.get_device()
101-
102-
auto_calibrated_device = rs.auto_calibrated_device(device)
103-
104-
if not auto_calibrated_device:
105-
print("The connected device does not support auto calibration")
106-
return
107+
initialize_pipe()
107108

108109
interactive_mode = False
109110

110111
while True:
111112
try:
112-
print ("interactive_mode: ", interactive_mode)
113+
print ("\ninteractive_mode: ", interactive_mode)
113114
operation_str = "Please select what the operation you want to do\n" + \
114115
"c - on chip calibration\n" + \
115116
"C - on chip calibration - host assist\n" + \
116117
"t - tare calibration\n" + \
117118
"T - tare calibration - host assist\n" + \
118119
"g - get the active calibration\n" + \
119120
"w - write new calibration\n" + \
120-
"e - exit\n"
121+
"a - toggle Advanced Mode on/off\n" + \
122+
"e - exit\n\n"
121123
operation = input(operation_str)
122124

123125
config = rs.config()
@@ -127,6 +129,7 @@ def main(argv):
127129
config.enable_stream(rs.stream.depth, 256, 144, rs.format.z16, 90)
128130

129131
conf = pipeline.start(config)
132+
pipeline.wait_for_frames() # Verify streaming started before calling calibration methods
130133
calib_dev = rs.auto_calibrated_device(conf.get_device())
131134

132135
# prepare device
@@ -144,7 +147,7 @@ def main(argv):
144147
if operation.lower() == 'c':
145148
print("Starting on chip calibration")
146149
occ_json = on_chip_calibration_json(occ_json_file, operation == 'C', interactive_mode)
147-
new_calib, health = calib_dev.run_on_chip_calibration(occ_json, on_chip_calib_cb, 5000)
150+
new_calib, health = calib_dev.run_on_chip_calibration(occ_json, on_chip_calib_cb, 9000)
148151
calib_done = len(new_calib) > 0
149152
while (not calib_done):
150153
frame_set = pipeline.wait_for_frames()
@@ -188,13 +191,29 @@ def main(argv):
188191
print("Writing the new calibration")
189192
calib_dev.set_calibration_table(new_calib)
190193
calib_dev.write_calibration()
194+
195+
if operation == 'a':
196+
am_device = rs.rs400_advanced_mode(device)
197+
if am_device:
198+
enabled_before_toggle = am_device.is_enabled()
199+
am_device.toggle_advanced_mode(not enabled_before_toggle)
200+
# Toggling Advanced Mode resets the camera, needs to re-query devices
201+
time.sleep(3)
202+
initialize_pipe()
203+
204+
state_str = "enabled"
205+
if enabled_before_toggle:
206+
state_str = "disabled"
207+
print('"Advanced Mode" is now', state_str)
208+
else:
209+
print('Camera does not support "Advanced Mode". Some calibrations may not run properly (depends on calibration parameters/type).')
191210

192211
if operation == 'e':
193212
return
194213

195214
print("Done\n")
196215
except Exception as e:
197-
pipeline.stop()
216+
initialize_pipe()
198217
print(e)
199218
except:
200219
print("A different Error")

0 commit comments

Comments
 (0)