Coverage for /opt/conda/envs/apienv/lib/python3.10/site-packages/daiquiri/core/hardware/bliss/motor.py: 86%
50 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-14 02:13 +0000
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-14 02:13 +0000
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3import math
5from daiquiri.core.hardware.abstract import HardwareProperty
6from daiquiri.core.hardware.abstract.motor import Motor as AbstractMotor, MotorStates
7from daiquiri.core.hardware.bliss.object import BlissObject
8from daiquiri.core.hardware.bliss.object import CouldBeNotImplementedProperty
10import logging
12logger = logging.getLogger(__name__)
15class LimitsProperty(HardwareProperty):
16 def translate_from(self, value):
17 if value is None:
18 return [None, None]
20 value = list(value)
21 for i, v in enumerate(value):
22 if math.isinf(v):
23 if v < 0:
24 value[i] = -999999999
25 else:
26 value[i] = 999999999
27 if value[0] > value[1]:
28 # BLISS returns the biggest value first, when the sign is negative
29 return value[::-1]
30 return value
33class StateProperty(HardwareProperty):
34 def translate_from(self, value):
35 if value is None:
36 return ["UNKNOWN"]
38 states = []
39 for s in MotorStates:
40 if s in value:
41 states.append(s)
43 if len(states):
44 return states
46 return ["UNKNOWN"]
49class PositionProperty(HardwareProperty):
50 def translate_from(self, value):
51 if value is None:
52 return None
54 if math.isnan(value):
55 return None
57 return round(value, 4)
60class NoneIfNotImplementedProperty(CouldBeNotImplementedProperty):
61 """Acceleration and velocity can not be exposed in case of a
62 CalcController"""
64 def notImplementedValue(self):
65 """Returned if the property is not implemented in the hardware"""
66 return None
69class Motor(BlissObject, AbstractMotor):
70 PROPERTY_MAP = {
71 "position": PositionProperty("position"),
72 "target": PositionProperty("_set_position"),
73 "tolerance": HardwareProperty("tolerance"),
74 "acceleration": NoneIfNotImplementedProperty("acceleration"),
75 "velocity": NoneIfNotImplementedProperty("velocity"),
76 "limits": LimitsProperty("limits"),
77 "state": StateProperty("state"),
78 "unit": HardwareProperty("unit"),
79 "offset": HardwareProperty("offset"),
80 "sign": HardwareProperty("sign"),
81 "display_digits": HardwareProperty("display_digits"),
82 }
84 CALLABLE_MAP = {"stop": "stop", "wait": "wait_move"}
86 # Call moves with wait=False
87 def _call_move(self, value, **kwargs):
88 logger.debug(f"_call_move {self.name()} {value} {kwargs}")
89 self._object.move(value, wait=False)
91 def _call_rmove(self, value, **kwargs):
92 logger.debug(f"_call_rmove {self.name()} {value} {kwargs}")
93 self._object.move(value, wait=False, relative=True)