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

38 statements  

« prev     ^ index     » next       coverage.py v7.6.5, created at 2024-11-15 02:12 +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] 

22 

23 

24class MotorPropertiesSchema(HardwareSchema): 

25 position = fields.Float() 

26 target = fields.Float() 

27 tolerance = fields.Float() 

28 acceleration = fields.Float() 

29 velocity = fields.Float() 

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

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

32 state = fields.List( 

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

34 ) 

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

36 offset = fields.Float() 

37 sign = fields.Int() 

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

39 

40 

41class MotorCallablesSchema(HardwareSchema): 

42 move = fields.Float() 

43 rmove = fields.Float() 

44 stop = RequireEmpty() 

45 wait = RequireEmpty() 

46 

47 

48class Motor(HardwareObject): 

49 _type = "motor" 

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

51 

52 _properties = MotorPropertiesSchema() 

53 _callables = MotorCallablesSchema() 

54 

55 def rmove(self, value): 

56 self.call("rmove", value) 

57 

58 def move(self, value): 

59 self.call("move", value) 

60 

61 def stop(self): 

62 self.call("stop", None) 

63 

64 def wait(self): 

65 self.call("wait", None)