Skip to content

Commit

Permalink
Upgraded minor_servos with setup table
Browse files Browse the repository at this point in the history
  • Loading branch information
giuseppe-carboni committed May 18, 2024
1 parent b33c2d1 commit c779b83
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 5 deletions.
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
}
)
21 changes: 16 additions & 5 deletions simulators/minor_servos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -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):
Expand Down
42 changes: 42 additions & 0 deletions simulators/minor_servos/helpers.py
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions simulators/minor_servos/setup.csv
Original file line number Diff line number Diff line change
@@ -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,*,*,*,*,*,*,*,*,*,*,*,*,*;

0 comments on commit c779b83

Please sign in to comment.