From c779b8330d6c96719fb2177a7cb462f3f5517704 Mon Sep 17 00:00:00 2001 From: Giuseppe Carboni Date: Sat, 18 May 2024 14:32:21 +0200 Subject: [PATCH] Upgraded minor_servos with setup table --- setup.py | 4 +++ simulators/minor_servos/__init__.py | 21 +++++++++++---- simulators/minor_servos/helpers.py | 42 +++++++++++++++++++++++++++++ simulators/minor_servos/setup.csv | 14 ++++++++++ 4 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 simulators/minor_servos/helpers.py create mode 100644 simulators/minor_servos/setup.csv diff --git a/setup.py b/setup.py index 543ebd7..0363412 100644 --- a/setup.py +++ b/setup.py @@ -13,4 +13,8 @@ 'Operating System :: OS Independent', 'Programming Language :: Python :: 3.10.7', ], + include_package_data=True, + package_data={ + 'simulators': ['minor_servos/setup.csv'] + } ) diff --git a/simulators/minor_servos/__init__.py b/simulators/minor_servos/__init__.py index f93eced..356dbf5 100644 --- a/simulators/minor_servos/__init__.py +++ b/simulators/minor_servos/__init__.py @@ -17,6 +17,7 @@ from bisect import bisect_left from socketserver import ThreadingTCPServer from simulators.common import ListeningSystem +from simulators.minor_servos.helpers import setup_import # Each system module (like active_surface.py, acu.py, etc.) has to @@ -96,6 +97,10 @@ def __init__(self, timer_value=DEFAULT_TIMER_VALUE): 'DR_GFR3': Derotator('GFR3'), 'DR_PFP': Derotator('PFP'), } + setup_import( + list(self.servos.keys()) + ['GREGORIAN_CAP'], + self.configurations + ) self.stop = Value(c_bool, False) self.update_thread = Thread( target=self._update, @@ -184,8 +189,10 @@ def _setup(self, args): configuration = args[0] if configuration not in self.configurations: return self.bad - self.configuration = self.configurations.get(configuration)['ID'] - for _, servo in self.servos.items(): + configuration = self.configurations.get(configuration) + self.configuration = configuration['ID'] + for servo_name, servo in self.servos.items(): + coordinates = configuration[servo_name] servo.operative_mode_timer.cancel() _change_atomic_value(servo.operative_mode, 0) servo.operative_mode_timer = Timer( @@ -195,8 +202,10 @@ def _setup(self, args): ) servo.operative_mode_timer.daemon = True servo.operative_mode_timer.start() - gregorian_cap_position = 1 if self.configuration == 1 else 2 - if self.gregorian_cap.value != gregorian_cap_position: + servo.set_coords(coordinates) + gregorian_cap_position = configuration['GREGORIAN_CAP'][0] + if (gregorian_cap_position + and self.gregorian_cap.value != gregorian_cap_position): _change_atomic_value(self.gregorian_cap, 0) self.cover_timer = Timer( self.timer_value, @@ -488,7 +497,9 @@ def get_status(self, now): def set_coords(self, coords): for index, value in enumerate(coords): - self.coords[index] = value + if not value: + continue + self.coords[index] = value + self.offsets[index] def set_offsets(self, coords): for index, value in enumerate(coords): diff --git a/simulators/minor_servos/helpers.py b/simulators/minor_servos/helpers.py new file mode 100644 index 0000000..8f1f566 --- /dev/null +++ b/simulators/minor_servos/helpers.py @@ -0,0 +1,42 @@ +import os +import csv +import pkg_resources + + +def setup_import(servos, configurations): + filename = os.environ.get('ACS_CDB', '/') + filename = os.path.join( + filename, + 'CDB', + 'alma', + 'DataBlock', + 'MinorServo', + 'Tabella Setup.csv' + ) + if not os.path.exists(filename): + filename = pkg_resources.resource_filename( + 'simulators', + 'minor_servos/setup.csv' + ) + with open(filename, 'r', encoding='utf-8') as csvfile: + reader = csv.reader(csvfile) + indexes = {} + for line in reader: + if not indexes: + for servo in servos: + temp = [e for e in line if e.startswith(servo)] + indexes[servo] = [line.index(e) for e in temp] + continue + for servo, servo_indexes in indexes.items(): + coordinates = [] + for index in servo_indexes: + coord = line[index].replace(';', '') + try: + if servo == 'GREGORIAN_CAP': + coord = int(coord) + else: + coord = float(coord) + except ValueError: + coord = None + coordinates.append(coord) + configurations[line[0]][servo] = coordinates diff --git a/simulators/minor_servos/setup.csv b/simulators/minor_servos/setup.csv new file mode 100644 index 0000000..197cac4 --- /dev/null +++ b/simulators/minor_servos/setup.csv @@ -0,0 +1,14 @@ +CONFIGURATION,PFP_TX,PFP_TZ,PFP_RTHETA,SRP_TX,SRP_TY,SRP_TZ,SRP_RX,SRP_RY,SRP_RZ,M3R_RZ,GFR_RZ,DR_GFR1,DR_GFR2,DR_GFR3,DR_PFP,GREGORIAN_CAP; +Primario,0,0,0,-5,5,-120,0,0,0,*,*,*,*,*,*,1; +Gregoriano1,0,0,0,-1.5,11.1393650793988,1.08830677049999,0.049894179898239,-0.036111111111111,0,*,-88.70659,*,*,*,*,2; +Gregoriano2,0,0,0,-1.5,11.1393650793988,1.08830677049999,0.049894179898239,-0.036111111111111,0,*,-159.8899,*,*,*,*,2; +Gregoriano3,0,0,0,-1.5,11.1393650793988,1.08830677049999,0.049894179898239,-0.036111111111111,0,*,90.97161,*,*,*,*,2; +Gregoriano4,0,0,0,-1.5,11.1393650793988,1.08830677049999,0.049894179898239,-0.036111111111111,0,*,162.771,*,*,*,*,2; +Gregoriano5,0,0,0,-1.5,11.1393650793988,1.08830677049999,0.049894179898239,-0.036111111111111,0,*,55.373967,*,*,*,*,2; +Gregoriano6,0,0,0,-1.5,11.1393650793988,1.08830677049999,0.049894179898239,-0.036111111111111,0,*,-51.82117,*,*,*,*,2; +Gregoriano7,0,0,0,*,*,*,*,*,*,*,*,*,*,*,*,*; +Gregoriano8,0,0,0,*,*,*,*,*,*,*,*,*,*,*,*,*; +BWG1,0,0,0,-1.5,11.1393650793988,0.358165166130078,0.049894179898239,-0.036111111111111,0,10,0,*,*,*,*,2; +BWG2,0,0,0,*,*,*,*,*,*,*,*,*,*,*,*,*; +BWG3,0,0,0,-1.5,11.1393650793988,-3.77159716192807,0.049894179898239,-0.036111111111111,0,20,0,*,*,*,*,2; +BWG4,0,0,0,*,*,*,*,*,*,*,*,*,*,*,*,*;