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

1#!/usr/bin/env python 

2# -*- coding: utf-8 -*- 

3import math 

4 

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 

9 

10import logging 

11 

12logger = logging.getLogger(__name__) 

13 

14 

15class LimitsProperty(HardwareProperty): 

16 def translate_from(self, value): 

17 if value is None: 

18 return [None, None] 

19 

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 

31 

32 

33class StateProperty(HardwareProperty): 

34 def translate_from(self, value): 

35 if value is None: 

36 return ["UNKNOWN"] 

37 

38 states = [] 

39 for s in MotorStates: 

40 if s in value: 

41 states.append(s) 

42 

43 if len(states): 

44 return states 

45 

46 return ["UNKNOWN"] 

47 

48 

49class PositionProperty(HardwareProperty): 

50 def translate_from(self, value): 

51 if value is None: 

52 return None 

53 

54 if math.isnan(value): 

55 return None 

56 

57 return round(value, 4) 

58 

59 

60class NoneIfNotImplementedProperty(CouldBeNotImplementedProperty): 

61 """Acceleration and velocity can not be exposed in case of a 

62 CalcController""" 

63 

64 def notImplementedValue(self): 

65 """Returned if the property is not implemented in the hardware""" 

66 return None 

67 

68 

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 } 

83 

84 CALLABLE_MAP = {"stop": "stop", "wait": "wait_move"} 

85 

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) 

90 

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)