Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bring piezo screws constraints management inline with best practice #28

Open
mvbnano opened this issue Feb 14, 2018 · 2 comments
Open

Comments

@mvbnano
Copy link
Member

mvbnano commented Feb 14, 2018

What is affected by this bug?

Constraints management for newfocus pieze screws needs to be inline with best practice.

When does this occur?

Currently, the config is loaded and the constraints are set as class variables in on_activate.

Where on the platform does it happen?

In piezo_screws_newfocus.py on branch dev_newfocus_screws .

Expected behavior (i.e. solution)

Constraints should be loaded in get_constraints. A dictionary is returned here, which can then be made a class variable, ie something like this:

    def on_activate(self):
        """ Initialisation performed during activation of the module.
        @return: error code
        """

        # TODO: get these from config
        self.vendor_id = 0x104d
        self.product_id = 0x4000

        # find our device
        self.dev = usb.core.find(idVendor=self.vendor_id, idProduct=self.product_id)

        # was it found?
        if self.dev is None:
            raise ValueError('Device not found')
            return 1

        # set the active configuration. With no arguments, the first
        # configuration will be the active one
        self.dev.set_configuration()

        # get an endpoint instance
        cfg = self.dev.get_active_configuration()
        intf = cfg[(0,0)]

        self.ep_out = usb.util.find_descriptor(
            intf,
            # match the first OUT endpoint
            custom_match = 
            lambda e: 
                usb.util.endpoint_direction(e.bEndpointAddress) == 
                usb.util.ENDPOINT_OUT)

        assert self.ep_out is not None
        assert self.ep_out.wMaxPacketSize == 64

        self.ep_in = usb.util.find_descriptor(
            intf,
            # match the first OUT endpoint
            custom_match = 
            lambda e: 
                usb.util.endpoint_direction(e.bEndpointAddress) == 
                usb.util.ENDPOINT_IN)

        assert self.ep_in is not None
        assert self.ep_in.wMaxPacketSize == 64

        self.constraints = self.get_constrains()

        self._go_to_original_home()

        return 0
    def get_constraints(self):
        """ Retrieve the hardware constrains from the motor device.

        @return dict: dict with constraints for the sequence generation and GUI

        Provides all the constraints for the xyz stage  and rot stage (like total
        movement, velocity, ...)
        Each constraint is a tuple of the form
            (min_value, max_value, stepsize)
        """
        # TODO: read this from config

        constraints = OrderedDict()

        axis0 = {}
        axis0['label'] = 'x'
        axis0['channel'] = config['x']['channel']
        axis0['pos_min'] = config['x']['constraints']['pos_min']
        axis0['pos_max'] = config['x']['constraints']['pos_max']

        axis1 = {}
        axis1['label'] = 'y'
        axis1['channel'] = config['y']['channel']
        axis1['pos_min'] = config['y']['constraints']['pos_min']
        axis1['pos_max'] = config['y']['constraints']['pos_max']

        axis2 = {}
        axis2['label'] = 'z'
        axis2['channel'] = config['z']['channel']
        axis2['pos_min'] = config['z']['constraints']['pos_min']
        axis2['pos_max'] = config['z']['constraints']['pos_max']

        # assign the parameter container for x to a name which will identify it
        constraints[axis0['label']] = axis0
        constraints[axis1['label']] = axis1
        constraints[axis2['label']] = axis2

        return constraints

Other Comments

If required, a good example of this is in ntmdt_piezo_stage.py on branch dev_ntmdt_stage.

@mvbnano
Copy link
Member Author

mvbnano commented Feb 15, 2018

Please also include example configuration - you can see an example of this in ntmdt_piezo_stage.py on branch dev_ntmdt_stage.

class PiezoStageNTMDT(Base, MotorInterface):

    """unstable: Matt van Breugel
    This is the hardware module for communicating with NT-MDT piezo scanning stages
    over USB (via the NovaSDK dll). It uses the VB script from the documentation.

    Example configuration:
    ```
        # ntmdt_stage:
        # module.Class: 'motor.ntmdt_piezo_stage.PiezoStageNTMDT'
        # scanner: 1
        # constraints:
        #     x_range:
        #         min: 0e-6
        #         max: 100e-6
        #     y_range:
        #         min: 0e-6
        #         max: 100e-6
        #     z_range:
        #         min: 0e-6
        #         max: 6e-6
    ```
    """
    _modclass = 'PiezoStageNTMDT'
    _modtype = 'hardware'

@mvbnano
Copy link
Member Author

mvbnano commented Apr 12, 2018

Remember to connect _do_move_abs as was specified in issue #16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants