6
6
from ot3_testing .test_config .zstage_leveling_config import ZStagePoint , CalibrateMethod , ZStageChannel
7
7
from typing import List
8
8
from drivers .play_sound import play_alarm_3
9
-
9
+ from utils import Utils
10
+ import os
11
+ import asyncio
10
12
RequestReadyFlag = False
13
+ ApplyCompensationFlag = True
11
14
12
15
13
16
class ZStageLeveling (TestBase ):
@@ -178,11 +181,11 @@ async def adjust_leveling(self, slot_name: str, mount: Mount):
178
181
input ("Judging complete ? (完成校准回车)" )
179
182
self .judge_complete = True
180
183
181
- async def run_z_stage_test (self ):
184
+ async def run_z_stage_test (self , project_path = None ):
182
185
"""
183
186
main loop
184
187
"""
185
- test_result = {}
188
+ self . judge_complete = False
186
189
if self .robot_ip is None :
187
190
addr = self .get_address ().strip ()
188
191
else :
@@ -193,13 +196,16 @@ async def run_z_stage_test(self):
193
196
194
197
# adjust
195
198
await self .adjust_leveling ('Z-C2' , Mount .RIGHT )
196
-
197
- await self .api .home ()
198
-
199
199
input ("Run Test (开始测试)?" )
200
200
# run test
201
+ await self .api .home ()
202
+
203
+ csv_title = []
204
+ csv_list = []
205
+
201
206
for mount in [Mount .RIGHT , Mount .LEFT ]:
202
207
self .mount = mount
208
+ test_result = {}
203
209
print (f"Start { self .mount .value } side..." )
204
210
for p_key , p_value in ZStagePoint [self .mount ].items ():
205
211
_point = p_value ["point" ]
@@ -208,12 +214,47 @@ async def run_z_stage_test(self):
208
214
result = await self .run_test_slot (_point , p_key , _channel_definition )
209
215
test_result .update (result )
210
216
await self .api .home ()
211
- print (test_result )
212
- # save
217
+ print (test_result )
218
+ # save
219
+ for key , value in test_result .items ():
220
+ result = []
221
+ distance_list = list (value .values ())
222
+ difference = round (abs (distance_list [0 ] - distance_list [1 ]), 3 )
223
+ compensation = ZStagePoint [self .mount ][key ]["compensation" ]
224
+ if ApplyCompensationFlag :
225
+ compensation_idx = 0
226
+ for compensation_key , compensation_value in compensation .items ():
227
+ print (
228
+ f"apply offset { compensation_key } -> { compensation_value } to { distance_list [compensation_idx ]} " )
229
+ result .append (compensation_value + distance_list [compensation_idx ])
230
+ compensation_idx += 1
231
+ difference = round (abs (result [0 ] - result [1 ]), 3 )
232
+ print (f"{ key } --> { value } (mm) --> difference: { difference } (mm)" )
233
+ for item_key , item_value in value .items ():
234
+ csv_title .append (self .mount .name + " " + key + " " + item_key )
235
+ csv_list .append (item_value )
236
+ csv_title .append (key + "-Result" )
237
+ csv_list .append (difference )
213
238
239
+ if project_path is not None :
240
+ file_path = os .path .join (project_path , 'testing_data' , 'z_stage_leveling.csv' )
241
+ else :
242
+ file_path = '../../testing_data/z_stage_leveling.csv'
243
+ self .save_csv (file_path , csv_title , csv_list )
244
+ self .laser_sensor .close ()
214
245
215
- if __name__ == '__main__' :
216
- import asyncio
246
+ def save_csv (self , file_path , title , content ):
247
+ """
248
+ save csv
249
+ """
250
+ is_exist = Utils .is_file_exist (file_path )
251
+ if is_exist :
252
+ pass
253
+ else :
254
+ Utils .write_to_csv (file_path , title )
255
+ Utils .write_to_csv (file_path , content )
217
256
218
- obj = ZStageLeveling (ZStagePoint , robot_ip = "192.168.6.51" )
257
+
258
+ if __name__ == '__main__' :
259
+ obj = ZStageLeveling (ZStagePoint , robot_ip = "192.168.6.33" )
219
260
asyncio .run (obj .run_z_stage_test ())
0 commit comments