Coverage for /opt/conda/envs/apienv/lib/python3.10/site-packages/daiquiri/core/hardware/abstract/motor.py: 95%

39 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2025-02-06 02:13 +0000

1#!/usr/bin/env python 

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

3from marshmallow import fields 

4 

5from daiquiri.core.hardware.abstract import HardwareObject 

6from daiquiri.core.schema.hardware import HardwareSchema 

7from daiquiri.core.schema.validators import RequireEmpty 

8 

9import logging 

10 

11logger = logging.getLogger(__name__) 

12 

13MotorStates = [ 

14 "READY", 

15 "MOVING", 

16 "FAULT", 

17 "UNKNOWN", 

18 "DISABLED", 

19 "LOWLIMIT", 

20 "HIGHLIMIT", 

21 "HOME", 

22 "OFF", 

23] 

24 

25 

26class MotorPropertiesSchema(HardwareSchema): 

27 position = fields.Float() 

28 target = fields.Float() 

29 tolerance = fields.Float() 

30 acceleration = fields.Float() 

31 velocity = fields.Float() 

32 

33 limits = fields.List(fields.Float(), metadata={"length": 2}) 

34 """Limits for the position, such as limits[0] <= position <= limits[1]""" 

35 

36 state = fields.List( 

37 fields.Str(metadata={"enum": MotorStates}), metadata={"readOnly": True} 

38 ) 

39 """List of actual state of the motor. 

40 

41 Extra unofficial state can also be exposed with the following template: 

42 

43 - `_MYSTATE:The state description` 

44 

45 It have to be prefixed with an underscore, and can have a colon 

46 separator with a description. 

47 """ 

48 

49 unit = fields.Str(metadata={"readOnly": True}) 

50 offset = fields.Float() 

51 sign = fields.Int() 

52 display_digits = fields.Int(allow_none=True, metadata={"readOnly": True}) 

53 

54 

55class MotorCallablesSchema(HardwareSchema): 

56 move = fields.Float() 

57 rmove = fields.Float() 

58 stop = RequireEmpty() 

59 wait = RequireEmpty() 

60 

61 

62class Motor(HardwareObject): 

63 _type = "motor" 

64 _state_ok = [MotorStates[0], MotorStates[1]] 

65 

66 _properties = MotorPropertiesSchema() 

67 _callables = MotorCallablesSchema() 

68 

69 def rmove(self, value): 

70 self.call("rmove", value) 

71 

72 def move(self, value): 

73 self.call("move", value) 

74 

75 def stop(self): 

76 self.call("stop", None) 

77 

78 def wait(self): 

79 self.call("wait", None)