Example #1
0
class Undulator(Controller):
    def __init__(self, name, config, axes, encoders):
        Controller.__init__(self, name, config, axes, encoders)

        self.axis_info = dict()

        try:
            self.ds_name = self.config.get("ds_name")
        except:
            elog.debug("no 'ds_name' defined in config for %s" % name)

    """
    Controller initialization actions.
    """
    def initialize(self):
        # Get a proxy on Insertion Device device server of the beamline.
        self.device = DeviceProxy(self.ds_name)

    """
    Axes initialization actions.
    """
    def initialize_axis(self, axis):
        attr_pos_name = axis.config.get("attribute_position", str)
        attr_vel_name = axis.config.get("attribute_velocity", str)
        attr_acc_name = axis.config.get("attribute_acceleration", str)
        self.axis_info[axis] = {"attr_pos_name": attr_pos_name,
                                "attr_vel_name": attr_vel_name,
                                "attr_acc_name": attr_acc_name}
        elog.debug("axis initilized--------------------------")

    """
    Actions to perform at controller closing.
    """
    def finalize(self):
        pass

    def _set_attribute(self, axis, attribute_name, value):
        self.device.write_attribute(self.axis_info[axis][attribute_name], value)

    def _get_attribute(self, axis, attribute_name):
        return self.device.read_attribute(self.axis_info[axis][attribute_name]).value

    def start_one(self, motion, t0=None):
        self._set_attribute(motion.axis, "attr_pos_name",
                            float(motion.target_pos / motion.axis.steps_per_unit))

    def read_position(self, axis):
        """
        Returns the position taken from controller
        in controller unit (steps).
        """
        return self._get_attribute(axis, "attr_pos_name")

    """
    VELOCITY
    """
    def read_velocity(self, axis):
        """
        Returns the current velocity taken from controller
        in motor units.
        """
        return self._get_attribute(axis, "attr_vel_name")

    def set_velocity(self, axis, new_velocity):
        """
        <new_velocity> is in motor units
        """
        self._set_attribute(axis, "attr_vel_name", new_velocity)

    """
    ACCELERATION
    """
    def read_acceleration(self, axis):
        return self._get_attribute(axis, "attr_acc_name")

    def set_acceleration(self, axis, new_acceleration):
        self._set_attribute(axis, "attr_acc_name", new_acceleration)

    """
    STATE
    """
    def state(self, axis):
        _state = self.device.state()

        if _state == DevState.ON:
            return AxisState("READY")
        elif _state == DevState.MOVING:
            return AxisState("MOVING")
        else:
            return AxisState("READY")

    """
    Must send a command to the controller to abort the motion of given axis.
    """
    def stop(self, axis):
        self.device.abort()

    def stop_all(self, *motion_list):
        self.device.abort()

    def get_info(self, axis):
        info_str = ""
        info_str = "DEVICE SERVER : %s \n" % self.ds_name
        info_str += self.ds.state() + "\n"
        info_str += "status=\"%s\"\n" % str(self.ds.status()).strip()
        info_str += "state=%s\n" % self.ds.state()
        info_str += "mode=%s\n" % str(self.ds.mode)
        info_str += ("undu states= %s" % " ".join(map(str, self.ds.UndulatorStates)))

        return info_str
Example #2
0
class TangoEMot(Controller):
    def __init__(self, name, config, axes, encoders):
        Controller.__init__(self, name, config, axes, encoders)

        # Gets DS name from xml config.
        self.ds_name = self.config.get("ds_name")

        # tests if DS is responding.

    def initialize(self):
        pass

    def finalize(self):
        pass

    def initialize_axis(self, axis):
        self.axis_proxy = DeviceProxy(self.ds_name)

        axis.config.set("steps_per_unit", self.axis_proxy.steps_per_unit)
        axis.config.set("acceleration", self.axis_proxy.ReadConfig("acceleration"))
        axis.config.set("velocity", self.axis_proxy.ReadConfig("velocity"))

    def initialize_encoder(self, encoder):
        self.encoder_proxy = DeviceProxy(self.ds_name)

        encoder.config.config_dict.update({"steps_per_unit": {"value": self.encoder_proxy.steps_per_unit}})

    def read_position(self, axis):
        """
        Returns the position (measured or desired) taken from controller
        in *controller unit* (steps for example).
        """
        return self.axis_proxy.position * axis.steps_per_unit

    def read_encoder(self, encoder):
        return self.encoder_proxy.Measured_Position * encoder.steps_per_unit

    def read_velocity(self, axis):
        _vel = self.axis_proxy.velocity * abs(axis.steps_per_unit)
        return _vel

    def set_velocity(self, axis, new_velocity):
        self.axis_proxy.velocity = new_velocity / abs(axis.steps_per_unit)

    def read_acctime(self, axis):
        return self.axis_proxy.acctime

    def set_acctime(self, axis, new_acc_time):
        self.axis_proxy.acctime = new_acc_time

    def read_acceleration(self, axis):
        return self.axis_proxy.acceleration * abs(axis.steps_per_unit)

    def set_acceleration(self, axis, new_acceleration):
        self.axis_proxy.acceleration = new_acceleration / abs(axis.steps_per_unit)

    def state(self, axis):
        _state = self.axis_proxy.state()
        if _state == DevState.ON:
            return AxisState("READY")
        elif _state == DevState.MOVING:
            return AxisState("MOVING")
        else:
            return AxisState("READY")

    def prepare_move(self, motion):
        pass

    def start_one(self, motion):
        """
        Called on a single axis motion,
        returns immediately,
        positions in motor units
        """
        self.axis_proxy.position = float(motion.target_pos / motion.axis.steps_per_unit)

    def stop(self, axis):
        self.axis_proxy.Abort()

    def home_search(self, axis):
        self.axis_proxy.GoHome()

    def home_state(self, axis):
        return self.state(axis)