Macro: Square Move, FS-DS

The code below moves 2 motors in a square. The procedure starts at the current position.

#!/bin/env python
# 
"""two motors are moved in a square"""

__all__ = ["squareScans"]

from sardana.macroserver.macro import Macro, Type

class squareScans(Macro):
    """move two motors in a square +- delta, relative to current position"""
    param_def = [
        [ "mot1", Type.Moveable, None, "the inner loop motor" ],
        [ "mot2", Type.Moveable, None, "the outer loop motor" ],
        [ "delta", Type.Float, None, "a floating point number" ],
        [ "n", Type.Integer, None, "movements: current position +- delta" ],
        ]
    def run(self, mot1, mot2, delta, n):

        pos1Old = mot1.getPosition()
        pos2Old = mot2.getPosition()

        self.mv(mot1, pos1Old - delta)
        self.mv(mot2, pos2Old - delta)
        
        for i in range(0, n):
            self.mv(mot1, pos1Old - delta, mot2, pos2Old - delta)
            self.output( "%d/%d: %s at %g %s at %g" % 
                         (i, n, mot1.getName(), mot1.getPosition(), mot2.getName(), mot2.getPosition()))
            self.mv(mot1, pos1Old + delta, mot2, pos2Old - delta)
            self.output( "%d/%d: %s at %g %s at %g" % 
                         (i, n, mot1.getName(), mot1.getPosition(), mot2.getName(), mot2.getPosition()))
            self.mv(mot1, pos1Old + delta, mot2, pos2Old + delta)
            self.output( "%d/%d: %s at %g %s at %g" % 
                         (i, n, mot1.getName(), mot1.getPosition(), mot2.getName(), mot2.getPosition()))
            self.mv(mot1, pos1Old - delta, mot2, pos2Old + delta)
            self.output( "%d/%d: %s at %g %s at %g" % 
                         (i, n, mot1.getName(), mot1.getPosition(), mot2.getName(), mot2.getPosition()))

        self.mv(mot1, pos1Old)
        self.mv(mot2, pos2Old)
    
        self.output( "%s at %g %s at %g" % 
                     (mot1.getName(), mot1.getPosition(), mot2.getName(), mot2.getPosition()))



2019-11-13