@@ -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+
6981def 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 ("\n interactive_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