-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclassConfig.py
More file actions
1582 lines (1301 loc) · 60.2 KB
/
Copy pathclassConfig.py
File metadata and controls
1582 lines (1301 loc) · 60.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#cython: language_level=3
import os
import glob
from scipy import io
import shutil
import time
import csv
from scipy import io
import json
import openpyxl
import miscmath as mm
import numpy as np
import DEFINES
import errors
import zlib
class Config:
"""
The general configuration class.
The general program configuration parameters as well as the file paths are stored here.
Attributes
----------
currentProjectTime: string
The time at which the program was launched, in the form '[YYYY]-[MM]-[DD]-[hh]h[mm]m[ss]s'
generalProjectFolder: string
The folder name of all the projects
currentProjectFolder: string
The current project folder name
resultFolder: string
The folder name for all the calibrations data, regrouped per positioner
positionerFolderPrefix: string
The prefix preceeding the positioner ID for the positioner folder
positionerFolderSuffix: string
The suffix added to the project time for the run
lifetimeSuffix: string
The suffix added to all run folders that are a lifetime
figureFolder: string
The folder name of the figure folder in each run folder
overviewsFolder: string
The folder name of the folder containing all the overviews
overviewCogging: string
The folder name of the folder containing all the cogging measurements overviews
overviewCurrent: string
The folder name of the folder containing all the current measurements overviews
overviewHardstops: string
The folder name of the folder containing all the hardstop measurements overviews
figureExtension: string
The extension for all the figures
overviewExtension: string
The extension for all the overviews
resultsOverviewFile: string
The file regrouping the last result of every positioner
resultsOverviewAutosave: string
The backup file of the resultsOverviewFile in case it could not be saved
lockFile:
The name of the lock created when the program accesses to the resultsOverviewFile file
positionerModelFile: string
The name of the positioner model file
positionerModelExtension: string
The extension of the positioner model file
figureNameCogging: string
The name preceeding the positioner ID in the cogging plot
figureNameCurrent: string
The name preceeding the positioner ID in the current measurements plot
figureNameHardstops: string
The name preceeding the positioner ID in the hardstops plot
generalConfigFolder: string
The folder name for all the configuration subfolders
testBenchFolder: string
The folder name for all the testbench configuration files
cameraFolder: string
The folder name for all the camera distortions files
firmwaresFolder: string
The folder name for all the firmware files
positionersFolder: string
The folder name for all the positioners configuration files
requirementsFolder: string
The folder name for all the requirements configuration files
calibrationsFolder: string
The folder name for all the calibration configuration files
testsFolder: string
The folder name for all the test configuration files
configFolder: string
The folder name for the general configuration file
resultsOverviewTemplateFile: string
The template file for the resultsOverviewFile
testBenchFileExtension: string
The extension for the testbench configuration files
cameraFileExtension: string
The extension for the camera distortions files
positionersFileExtension: string
The extension for the positioners configuration files
requirementsFileExtension: string
The extension for the requirements configuration files
fastCalibrationsFileExtension: string
The extension for the fast calibration configuration files
calibrationsFileExtension: string
The extension for the calibration configuration files
testsFileExtension: string
The extension for the test configuration files
currentTestBenchFile: string
The current testbench configuration file name
currentPositionerFile: string
The current positioner configuration file name
currentRequirementsFile: string
The current requiremetns configuration file name
currentFastCalibrationFile: string
The current fast calibration configuration file name
currentCalibrationFile:string
The current calibration configuration file name
currentTestFile: string
The current test configuration file name
currentConfigFile: string
The current configuration file name
configFileExtension: string
The general configuration file extension
calibrationResultsFile: string
The file name of the calibration results
testResultsFile: string
The file name of the test results
calibrationResultsFileExt: string
The file extension of the calibration results
testResultsFileExt: string
The file extension of the test results
lifetimeIterationFolderName: string
The folder name of an individual lifetime iteration
resultsLoadingFolder: string
The folder name to load the results from
preloadPositionerModel: bool
Set to True to preload the existing models before the fast calibration
calibrateDatum: bool
Set to True to calibrate the positioners datums
calibrateMotor: bool
Set to True to calibrate the positioners motors
calibrateCogging: bool
Set to True to calibrate the positioners cogging torques
forceMotorCalibration: bool
Set to True to force the positioners motors calibration, overwritting any existing calibration
forceDatumCalibration: bool
Set to True to force the positioners datums calibration, overwritting any existing calibration
forceCoggingCalibration: bool
Set to True to force the positioners cogging torque calibration, overwritting any existing calibration
nbMotorCalib: uint
The maximal number of times to perform the motor calibration
nbDatumCalib: uint
The number of times to perform the datum calibration
nbCoggingCalib: uint
The number of times to perform the cogging calibration
IDsToLoad: list of uint
The IDs of the positioners where the results are loaded (resultsLoadingFolder)
preheatBenchTime: uint
The testbench preheat time
preheatBench: bool
Set to True to preheat the bench
moveDuringPreheat: bool
If True, the positioners will move during the preheat. Else they will remain still
doFastCalibRun: bool
Set to True to perform a fast calibration
doCalibRun: bool
Set to True to perform a calibration
overwritePositionerModel: bool
Set to True to overwrite the positioner model at the end of the calibration
loadCalibRun: bool
Set to True to load a previous calibration run (from resultsLoadingFolder)
doTestRun: bool
Set to True to perform a test
loadTestRun: bool
Set to True to load a previous test run (from resultsLoadingFolder)
nbTestingLoops: uint
The number of testing loops. This will repeat the calibration-test pair n times.
currentLifetimeIteration: uint
The current lifetime iteration
reloadCalibParEachIter: bool
Set to True to reload the calibration configuration at each iteration
reloadTestParEachIter: bool
Set to True to reload the test configuration at each iteration
doLivePlot: bool
Set to True to do a live plotting of the positioners position
plotResults: bool
Set to True to generate the results graphs
saveInQc: bool
Set to True to save the results in the Quality Control file (resultsOverviewFile)
sendMail: bool
Set to True to send a summary mail at the end of the run
mailReceivers: list of string
The list of e-mail adresses to send the summary mails to
plotCoggingValues: bool
Set to True to generate the cogging graphs
plotCurrentValues: bool
Set to True to measure and generate the current graphs
plotHardstopRepeatability: bool
Set to True to measure and generate the hardstop repeatability graphs
nbHardstopRepeatabilityChecks: uint
The number of hardstop repeatability checks
upgradeFirmware: bool
Set to True to send a new firmware to the positioners
firmwareUpgradeFile: string
The relative or absolute path to the new firmware binary file
Methods
-------
__init__:
Initializes the class
load:
Loads the configuration parameters from a file
save:
Saves the configuration file in the default location.
reset_project_time:
Resets the project time string (currentProjectTime) to be now
get_camera_path:
Returns the relative path to the camera distortion folder as one string
get_config_path:
Returns the relative path to the general configurations folder as one string
get_testbench_path:
Returns the relative path to the testbench configurations folder as one string
get_fast_calib_param_path:
Returns the relative path to the fast calibration configurations folder as one string
get_calib_param_path:
Returns the relative path to the calibration configurations folder as one string
get_positioner_physics_path:
Returns the relative path to the positioner physics configurations folder as one string
get_positioner_requirements_path:
Returns the relative path to the positioner requirements configurations folder as one string
get_test_param_path:
Returns the relative path to the test configurations folder as one string
get_config_fileName:
Returns the relative path and filename of the configuration file as one string
get_current_testBench_fileName:
Returns the relative path and filename of the current testbench configuration file as one string
get_current_fast_calib_param_fileName:
Returns the relative path and filename of the current fast calibration configuration file as one string
get_current_calib_param_fileName:
Returns the relative path and filename of the current calibration configuration file as one string
get_current_positioner_physics_fileName:
Returns the relative path and filename of the current positioner physics configuration file as one string
get_current_positioner_requirements_fileName:
Returns the relative path and filename of the current positioner requirements configuration file as one string
get_current_test_param_fileName:
Returns the relative path and filename of the current test configuration file as one string
get_all_config_filenames:
Returns all the general configuration file names in a list of string
get_all_testbench_filenames:
Returns all the testbench configuration file names in a list of string
get_all_calib_filenames:
Returns all the calibration configuration file names in a list of string
get_all_test_filenames:
Returns all the test configuration file names in a list of string
get_all_positioner_physics_filenames:
Returns all the positioner physics configuration file names in a list of string
get_all_positioner_requirements_filenames:
Returns all the positioner requirements configuration file names in a list of string
save_positioners_model:
Saves the model of the positioners in the testbench.
load_positioners_model:
Loads the model of the positioners in the testbench.
load_calib_results:
Loads calibration results from already performed runs.
save_calib_results:
Saves the calibration results to the current run folder
load_test_results:
Loads test results from already performed runs.
save_test_results:
Saves the test results to the current run folder
load_firmware:
Reads a firmware binary file and returns the data needed for a firmware upgrade.
get_current_figure_folder:
Returns the current run's figure folder relative path
get_current_overview_folder:
Returns the overview folder relative path
get_overview_folder_cogging:
Returns the cogging overviews folder relative path
get_overview_folder_current:
Returns the current measurements overviews folder relative path
get_overview_folder_hardstops:
Returns the hardstop overviews folder relative path
get_figure_name_cogging:
Returns the cogging overview figure filename of the positioner
get_figure_name_current:
Returns the current measurements overview figure filename of the positioner
get_figure_name_hardstops:
Returns the hardstop overview figure filename of the positioner
get_overwiew_filename:
Returns the general overview figure filename of the positioner
get_current_positioner_folder:
Returns the current run's positioner folder.
get_all_project_names:
Returns a list containing the name of all the projects.
get_positioner_folder:
Returns the positioner folder.
get_latest_positioner_folder:
Returns the folder name of the latest run finished with this positioner, excluding the ongoing one.
get_all_common_test_subfolders:
Returns a list of folder names of previously done runs.
check_folder_is_lifetime:
Checks if the specified folder contains lifetime iterations or not.
save_QC_result:
Creates the entries of the calibResults and testResults in the Quality Control file.
"""
__slots__ = ( 'currentProjectTime',\
'generalProjectFolder',\
'currentProjectFolder',\
'resultFolder',\
'positionerFolderPrefix',\
'positionerFolderSuffix',\
'lifetimeSuffix',\
'figureFolder',\
'overviewsFolder',\
'overviewCogging',\
'overviewCurrent',\
'overviewHardstops',\
'figureExtension',\
'overviewExtension',\
'resultsOverviewFile',\
'resultsOverviewAutosave',\
'lockFile',\
'positionerModelFile',\
'positionerModelExtension',\
'figureNameCogging',\
'figureNameCurrent',\
'figureNameHardstops',\
'generalConfigFolder',\
'testBenchFolder',\
'cameraFolder',\
'firmwaresFolder',\
'positionersFolder',\
'requirementsFolder',\
'calibrationsFolder',\
'testsFolder',\
'configFolder',\
'resultsOverviewTemplateFile',\
'testBenchFileExtension',\
'cameraFileExtension',\
'positionersFileExtension',\
'requirementsFileExtension',\
'fastCalibrationsFileExtension',\
'calibrationsFileExtension',\
'testsFileExtension',\
'currentTestBenchFile',\
'currentPositionerFile',\
'currentRequirementsFile',\
'currentFastCalibrationFile',\
'currentCalibrationFile',\
'currentTestFile',\
'currentConfigFile',\
'configFileExtension',\
'calibrationResultsFile',\
'testResultsFile',\
'calibrationResultsFileExt',\
'testResultsFileExt',\
'lifetimeIterationFolderName',\
'resultsLoadingFolder',\
'preloadPositionerModel',\
'calibrateDatum',\
'calibrateMotor',\
'calibrateCogging',\
'forceMotorCalibration',\
'forceDatumCalibration',\
'forceCoggingCalibration',\
'nbMotorCalib',\
'nbDatumCalib',\
'nbCoggingCalib',\
'IDsToLoad',\
'preheatBenchTime',\
'preheatBench',\
'moveDuringPreheat',\
'doFastCalibRun',\
'doCalibRun',\
'overwritePositionerModel',\
'loadCalibRun',\
'doTestRun',\
'loadTestRun',\
'nbTestingLoops',\
'currentLifetimeIteration',\
'reloadCalibParEachIter',\
'reloadTestParEachIter',\
'doLivePlot',\
'plotResults',\
'saveInQc',\
'sendMail',\
'mailReceivers',\
'plotCoggingValues',\
'plotCurrentValues',\
'plotHardstopRepeatability',\
'nbHardstopRepeatabilityChecks',\
'upgradeFirmware',\
'firmwareUpgradeFile')
def __init__(self):
"""Initializes the class"""
self.currentProjectTime = time.strftime("%Y-%m-%d-%Hh%Mm%Ss", time.localtime(time.time()))
#project parameters
self.generalProjectFolder = 'Projects' #generalProjectFolder
self.currentProjectFolder = 'Blackbird' #generalProjectFolder\currentProjectFolder
self.resultFolder = 'All_calibrations' #generalProjectFolder\currentProjectFolder\resultFolder
self.positionerFolderPrefix = 'Positioner' #generalProjectFolder\currentProjectFolder\resultFolder\positionerFolderPrefix+positionerID\
self.positionerFolderSuffix = '' #generalProjectFolder\currentProjectFolder\resultFolder\positionerFolderPrefix+positionerID\currentProjectTime+positionerFolderSuffix
self.lifetimeSuffix = 'lifetime'
self.figureFolder = 'Figures' #generalProjectFolder\currentProjectFolder\resultFolder\positionerFolderPrefix+positionerID\currentProjectTime+positionerFolderSuffix\figureFolder
self.overviewsFolder = 'Overview' #generalProjectFolder\currentProjectFolder\overviewsFolder
self.overviewCogging = 'Cogging measures'
self.overviewCurrent = 'Current measures'
self.overviewHardstops = 'Hardstop repeatability measures'
self.figureExtension = '.png' #generalProjectFolder\currentProjectFolder\resultFolder\positionerFolderPrefix+positionerID\currentProjectTime+positionerFolderSuffix\figureFolder\*figureExtension
self.overviewExtension = '.png' #generalProjectFolder\currentProjectFolder\overviewsFolder\*overviewExtension
self.resultsOverviewFile = 'Results.xlsx' #generalProjectFolder\currentProjectFolder\resultsOverviewFile
self.resultsOverviewAutosave = 'Results_autosave.xlsx'
self.lockFile = '.lock'
self.positionerModelFile = 'Model' #generalProjectFolder\currentProjectFolder\resultFolder\positionerFolderPrefix+positionerID\positionerModelFile+positionerID
self.positionerModelExtension = '.json' #generalProjectFolder\currentProjectFolder\resultFolder\positionerFolderPrefix+positionerID\positionerModelFile+positionerID+positionerModelExtension
self.figureNameCogging = 'Cogging'
self.figureNameCurrent = 'Current'
self.figureNameHardstops = 'Hardstop'
#configuration files
self.generalConfigFolder = 'Config' #generalConfigFolder
self.testBenchFolder = 'TestBenches' #generalConfigFolder\testBenchFolder
self.cameraFolder = 'Cameras' #generalConfigFolder\cameraFolder
self.firmwaresFolder = 'Firmwares' #generalConfigFolder\firmwaresFolder
self.positionersFolder = 'Positioners' #generalConfigFolder\positionersFolder
self.requirementsFolder = 'Requirements' #generalConfigFolder\requirementsFolder
self.calibrationsFolder = 'Calibrations' #generalConfigFolder\calibrationsFolder
self.testsFolder = 'Tests' #generalConfigFolder\testsFolder
self.configFolder = 'General' #generalConfigFolder\configFolder
self.resultsOverviewTemplateFile = 'Results Template.xlsx'#generalConfigFolder\configFolder\resultsOverviewTemplateFile
self.configFileExtension = '.cnf' #generalConfigFolder\configFolder\*configFileExtension
self.testBenchFileExtension = '.tb' #generalConfigFolder\testBenchFolder\*testbenchFileExtension
self.cameraFileExtension = '.mat' #generalConfigFolder\cameraFolder\*cameraFileExtension
self.positionersFileExtension = '.pos' #generalConfigFolder\positionersFolder\*positionersFileExtension
self.requirementsFileExtension = '.rqm' #generalConfigFolder\requirementsFolder\*requirementsFileExtension
self.fastCalibrationsFileExtension = '.fcal' #generalConfigFolder\calibrationsFolder\*fastCalibrationsFileExtension
self.calibrationsFileExtension = '.cal' #generalConfigFolder\calibrationsFolder\*calibrationsFileExtension
self.testsFileExtension = '.tst' #generalConfigFolder\testsFolder\*testsFileExtension
self.currentConfigFile = DEFINES.DEFAULT_CONFIG_FILENAME #generalConfigFolder\testBenchFolder\currentTestbenchFile
self.currentTestBenchFile = '' #generalConfigFolder\testBenchFolder\currentTestbenchFile
self.currentPositionerFile = '' #generalConfigFolder\testBenchFolder\currentPositionerFile
self.currentRequirementsFile = '' #generalConfigFolder\testBenchFolder\currentRequirementsFile
self.currentFastCalibrationFile = '' #generalConfigFolder\calibrationsFolder\currentFastCalibrationFile
self.currentCalibrationFile = '' #generalConfigFolder\calibrationsFolder\currentCalibrationFile
self.currentTestFile = '' #generalConfigFolder\testsFolder\currentTestFile
#testing files output
self.calibrationResultsFile = 'calibResults' #GeneralProjectFolder\currentProjectFolder\resultFolder\positionerFolderPrefix+positionerID\currentProjectTime+positionerFolderSuffix\calibrationResultsFile
self.testResultsFile = 'testResults' #GeneralProjectFolder\currentProjectFolder\resultFolder\positionerFolderPrefix+positionerID\currentProjectTime+positionerFolderSuffix\testResultsFile
self.calibrationResultsFileExt = '.json' #GeneralProjectFolder\currentProjectFolder\resultFolder\positionerFolderPrefix+positionerID\currentProjectTime+positionerFolderSuffix\calibrationResultsFile+fileID+calibrationResultsFileExt
self.testResultsFileExt = '.json' #GeneralProjectFolder\currentProjectFolder\resultFolder\positionerFolderPrefix+positionerID\currentProjectTime+positionerFolderSuffix\testResultsFile+fileID+testResultsFileExt
self.lifetimeIterationFolderName = 'Iteration'
self.resultsLoadingFolder = DEFINES.CONFIG_LOAD_LATEST_RESULT #projectTime+folderSuffix DEFINES.CONFIG_LOAD_LATEST_RESULT
self.IDsToLoad = []
#program parameters
self.preloadPositionerModel = False
self.calibrateMotor = True
self.calibrateDatum = True
self.calibrateCogging = True
self.forceMotorCalibration = True
self.forceDatumCalibration = True
self.forceCoggingCalibration = True
self.nbMotorCalib = 10
self.nbDatumCalib = 100
self.nbCoggingCalib = 1
self.preheatBenchTime = DEFINES.CONFIG_PREHEAT_BENCH_DEFAULT_TIME
self.preheatBench = True
self.moveDuringPreheat = True
self.doFastCalibRun = True
self.doCalibRun = True
self.overwritePositionerModel = True
self.loadCalibRun = False
self.doTestRun = True
self.loadTestRun = False
self.nbTestingLoops = 1
self.currentLifetimeIteration = 0
self.reloadCalibParEachIter = False
self.reloadTestParEachIter = False
self.doLivePlot = False
self.sendMail = True
self.plotResults = True
self.saveInQc = True
self.mailReceivers = ['Stefane.Caseiro@mpsag.com', 'Julien.Arnould@mpsag.com']#,'luzius.kronig@epfl.ch','ricardo.araujo@epfl.ch']
self.plotCoggingValues = True
self.plotCurrentValues = True
self.plotHardstopRepeatability = True
self.nbHardstopRepeatabilityChecks = 50
self.upgradeFirmware = True
self.firmwareUpgradeFile = os.path.join(self.generalConfigFolder, self.firmwaresFolder, '4.1.15.bin')
def load(self,fileName):
"""
Loads the configuration parameters from a file
Parameters
----------
fileName: string
The path and name to the file containing the parameters
Raises
------
errors.IOError
If the configuration file could not be loaded\n
If RAISE_ERROR_ON_UNEXPECTED_KEY is True, then this error is also raised when unexpected data are encoutered in the file
"""
#Load all the data in the file, exculding the fileInfos
try:
with open(os.path.join(fileName),'r') as inFile:
variablesToLoad=json.load(inFile)
for key in variablesToLoad.keys():
if key in type(self).__slots__:
setattr(self, key, variablesToLoad[key])
else:
log.message(DEFINES.LOG_MESSAGE_PRIORITY_DEBUG_WARNING,1,f'Unexpected data was encountered during the loading of the general parameters. Faulty key: {key}')
if DEFINES.RAISE_ERROR_ON_UNEXPECTED_KEY:
raise errors.IOError('Unexpected data was encountered during the loading of the general parameters') from None
except OSError:
raise errors.IOError('The general parameters file could not be found') from None
def save(self,filePath,fileName):
"""
Saves the parameters in a file
Parameters
----------
filePath: string
The path where the file will be stored. If the path doesn't exist, it will be created.
fileName: string
The name of the file to save the parameters to.
"""
variablesToSave = {}
variablesToSave['currentConfigFile'] = self.currentConfigFile
variablesToSave['currentProjectFolder'] = self.currentProjectFolder
variablesToSave['positionerFolderSuffix'] = self.positionerFolderSuffix
variablesToSave['currentTestBenchFile'] = self.currentTestBenchFile
variablesToSave['currentPositionerFile'] = self.currentPositionerFile
variablesToSave['currentRequirementsFile'] = self.currentRequirementsFile
variablesToSave['currentFastCalibrationFile'] = self.currentFastCalibrationFile
variablesToSave['currentCalibrationFile'] = self.currentCalibrationFile
variablesToSave['currentTestFile'] = self.currentTestFile
variablesToSave['resultsLoadingFolder'] = self.resultsLoadingFolder
variablesToSave['IDsToLoad'] = self.IDsToLoad
variablesToSave['calibrateMotor'] = self.calibrateMotor
variablesToSave['calibrateDatum'] = self.calibrateDatum
variablesToSave['calibrateCogging'] = self.calibrateCogging
variablesToSave['forceMotorCalibration'] = self.forceMotorCalibration
variablesToSave['forceDatumCalibration'] = self.forceDatumCalibration
variablesToSave['forceCoggingCalibration'] = self.forceCoggingCalibration
variablesToSave['nbMotorCalib'] = self.nbMotorCalib
variablesToSave['nbDatumCalib'] = self.nbDatumCalib
variablesToSave['nbCoggingCalib'] = self.nbCoggingCalib
variablesToSave['preheatBenchTime'] = self.preheatBenchTime
variablesToSave['moveDuringPreheat'] = self.moveDuringPreheat
variablesToSave['preheatBench'] = self.preheatBench
variablesToSave['doFastCalibRun'] = self.doFastCalibRun
variablesToSave['doCalibRun'] = self.doCalibRun
variablesToSave['overwritePositionerModel'] = self.overwritePositionerModel
variablesToSave['loadCalibRun'] = self.loadCalibRun
variablesToSave['doTestRun'] = self.doTestRun
variablesToSave['loadTestRun'] = self.loadTestRun
variablesToSave['nbTestingLoops'] = self.nbTestingLoops
variablesToSave['doLivePlot'] = self.doLivePlot
variablesToSave['upgradeFirmware'] = self.upgradeFirmware
variablesToSave['firmwareUpgradeFile'] = self.firmwareUpgradeFile
variablesToSave['plotResults'] = self.plotResults
variablesToSave['saveInQc'] = self.saveInQc
variablesToSave['sendMail'] = self.sendMail
variablesToSave['mailReceivers'] = self.mailReceivers
variablesToSave['plotCoggingValues'] = self.plotCoggingValues
variablesToSave['plotCurrentValues'] = self.plotCurrentValues
variablesToSave['plotHardstopRepeatability'] = self.plotHardstopRepeatability
variablesToSave['nbHardstopRepeatabilityChecks'] = self.nbHardstopRepeatabilityChecks
os.makedirs(filePath, exist_ok=True)
if fileName != DEFINES.DEFAULT_CONFIG_FILENAME+self.configFileExtension:
with open(os.path.join(filePath, fileName),'w+') as outFile:
json.dump(variablesToSave, outFile, separators = (',\n',': '))
with open(os.path.join(filePath, DEFINES.DEFAULT_CONFIG_FILENAME+self.configFileExtension),'w+') as outFile:
json.dump(variablesToSave, outFile, separators = (',\n',': '))
def reset_project_time(self):
"""Resets the project time string (currentProjectTime) to be now"""
self.currentProjectTime = time.strftime("%Y-%m-%d-%Hh%Mm%Ss", time.localtime(time.time()))
def get_camera_path(self):
"""Returns the relative path to the camera distortion folder as one string"""
return os.path.join(self.generalConfigFolder,self.cameraFolder)
def get_config_path(self):
"""Returns the relative path to the general configurations folder as one string"""
return os.path.join(self.generalConfigFolder,self.configFolder)
def get_testbench_path(self):
"""Returns the relative path to the testbench configurations folder as one string"""
return os.path.join(self.generalConfigFolder,self.testBenchFolder)
def get_fast_calib_param_path(self):
"""Returns the relative path to the fast calibration configurations folder as one string"""
return os.path.join(self.generalConfigFolder, self.calibrationsFolder)
def get_calib_param_path(self):
"""Returns the relative path to the calibration configurations folder as one string"""
return os.path.join(self.generalConfigFolder, self.calibrationsFolder)
def get_positioner_physics_path(self):
"""Returns the relative path to the positioner physics configurations folder as one string"""
return os.path.join(self.generalConfigFolder, self.positionersFolder)
def get_positioner_requirements_path(self):
"""Returns the relative path to the positioner requirements configurations folder as one string"""
return os.path.join(self.generalConfigFolder, self.requirementsFolder)
def get_test_param_path(self):
"""Returns the relative path to the test configurations folder as one string"""
return os.path.join(self.generalConfigFolder, self.testsFolder)
def get_current_config_fileName(self):
"""Returns the relative path and filename of the configuration file as one string"""
return os.path.join(self.generalConfigFolder, self.configFolder, self.currentConfigFile + self.configFileExtension)
def get_current_testBench_fileName(self):
"""Returns the relative path and filename of the current testbench configuration file as one string"""
return os.path.join(self.generalConfigFolder, self.testBenchFolder, self.currentTestBenchFile + self.testBenchFileExtension)
def get_current_fast_calib_param_fileName(self):
"""Returns the relative path and filename of the current fast calibration configuration file as one string"""
return os.path.join(self.generalConfigFolder, self.calibrationsFolder, self.currentFastCalibrationFile+self.fastCalibrationsFileExtension)
def get_current_calib_param_fileName(self):
"""Returns the relative path and filename of the current calibration configuration file as one string"""
return os.path.join(self.generalConfigFolder, self.calibrationsFolder, self.currentCalibrationFile+self.calibrationsFileExtension)
def get_current_positioner_physics_fileName(self):
"""Returns the relative path and filename of the current positioner physics configuration file as one string"""
return os.path.join(self.generalConfigFolder, self.positionersFolder, self.currentPositionerFile+self.positionersFileExtension)
def get_current_positioner_requirements_fileName(self):
"""Returns the relative path and filename of the current positioner requirements configuration file as one string"""
return os.path.join(self.generalConfigFolder, self.requirementsFolder, self.currentRequirementsFile+self.requirementsFileExtension)
def get_current_test_param_fileName(self):
"""Returns the relative path and filename of the current test configuration file as one string"""
return os.path.join(self.generalConfigFolder, self.testsFolder, self.currentTestFile+self.testsFileExtension)
def get_all_config_filenames(self):
"""Returns all the general configuration file names in a list of string"""
filenames = []
for file in os.listdir(self.get_testbench_path()):
if file.endswith(self.testBenchFileExtension):
filenames.append(file)
return filenames
def get_all_testbench_filenames(self):
"""Returns all the testbench configuration file names in a list of string"""
filenames = []
for file in os.listdir(self.get_testbench_path()):
if file.endswith(self.testBenchFileExtension):
filenames.append(file)
return filenames
def get_all_calib_filenames(self):
"""Returns all the calibration configuration file names in a list of string"""
filenames = []
for file in os.listdir(self.get_calib_param_path()):
if file.endswith(self.calibrationsFileExtension):
filenames.append(file)
return filenames
def get_all_test_filenames(self):
"""Returns all the test configuration file names in a list of string"""
filenames = []
for file in os.listdir(self.get_test_param_path()):
if file.endswith(self.testsFileExtension):
filenames.append(file)
return filenames
def get_all_positioner_physics_filenames(self):
"""Returns all the positioner physics configuration file names in a list of string"""
filenames = []
for file in os.listdir(self.get_positioner_physics_path()):
if file.endswith(self.positionersFileExtension):
filenames.append(file)
return filenames
def get_all_positioner_requirements_filenames(self):
"""Returns all the positioner requirements configuration file names in a list of string"""
filenames = []
for file in os.listdir(self.get_positioner_requirements_path()):
if file.endswith(self.requirementsFileExtension):
filenames.append(file)
return filenames
def save_positioners_model(self, testBench):
"""
Saves the model of the positioners in the testbench.
Parameters
----------
testBench: classTestBench.TestBench
The testbench on which the calibration was performed. The positioners attached to the testbench
must have run or loaded a calibration and their internal model be updated prior to that function call.
"""
if testBench.canUSB is None:
invalidIDs = []
else:
invalidIDs = testBench.canUSB.invalidIDs
for positioner in (p for p in testBench.positioners if p.ID not in invalidIDs):
filePath = self.get_current_positioner_folder(positioner.ID)
fileName = self.positionerModelFile+self.positionerModelExtension
positioner.model.save(filePath, fileName)
filePath = os.path.join(self.generalProjectFolder,self.currentProjectFolder,self.resultFolder,self.positionerFolderPrefix+'_'+str(positioner.ID))
fileName = self.positionerModelFile+'_'+str(positioner.ID)+self.positionerModelExtension
if self.overwritePositionerModel or not os.path.exists(os.path.join(filePath,fileName)):
positioner.model.save(filePath, fileName)
def load_positioners_model(self, testBench):
"""
Loads the model of the positioners in the testbench.
Parameters
----------
testBench: classTestBench.TestBench
The testbench containing the positioners to which the model will be loaded.
Any positioner that has no model file will remain unchanged.
"""
if testBench.canUSB is None:
invalidIDs = []
else:
invalidIDs = testBench.canUSB.invalidIDs
for positioner in (p for p in testBench.positioners if p.ID not in invalidIDs):
filePath = os.path.join(self.generalProjectFolder,self.currentProjectFolder,self.resultFolder,self.positionerFolderPrefix+'_'+str(positioner.ID))
fileName = os.path.join(filePath,self.positionerModelFile+'_'+str(positioner.ID)+self.positionerModelExtension)
if os.path.exists(fileName):
positioner.model.load(fileName)
def load_calib_results(self, calibResults, positionerIDs, lifetimeLoop = 0):
"""
Loads calibration results from already performed runs.
Parameters
----------
calibResults: list of classCalibration.Results
A list containing the empty calibration results containers
positionerIDs: list of uint
The list containing the IDs of the positioners to load
lifetimeLoop: uint
The current lifetime iteration. Unused if self.nbTestingLoops = 1.
Raises
------
errors.IOError:
If the positioner doesn't have the "self.resultFolder" folder\n
If the calibration results loading failed
"""
if len(calibResults) is not len(positionerIDs):
raise errors.Error("Calibration result container has the wrong length") from None
filePath = os.path.join( self.generalProjectFolder,\
self.currentProjectFolder,\
self.resultFolder)
i = 0
for positionerID in positionerIDs:
if self.resultsLoadingFolder == DEFINES.CONFIG_LOAD_LATEST_RESULT:
resultPath = self.get_latest_positioner_folder(positionerID)
if resultPath == '':
raise errors.IOError(f'Positioner {positionerID:04.0f} results folder not found') from None
else:
resultPath = self.resultsLoadingFolder
resultPath = os.path.join( filePath,\
self.positionerFolderPrefix+'_'+str(positionerID),\
resultPath)
if self.check_folder_is_lifetime(resultPath):
resultPath = os.path.join( resultPath,\
self.lifetimeIterationFolderName+'_'+str(lifetimeLoop+1))
try:
calibResults[i].load(os.path.join( resultPath,\
self.calibrationResultsFile+self.calibrationResultsFileExt))
except errors.IOError as e:
log.message(DEFINES.LOG_MESSAGE_PRIORITY_ERROR,0,str(e))
raise errors.IOError(f'Positioner {positionerID:04.0f} calibration results loading failed') from None
i += 1
def save_calib_results(self, calibResults, invalidIDs = []):
"""
Saves the calibration results to the current run folder
Parameters
----------
calibResults: list of classCalibration.Results
A list containing the calibration results at any stage
invalidIDs: list of uint, optional
The list containing the invalid positioner IDs. The results matching this ID will not be saved.
"""
for currentResult in calibResults:
if currentResult.positionerID not in invalidIDs:
filePath = self.get_current_positioner_folder(currentResult.positionerID)
fileName = self.calibrationResultsFile+self.calibrationResultsFileExt
currentResult.save(filePath, fileName)
def load_test_results(self, testResults, positionerIDs, lifetimeLoop = 0):
"""
Loads test results from already performed runs.
Parameters
----------
testResults: list of classTest.Results
A list containing the empty test results containers
positionerIDs: list of uint
The list containing the IDs of the positioners to load
lifetimeLoop: uint
The current lifetime iteration. Unused if self.nbTestingLoops = 1.
Raises
------
errors.IOError:
If the positioner doesn't have the "self.resultFolder" folder\n
If the test results loading failed
"""
if len(testResults) is not len(positionerIDs):
raise errors.Error("Test result container has the wrong length") from None
filePath = os.path.join( self.generalProjectFolder,\
self.currentProjectFolder,\
self.resultFolder)
i = 0
for positionerID in positionerIDs:
if self.resultsLoadingFolder == DEFINES.CONFIG_LOAD_LATEST_RESULT:
resultPath = self.get_latest_positioner_folder(positionerID)
if resultPath == '':
raise errors.IOError(f'Positioner {positionerID:04.0f} results folder not found') from None
else:
resultPath = self.resultsLoadingFolder
resultPath = os.path.join( filePath,\
self.positionerFolderPrefix+'_'+str(positionerID),\
resultPath)
if self.check_folder_is_lifetime(resultPath):
resultPath = os.path.join( resultPath,\
self.lifetimeIterationFolderName+'_'+str(lifetimeLoop+1))
try:
testResults[i].load(os.path.join( resultPath,\
self.testResultsFile+self.testResultsFileExt))
except errors.IOError:
raise errors.IOError(f'Positioner {positionerID:04.0f} test results loading failed') from None
i += 1
def save_test_results(self, testResults, invalidIDs = []):
"""
Saves the test results to the current run folder
Parameters
----------
testResults: list of classTest.Results
A list containing the test results at any stage
invalidIDs: list of uint, optional
The list containing the invalid positioner IDs. The results matching this ID will not be saved.
"""
for currentResult in testResults:
if currentResult.positionerID not in invalidIDs:
filePath = self.get_current_positioner_folder(currentResult.positionerID)
fileName = self.testResultsFile+self.testResultsFileExt
currentResult.save(filePath, fileName)
def load_firmware(self):
"""
Reads a firmware binary file and returns the data needed for a firmware upgrade.
The file full path is specified in self.firmwareUpgradeFile. It must be a vaild binary file.
Returns
-------
Tuple: firmwareLength, firmwareChecksum, firmwareFrames
firmwareLength: int
The number of Bytes in the file
firmwareChecksum: int
The file checksum using zlib.crc32
firmwareFrames: list of hexadecimal strings
A list of 8 Bytes hexadecimal frames in the correct order. The last item in the list may not be the same length depending on the input file.
version: string
The version of the new firmware based on the filename
Raises
------
errors.IOError
If the file could not be read correctly or was not found
"""
#read the new firmware and return the frames to send
firmwareData = []
firmwareFrames = []
try:
with open(self.firmwareUpgradeFile, 'rb') as file:
firmwareData = file.read()
version = os.path.basename(self.firmwareUpgradeFile).split('.')
version = version[0]+'.'+version[1]+'.'+version[2]
except:
raise errors.IOError("The firmware file could not be read") from None
firmwareLength = len(firmwareData)
firmwareChecksum = zlib.crc32(firmwareData)
n = 8 #as we want max 8 Bytes per frame
firmwareFrames = [(firmwareData[i:i+n]).hex() for i in range(0, len(firmwareData), n)]
return firmwareLength, firmwareChecksum, firmwareFrames, version
def get_current_figure_folder(self, positionerID):
"""
Returns the current run's figure folder relative path
Parameters
----------
positionerID: uint
The ID of the positioner
Returns
-------
string:
The relative path to the positioner's current run figure folder
"""
filePath = os.path.join( self.get_current_positioner_folder(positionerID),\