def start(self): self.exception = None self.index = 0 event.connect(self.movable, "position", self.position_changed) MotorMaster.start(self) if self.exception: raise self.exception[0], self.exception[1], self.exception[2]
def initialize_axis(self, axis): def set_pos(move_done, axis=axis): if move_done: self.set_position(axis, axis.dial()*axis.steps_per_unit) self._axis_moves[axis] = { "measured_simul": False, "measured_noise": 0.0, "end_t": 0, "end_pos": 0, "move_done_cb": set_pos } event.connect(axis, "move_done", set_pos) # this is to test axis are initialized only once axis.settings.set('init_count', axis.settings.get('init_count') + 1) # Add new axis oject methods as tango commands. add_axis_method(axis, self.custom_get_twice, types_info=("int", "int")) add_axis_method(axis, self.custom_get_chapi, types_info=("str", "str")) add_axis_method(axis, self.custom_send_command, types_info=("str", "None")) add_axis_method(axis, self.custom_command_no_types, types_info=("None", "None")) add_axis_method(axis, self.custom_set_measured_noise, types_info=("float", "None")) add_axis_method(axis, self._set_closed_loop, name = "Set_Closed_Loop", types_info = (bool, None)) add_axis_method(axis, self.put_discrepancy, types_info=("int", "None")) if axis.encoder: self.__encoders.setdefault(axis.encoder, {})["axis"] = axis
def prepare(self, scan_info, devices_tree): parent_node = self._node prev_level = 1 self._nodes = dict() for dev in list(devices_tree.expand_tree(mode=Tree.WIDTH))[1:]: dev_node = devices_tree.get_node(dev) level = devices_tree.depth(dev_node) if prev_level != level: prev_level = level parent_node = self._nodes[dev_node.bpointer] if isinstance(dev, (AcquisitionDevice, AcquisitionMaster)): data_container_node = _create_node(dev.name, parent=parent_node) self._nodes[dev] = data_container_node for channel in dev.channels: self._nodes[channel] = channel.data_node( data_container_node) connect(channel, 'new_data', self._channel_event) for signal in ('start', 'end'): connect(dev, signal, self._device_event) if self._writer: self._writer.prepare(self, scan_info, devices_tree)
def init(self): HardwareObject.init(self) self.controller = self.getObjectByRole("controller") event.connect(self.controller.tf, "state", self._tf_state_updated) event.connect(self.controller.tf2, "state", self._tf_state_updated) self.tfCfgByName = {} self.coefByName = {} self.sizeByName = {} self.posNames = [] cfg = self["lenses_config"] if not isinstance(cfg, list): cfg = [cfg] for lens_cfg in cfg: name = lens_cfg.getProperty("name") tf1 = lens_cfg.getProperty("tf1").split() tf2 = lens_cfg.getProperty("tf2").split() size = lens_cfg.getProperty("size") coef = lens_cfg.getProperty("coef") self.posNames.append(lens_cfg.getProperty("name")) self.tfCfgByName[name] = { "tf1": ["IN" if x else "OUT" for x in map(int, tf1)], "tf2": ["IN" if x else "OUT" for x in map(int, tf2)], } self.sizeByName[name] = float(size) self.coefByName[name] = float(coef)
def initialize_axis(self, axis): # this is to protect position reading, # indeed the mockup controller uses redis to store # a 'hardware position', and it is not allowed # to read a position before it has been written def set_pos(move_done, axis=axis): if move_done: self.set_position(axis, axis.dial()*axis.steps_per_unit) self._axis_moves[axis] = { "end_t": None, "move_done_cb": set_pos } if axis.settings.get('hw_position') is None: axis.settings.set('hw_position', 0) self._axis_moves[axis]['start_pos'] = self.read_position(axis) self._axis_moves[axis]['target'] = self._axis_moves[axis]['start_pos'] event.connect(axis, "move_done", set_pos) self.__voltages[axis] = axis.config.get("default_voltage", int, default=220) self.__cust_attr_float[axis] = axis.config.get("default_cust_attr", float, default=3.14) # this is to test axis are initialized only once axis.settings.set('init_count', axis.settings.get('init_count') + 1) if axis.encoder: self.__encoders.setdefault(axis.encoder, {})["axis"] = axis
def trigger(self): self.initial_velocity = self.movable.velocity() self.movable.velocity(self.velocity) end = self._calculate_undershoot(self.end_pos, end=True) event.connect(self.movable, "move_done", self.move_done) self.movable.move(end) if self.backnforth: self.start_pos, self.end_pos = self.end_pos, self.start_pos
def __init__(self, master, slave, parent): self._master = master self._parent = parent for signal in ('start', 'end'): connect(slave, signal, self) for channel in slave.channels: connect(channel, 'new_data', self)
def __init__(self, device, parent): self._device = device self._parent = parent for signal in ('start', 'end'): connect(device, signal, self) for channel in device.channels: connect(channel, 'new_data', self)
def initialize_axis(self, axis): axis.driver = axis.config.get("driver", str) axis.channel = axis.config.get("channel", int) axis.accumulator = None event.connect(axis, "move_done", self._axis_move_done) # self._write_no_reply(axis, "JOF") #, raw=True) self._write_no_reply(axis, "MON %s" % axis.driver)
def create_object_from_cache(config, name, controller): try: o = controller.get_axis(name) except KeyError: o = controller.get_encoder(name) else: event.connect(o, "write_setting", config_write_setting) return o
def create_objects_from_config_node(config, node): set_backend("beacon") name = node.get('name') controller_config = node.parent controller_class_name = controller_config.get('class') controller_name = controller_config.get('name') if controller_name is None: controller_name = "%s_%d" % ( controller_class_name, id(controller_config)) controller_class = get_controller_class(controller_class_name) axes = list() axes_names = list() encoders = list() encoder_names = list() for axis_config in controller_config.get('axes'): axis_name = axis_config.get("name") CONTROLLER_BY_AXIS[axis_name] = controller_name if axis_name.startswith("$"): axis_class = AxisRef axis_name = axis_name.lstrip('$') else: axis_class_name = axis_config.get("class") if axis_class_name is None: axis_class = Axis else: axis_class = get_axis_class(axis_class_name) if axis_name != name: axes_names.append(axis_name) axes.append((axis_name, axis_class, axis_config)) for encoder_config in controller_config.get('encoders', []): encoder_name = encoder_config.get("name") CONTROLLER_BY_ENCODER[encoder_name] = controller_name encoder_class_name = encoder_config.get("class") if encoder_class_name is None: encoder_class = Encoder else: encoder_class = get_encoder_class(encoder_class_name) if encoder_name != name: encoder_names.append(encoder_name) encoders.append((encoder_name, encoder_class, encoder_config)) controller = controller_class(controller_name, controller_config, axes, encoders) controller._update_refs() controller.initialize() try: o = controller.get_axis(name) except KeyError: o = controller.get_encoder(name) else: event.connect(o, "write_setting", config_write_setting) all_names = axes_names + encoder_names cache_dict = dict(zip(all_names, [controller]*len(all_names))) return {name: o}, cache_dict
def initialize_axis(self, axis): """ - Reads specific config - Adds specific methods - Switches piezo to ONLINE mode so that axis motion can be caused by move commands. Args: - <axis> Returns: - None """ axis.channel = axis.config.get("channel", int) axis.chan_letter = axis.config.get("chan_letter") add_axis_method(axis, self.get_id, types_info=(None, str)) '''Closed loop''' add_axis_method(axis, self.open_loop, types_info=(None, None)) add_axis_method(axis, self.close_loop, types_info=(None, None)) '''DCO''' add_axis_method(axis, self.activate_dco, types_info=(None, None)) add_axis_method(axis, self.desactivate_dco, types_info=(None, None)) '''GATE''' # to enable automatic gating (ex: zap) add_axis_method(axis, self.enable_auto_gate, types_info=(bool, None)) # to trig gate from external device (ex: HPZ with setpoint controller) add_axis_method(axis, self.set_gate, types_info=(bool, None)) if axis.channel == 1: self.ctrl_axis = axis # NO automatic gating by default. self.auto_gate_enabled = False '''end of move event''' event.connect(axis, "move_done", self.move_done_event_received) # Enables the closed-loop. # self.sock.write("SVO 1 1\n") self.send_no_ans(axis, "ONL %d 1" % axis.channel) # VCO for velocity control mode ? # self.send_no_ans(axis, "VCO %d 1" % axis.channel) # Updates cached value of closed loop status. self.closed_loop = self._get_closed_loop_status(axis) # Reads high/low limits of the piezo to use in set_gate self.low_limit = self._get_low_limit(axis) self.high_limit = self._get_high_limit(axis)
def __init__(self, *args): BlissWidget.__init__(self, *args) self.defineSignal("newScan", ()) self.scanObject = None self.xdata = [] self.ylable = "" self.mylog = 0 self.canAddPoint = True self.dm = DataManager() event.connect(self.dm, "scan_new", self.newScan) event.connect(self.dm, "scan_data", self.newScanPoint) self.addProperty("backgroundColor", "combo", ("white", "default"), "white") self.addProperty("graphColor", "combo", ("white", "default"), "white") self.lblTitle = QLabel(self) self.graphPanel = QFrame(self) buttonBox = QHBox(self) self.lblPosition = QLabel(buttonBox) self.graph = QtBlissGraph(self.graphPanel) QObject.connect(self.graph, PYSIGNAL("QtBlissGraphSignal"), self.handleBlissGraphSignal) QObject.disconnect( self.graph, SIGNAL("plotMousePressed(const QMouseEvent&)"), self.graph.onMousePressed, ) QObject.disconnect( self.graph, SIGNAL("plotMouseReleased(const QMouseEvent&)"), self.graph.onMouseReleased, ) self.graph.canvas().setMouseTracking(True) self.graph.enableLegend(False) self.graph.enableZoom(False) self.graph.setAutoLegend(False) self.lblPosition.setAlignment(Qt.AlignRight) self.lblTitle.setAlignment(Qt.AlignHCenter) self.lblTitle.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.lblPosition.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) buttonBox.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) QVBoxLayout(self.graphPanel) self.graphPanel.layout().addWidget(self.graph) QVBoxLayout(self) self.layout().addWidget(self.lblTitle) self.layout().addWidget(buttonBox) self.layout().addWidget(self.graphPanel)
def __init__(self, *args): BlissWidget.__init__(self, *args) self.defineSignal("newScan", ()) self.scanObject = None self.xdata = [] self.ylable = "" self.mylog = 0 self.canAddPoint = True self.dm = DataManager() event.connect(self.dm, "scan_new", self.newScan) event.connect(self.dm, "scan_data", self.newScanPoint) self.addProperty("backgroundColor", "combo", ("white", "default"), "white") self.addProperty("graphColor", "combo", ("white", "default"), "white") self.lblTitle = QLabel(self) self.graphPanel = QFrame(self) buttonBox = QHBox(self) self.lblPosition = QLabel(buttonBox) self.graph = QtBlissGraph(self.graphPanel) QObject.connect( self.graph, PYSIGNAL("QtBlissGraphSignal"), self.handleBlissGraphSignal ) QObject.disconnect( self.graph, SIGNAL("plotMousePressed(const QMouseEvent&)"), self.graph.onMousePressed, ) QObject.disconnect( self.graph, SIGNAL("plotMouseReleased(const QMouseEvent&)"), self.graph.onMouseReleased, ) self.graph.canvas().setMouseTracking(True) self.graph.enableLegend(False) self.graph.enableZoom(False) self.graph.setAutoLegend(False) self.lblPosition.setAlignment(Qt.AlignRight) self.lblTitle.setAlignment(Qt.AlignHCenter) self.lblTitle.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) self.lblPosition.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) buttonBox.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) QVBoxLayout(self.graphPanel) self.graphPanel.layout().addWidget(self.graph) QVBoxLayout(self) self.layout().addWidget(self.lblTitle) self.layout().addWidget(buttonBox) self.layout().addWidget(self.graphPanel)
def get_axis(axis_name): """Get axis from loaded configuration or from Beacon If needed, instanciates the controller of the axis and initializes it. Args: axis_name (str): Axis name Returns: :class:`bliss.common.axis.Axis` object Raises: RuntimeError """ if BACKEND=='beacon': global BEACON_CONFIG if BEACON_CONFIG is None: BEACON_CONFIG = beacon_get_config() o = BEACON_CONFIG.get(axis_name) if not isinstance(o, Axis): raise AttributeError("'%s` is not an axis" % axis_name) return o try: controller_name = CONTROLLER_BY_AXIS[axis_name] except KeyError: raise RuntimeError("no axis '%s` in config" % axis_name) else: try: controller = CONTROLLERS[controller_name] except KeyError: raise RuntimeError( "no controller can be found for axis '%s`" % axis_name) try: controller_instance = controller["object"] except KeyError: raise RuntimeError( "could not get controller instance for axis '%s`" % axis_name) if not controller["initialized"]: controller_instance._update_refs() controller_instance.initialize() controller["initialized"] = True axis = controller_instance.get_axis(axis_name) event.connect(axis, "write_setting", write_setting) return axis
def initialize(self): for real_axis in self._tagged['real']: # check if real axis is really from another controller if real_axis.controller == self: raise RuntimeError("Real axis '%s` doesn't exist" % real_axis.name) self.reals.append(real_axis) real_axis.controller._initialize_axis(real_axis) self.pseudos = [ axis for axis_name, axis in self.axes.iteritems() if axis not in self.reals ] self._reals_group = Group(*self.reals) event.connect(self._reals_group, 'move_done', self._real_move_done) calc = False for pseudo_axis in self.pseudos: self._Controller__initialized_hw_axis[pseudo_axis].value = True self._initialize_axis(pseudo_axis) event.connect(pseudo_axis, 'sync_hard', self._pseudo_sync_hard) if self.read_position(pseudo_axis) is None: # the pseudo axis position has *never* been calculated calc = True for real_axis in self.reals: event.connect(real_axis, 'internal_position', self._calc_from_real) event.connect(real_axis, 'internal__set_position', self._real_setpos_update) if calc: self._calc_from_real()
def initialize(self): for real_axis in self._tagged['real']: # check if real axis is really from another controller if real_axis.controller == self: raise RuntimeError( "Real axis '%s` doesn't exist" % real_axis.name) self.reals.append(real_axis) real_axis.controller._initialize_axis(real_axis) self.pseudos = [axis for axis_name, axis in self.axes.iteritems() if axis not in self.reals] self._reals_group = Group(*self.reals) event.connect(self._reals_group, 'move_done', self._real_move_done) calc = False for pseudo_axis in self.pseudos: self._Controller__initialized_hw_axis[pseudo_axis].value = True self._initialize_axis(pseudo_axis) event.connect(pseudo_axis, 'sync_hard', self._pseudo_sync_hard) if self.read_position(pseudo_axis) is None: # the pseudo axis position has *never* been calculated calc = True for real_axis in self.reals: event.connect(real_axis, 'internal_position', self._calc_from_real) event.connect(real_axis, 'internal__set_position', self._real_setpos_update) if calc: self._calc_from_real()
def test_move_done_event(self): res = {"ok": False} def callback(move_done, res=res): if move_done: res["ok"] = True roby = bliss.get_axis("roby") roby_pos = roby.position() robz = bliss.get_axis("robz") robz_pos = robz.position() event.connect(self.grp, "move_done", callback) self.grp.rmove({robz: 2, roby: 3}) self.assertEquals(res["ok"], True) self.assertEquals(robz.position(), robz_pos+2) self.assertEquals(roby.position(), roby_pos+3)
def GroupMove(self, axes_pos): """ Absolute move multiple motors """ axes_dict = self._get_axis_devices() axes_names = axes_pos[::2] if not set(axes_names).issubset(set(axes_dict)): raise ValueError("unknown axis(es) in motion") axes = [axes_dict[name].axis for name in axes_names] group = Group(*axes) event.connect(group, 'move_done', self.group_move_done) positions = map(float, axes_pos[1::2]) axes_pos_dict = dict(zip(axes, positions)) group.move(axes_pos_dict, wait=False) groupid = ','.join(map(':'.join, grouped(axes_pos, 2))) self.group_dict[groupid] = group return groupid
def test_move_done(roby, robz): grp = Group(robz, roby) res = {"ok": False} def callback(move_done, res=res): if move_done: res["ok"] = True roby_pos = roby.position() robz_pos = robz.position() event.connect(grp, "move_done", callback) grp.rmove({robz: 2, roby: 3}) assert res["ok"] == True assert robz.position() == robz_pos + 2 assert roby.position() == roby_pos + 3
def test_scan_callbacks(beacon): session = beacon.get("test_session") session.setup() res = {"new": False, "end": False, "values": []} def on_scan_new(scan_info): res["new"] = True def on_scan_data(scan_info, values): res["values"].append(values[counter.name]) def on_scan_end(scan_info): res["end"] = True event.connect(scan, 'scan_new', on_scan_new) event.connect(scan, 'scan_data', on_scan_data) event.connect(scan, 'scan_end', on_scan_end) counter_class = getattr(setup_globals, 'TestScanGaussianCounter') counter = counter_class("gaussian", 10, cnt_time=0.1) s = scans.timescan(0.1, counter, npoints=10, return_scan=True, save=False) assert res["new"] assert res["end"] assert numpy.array_equal(numpy.array(res["values"]), counter.data)
def initialize_axis(self, axis): """ - Reads specific config - Adds specific methods - Switches piezo to ONLINE mode so that axis motion can be caused by move commands. Args: - <axis> Returns: - None """ axis.channel = axis.config.get("channel", int) axis.chan_letter = axis.config.get("chan_letter") if axis.channel == 1: self.ctrl_axis = axis # NO automatic gating by default. self.auto_gate_enabled = False '''end of move event''' event.connect(axis, "move_done", self.move_done_event_received) # Enables the closed-loop. # self.sock.write("SVO 1 1\n") self.send_no_ans(axis, "ONL %d 1" % axis.channel) # VCO for velocity control mode ? # self.send_no_ans(axis, "VCO %d 1" % axis.channel) # Updates cached value of closed loop status. self.closed_loop = self._get_closed_loop_status(axis) # Reads high/low limits of the piezo to use in set_gate self.low_limit = self._get_low_limit(axis) self.high_limit = self._get_high_limit(axis)
def _update_refs(self): Controller._update_refs(self) self.reals = [] for real_axis in self._tagged['real']: # check if real axis is really from another controller if real_axis.controller == self: raise RuntimeError( "Real axis '%s` doesn't exist" % real_axis.name) self.reals.append(real_axis) event.connect(real_axis, 'position', self._calc_from_real) event.connect(real_axis, 'state', self._update_state_from_real) self._reals_group = Group(*self.reals) event.connect(self._reals_group, 'move_done', self._real_move_done) self.pseudos = [ axis for axis_name, axis in self.axes.iteritems() if axis not in self.reals]
def initialize_axis(self, axis): CalcController.initialize_axis(self, axis) event.connect(axis, "s_param", self._calc_from_real)
def initialize_axis(self, axis): CalcController.initialize_axis(self, axis) event.connect(axis, "dspace", self._calc_from_real)
def initialize_axis(self, axis): CalcController.initialize_axis(self, axis) axis.no_offset = self.no_offset event.connect(axis, "dspace", self._calc_from_real)