From 271e52bcf9752ace4d60e8bbd506e288c1d74b51 Mon Sep 17 00:00:00 2001
From: Jens Meyer <jens.meyer@esrf.fr>
Date: Mon, 10 Aug 2020 16:17:55 +0200
Subject: [PATCH] Added RUNNING state to indicate the the robot movement was
 paused when entering the hutch. The movement will resume when the hutch is
 closed.

---
 SampleChangerDS/TomoSampleChanger.py  | 77 ++++++++++++++++-----------
 SampleChangerDS/TomoSampleChanger.xmi |  4 +-
 2 files changed, 49 insertions(+), 32 deletions(-)

diff --git a/SampleChangerDS/TomoSampleChanger.py b/SampleChangerDS/TomoSampleChanger.py
index d336e8e..e2c2594 100644
--- a/SampleChangerDS/TomoSampleChanger.py
+++ b/SampleChangerDS/TomoSampleChanger.py
@@ -19,14 +19,14 @@ handle all functionality of the robot.
 """
 
 # PyTango imports
-import PyTango
-from PyTango import DebugIt
-from PyTango.server import run
-from PyTango.server import Device, DeviceMeta
-from PyTango.server import attribute, command
-from PyTango.server import device_property
-from PyTango import AttrQuality, DispLevel, DevState
-from PyTango import AttrWriteType, PipeWriteType
+import tango
+from tango import DebugIt
+from tango.server import run
+from tango.server import Device
+from tango.server import attribute, command
+from tango.server import device_property
+from tango import AttrQuality, DispLevel, DevState
+from tango import AttrWriteType, PipeWriteType
 # Additional import
 # PROTECTED REGION ID(TomoSampleChanger.additionnal_import) ENABLED START #
 
@@ -50,8 +50,17 @@ class TomoSampleChanger(Device):
     The robot can be installed on different tomgraphy end stations and aligns itself with the set-up used.
     The class used the StaubLink/StaubPy/id19Controller.py of the StaubLink project on the ESRF Gitlab to 
     handle all functionality of the robot.
+
+    **Properties:**
+
+    - Device Property
+        sampleLoaded
+            - Is the sample loaded
+            - Type:'DevBoolean'
+        samplePosition
+            - The position of the loaded sample
+            - Type:'DevString'
     """
-    __metaclass__ = DeviceMeta
     # PROTECTED REGION ID(TomoSampleChanger.class_variable) ENABLED START #
     
     green_mode = PyTango.GreenMode.Gevent
@@ -273,11 +282,13 @@ class TomoSampleChanger(Device):
     # -----------------
 
     sampleLoaded = device_property(
-        dtype='bool', default_value=False
+        dtype='DevBoolean',
+        default_value=False
     )
 
     samplePosition = device_property(
-        dtype='str', default_value="None"
+        dtype='DevString',
+        default_value="None"
     )
 
     # ----------
@@ -285,48 +296,48 @@ class TomoSampleChanger(Device):
     # ----------
 
     SamplePosition = attribute(
-        dtype='str',
+        dtype='DevString',
     )
 
     SampleLoaded = attribute(
-        dtype='bool',
+        dtype='DevBoolean',
         label="Sample loaded",
         doc="The name of the sample currently loaded",
     )
 
     Aligned = attribute(
-        dtype='bool',
+        dtype='DevBoolean',
         doc="Sample changer aligned with tomograph end station",
     )
 
     ParkingPosition = attribute(
-        dtype='bool',
+        dtype='DevBoolean',
     )
 
     RemoteMode = attribute(
-        dtype='bool',
+        dtype='DevBoolean',
     )
 
     AirPressureOK = attribute(
-        dtype='bool',
+        dtype='DevBoolean',
         label="Air pressure OK",
         doc="True when the air pressure is not to high nor to low.",
     )
 
     WagoOK = attribute(
-        dtype='bool',
+        dtype='DevBoolean',
         label="Wago OK",
         doc="True when the connection to the interlock Wago controller is alive.",
     )
 
     TomographUsed = attribute(
-        dtype='str',
+        dtype='DevString',
         label="Tomograph used",
         doc="The name of the tomography end station where the sample changer is installed.",
     )
 
     RobotLibraryName = attribute(
-        dtype='str',
+        dtype='DevString',
         label="Robot Library Name",
     )
 
@@ -335,6 +346,7 @@ class TomoSampleChanger(Device):
     # ---------------
 
     def init_device(self):
+        """Initialises the attributes and properties of the TomoSampleChanger."""
         Device.init_device(self)
         # PROTECTED REGION ID(TomoSampleChanger.init_device) ENABLED START #
         
@@ -406,15 +418,21 @@ class TomoSampleChanger(Device):
         # PROTECTED REGION END #    //  TomoSampleChanger.init_device
 
     def always_executed_hook(self):
+        """Method always executed before any TANGO command is executed."""
         # PROTECTED REGION ID(TomoSampleChanger.always_executed_hook) ENABLED START #
         pass
         # PROTECTED REGION END #    //  TomoSampleChanger.always_executed_hook
 
     def delete_device(self):
+        """Hook to delete resources allocated in init_device.
+
+        This method allows for any memory or other resources allocated in the
+        init_device method to be released.  This method is called by the device
+        destructor and by the device Init command.
+        """
         # PROTECTED REGION ID(TomoSampleChanger.delete_device) ENABLED START #
         pass
         # PROTECTED REGION END #    //  TomoSampleChanger.delete_device
-
     # ------------------
     # Attributes methods
     # ------------------
@@ -490,7 +508,6 @@ class TomoSampleChanger(Device):
         
         # PROTECTED REGION END #    //  TomoSampleChanger.RobotLibraryName_read
 
-
     # --------
     # Commands
     # --------
@@ -510,8 +527,9 @@ class TomoSampleChanger(Device):
                 else:
                     if  self.is_moving == True:
                         # pause mode activated
+                        # The hutch was opened, the movemeny is inerrupted and will resume on hutch closure
                         if self.robot.power() == 0:
-                            _state = PyTango.DevState.PAUSE
+                            _state = PyTango.DevState.RUNNING
                         else:
                             _state = PyTango.DevState.MOVING
                     else:
@@ -542,8 +560,8 @@ class TomoSampleChanger(Device):
             if state == PyTango.DevState.DISABLE:
                 self._status += "DISABLED"
             else:
-                if state == PyTango.DevState.PAUSE:
-                    self._status += "PAUSE"
+                if state == PyTango.DevState.RUNNING:
+                    self._status += "PAUSE, movement is paused due to hutch opening"
                 else:
                     if state == PyTango.DevState.MOVING:
                         self._status += "MOVING"
@@ -587,9 +605,6 @@ class TomoSampleChanger(Device):
                     self._status += "\nReading of the robot status failed\n"
                     self._status += "\n"
                     self._status += str(self.state_error)
-                else:
-                    if state == PyTango.DevState.PAUSE:
-                        self._status += "\nGo to the robot teach pendant and follows instructions\n"
                         
         self.set_status(self._status)
         return self._status
@@ -597,8 +612,8 @@ class TomoSampleChanger(Device):
         # PROTECTED REGION END #    //  TomoSampleChanger.Status
 
     @command(
-    dtype_in='str', 
-    doc_in="Sample to load", 
+        dtype_in='DevString',
+        doc_in="Sample to load",
     )
     @DebugIt()
     def LoadSample(self, argin):
@@ -804,6 +819,7 @@ class TomoSampleChanger(Device):
 
 
 def main(args=None, **kwargs):
+    """Main function of the TomoSampleChanger module."""
     # PROTECTED REGION ID(TomoSampleChanger.main) ENABLED START #
     
     # Enable gevents for the server
@@ -812,5 +828,6 @@ def main(args=None, **kwargs):
     
     # PROTECTED REGION END #    //  TomoSampleChanger.main
 
+
 if __name__ == '__main__':
     main()
diff --git a/SampleChangerDS/TomoSampleChanger.xmi b/SampleChangerDS/TomoSampleChanger.xmi
index 7d8e092..b58e98d 100644
--- a/SampleChangerDS/TomoSampleChanger.xmi
+++ b/SampleChangerDS/TomoSampleChanger.xmi
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="ASCII"?>
 <pogoDsl:PogoSystem xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pogoDsl="http://www.esrf.fr/tango/pogo/PogoDsl">
-  <classes name="TomoSampleChanger" pogoRevision="9.6">
+  <classes name="TomoSampleChanger" pogoRevision="9.7">
     <description description="Handles the sample changer robot for micro tomography on ID19.&#xA;The robot can be installed on different tomgraphy end stations and aligns itself with the set-up used.&#xA;The class used the StaubLink/StaubPy/id19Controller.py of the StaubLink project on the ESRF Gitlab to &#xA;handle all functionality of the robot." title="Sample changer for micro tomography on ID19" sourcePath="/mntdirect/_users/meyer/ID19/SampleChanger/SampleChangerDS" language="PythonHL" filestogenerate="XMI   file,Code files,Protected Regions" license="GPL" copyright="Copyright (C): 2018&#xA;               European Synchrotron Radiation Facility&#xA;               BP 220, Grenoble 38043&#xA;               France" hasMandatoryProperty="false" hasConcreteProperty="true" hasAbstractCommand="false" hasAbstractAttribute="false">
       <inheritances classname="Device_Impl" sourcePath=""/>
       <identification contact="at esrf.fr - meyer" author="meyer" emailDomain="esrf.fr" classFamily="BeamlineComponents" siteSpecific="" platform="Unix Like" bus="Not Applicable" manufacturer="none" reference=""/>
@@ -211,7 +211,7 @@
     <states name="MOVING" description="Moving to load, unload or align">
       <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
     </states>
-    <states name="PAUSE" description="Waiting for restart">
+    <states name="RUNNING" description="The robot movement was stopped to enter the hutch. The movement will resume &#xA;when the hutch will be closed.">
       <status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
     </states>
     <states name="FAULT" description="Requested movement failed.">
-- 
GitLab