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 __move(*args, **kwargs): wait, relative = kwargs.get('wait', True), kwargs.get('relative', False) motor_pos = OrderedDict() for m, p in zip(__get_objects_iter(*args[::2]), args[1::2]): motor_pos[m] = p group = Group(*motor_pos.keys()) group.move(motor_pos, wait=wait, relative=relative) return group, motor_pos
def axis_group_move(self, axes_pos): axes = map(get_bliss_obj, axes_pos[::2]) axes_positions = map(float, axes_pos[1::2]) axes_pos_dict = dict(zip(axes, axes_positions)) group = Group(*axes) event.connect(group, 'move_done', self.__on_axis_group_move_done) group.move(axes_pos_dict, wait=False) group_id = ','.join(map(':'.join, grouped(axes_pos, 2))) self.group_dict[group_id] = group return group_id
def d2scan(motor1, start1, stop1, motor2, start2, stop2, npoints, count_time, *counters, **kwargs): """ Relative 2 motor scan Scans two motors, as specified by *motor1* and *motor2*. Each motor moves the same number of points. If a motor is at position *X* before the scan begins, the scan will run from `X+start` to `X+end`. The step size of a motor is `(*start*-*stop*)/(*npoints*-1)`. The number of intervals will be *npoints*-1. Count time is given by *count_time* (seconds). At the end of the scan (even in case of error) the motor will return to its initial position Use `d2scan(..., run=False, return_scan=True)` to create a scan object and its acquisition chain without executing the actual scan. Args: motor1 (Axis): motor1 to scan start1 (float): motor1 relative start position stop1 (float): motor1 relative end position motor2 (Axis): motor2 to scan start2 (float): motor2 relative start position stop2 (float): motor2 relative end position npoints (int): the number of points count_time (float): count time (seconds) counters (BaseCounter or MeasurementGroup): change for those counters or measurement group. if counter is empty use the active measurement group. Keyword Args: name (str): scan name in data nodes tree and directories [default: 'scan'] title (str): scan title [default: 'd2scan <motor1> ... <count_time>'] save (bool): save scan data to file [default: True] sleep_time (float): sleep time between 2 points [default: None] run (bool): if True (default), run the scan. False means just create scan object and acquisition chain return_scan (bool): False by default """ kwargs['type'] = 'd2scan' oldpos1 = motor1.position() oldpos2 = motor2.position() kwargs.setdefault('name', 'd2scan') scan = a2scan(motor1, oldpos1 + start1, oldpos1 + stop1, motor2, oldpos2 + start2, oldpos2 + stop2, npoints, count_time, *counters, **kwargs) group = Group(motor1, motor2) group.move(motor1, oldpos1, motor2, oldpos2) return scan
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 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 __init__(self, *args, **keys): trigger_type = keys.pop('trigger_type', AcquisitionMaster.SOFTWARE) self.next_mv_cmd_arg = list() if len(args) % 2: raise TypeError( '_VariableStepTriggerMaster: argument is a mot, positions ...') self._motor_pos = list() self._axes = list() for _axis, pos_list in grouped(args, 2): self._axes.append(_axis) self._motor_pos.append(pos_list) mot_group = Group(*self._axes) group_name = '/'.join((x.name for x in self._axes)) AcquisitionMaster.__init__(self, mot_group, group_name, trigger_type=trigger_type, **keys) self.channels.extend((AcquisitionChannel(axis.name, numpy.double, ()) for axis in self._axes))
def __init__(self, *args, **keys): trigger_type = keys.pop('trigger_type', AcquisitionMaster.SOFTWARE) self.next_mv_cmd_arg = list() if len(args) % 4: raise TypeError( '_StepTriggerMaster: argument is a mot1,start,stop,nb points,mot2,start2...' ) self._motor_pos = list() self._axes = list() for axis, start, stop, nb_point in grouped(args, 4): self._axes.append(axis) self._motor_pos.append(numpy.linspace(start, stop, nb_point)) mot_group = Group(*self._axes) group_name = '/'.join((x.name for x in self._axes)) AcquisitionMaster.__init__(self, mot_group, group_name, trigger_type=trigger_type, **keys) self.channels.extend((AcquisitionChannel(axis.name, numpy.double, ()) for axis in self._axes))
class CalcController(Controller): def __init__(self, *args, **kwargs): Controller.__init__(self, *args, **kwargs) self._reals_group = None self.reals = [] self.pseudos = [] 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_axis(self, axis): pass def _pseudo_sync_hard(self): for real_axis in self.reals: real_axis.sync_hard() def _axis_tag(self, axis): return [ tag for tag, axes in self._tagged.iteritems() if tag != 'real' and len(axes) == 1 and axis in axes ][0] def _get_set_positions(self): setpos_dict = dict() for axis in self.pseudos: setpos_dict[self._axis_tag(axis)] = axis.user2dial( axis._set_position()) return setpos_dict def _real_setpos_update(self, _): real_setpos = dict() for axis in self.reals: real_setpos[self._axis_tag(axis)] = axis._set_position() new_setpos = self.calc_from_real(real_setpos) for tagged_axis_name, setpos in new_setpos.iteritems(): axis = self._tagged[tagged_axis_name][0] axis.settings.set("_set_position", axis.dial2user(setpos)) def _do_calc_from_real(self): real_positions_by_axis = self._reals_group.position() real_positions = dict([(self._axis_tag(axis), pos) for axis, pos in real_positions_by_axis.items() ]) return self.calc_from_real(real_positions) def _calc_from_real(self, *args, **kwargs): new_positions = self._do_calc_from_real() for tagged_axis_name, dial_pos in new_positions.iteritems(): axis = self._tagged[tagged_axis_name][0] if axis in self.pseudos: user_pos = axis.dial2user(dial_pos) axis.settings.set("dial_position", dial_pos) axis.settings.set("position", user_pos) else: raise RuntimeError("cannot assign position to real motor") return new_positions def calc_from_real(self, real_positions): """Return a dict { pseudo motor tag: new position, ... }""" raise NotImplementedError def _real_move_done(self, done): if done: for axis in self.pseudos: if axis.encoder: # check position and raise RuntimeError if encoder # position doesn't correspond to axis position # (MAXE_E) axis._do_encoder_reading() def start_one(self, motion): self.start_all(motion) def start_all(self, *motion_list): positions_dict = self._get_set_positions() move_dict = dict() for tag, target_pos in self.calc_to_real(positions_dict).iteritems(): real_axis = self._tagged[tag][0] move_dict[real_axis] = target_pos # force a global position update in case phys motors never move self._calc_from_real() self._reals_group.move(move_dict, wait=False) def calc_to_real(self, positions_dict): raise NotImplementedError def stop(self, axis): self._reals_group.stop() def read_position(self, axis): return axis.settings.get("dial_position") def state(self, axis, new_state=None): st = self._reals_group.state() if st == 'READY': self._calc_from_real() return st def set_position(self, axis, new_pos): if not axis in self.pseudos: raise RuntimeError( "Cannot set dial position on motor '%s` from CalcController" % axis.name) positions = self._get_set_positions() positions[self._axis_tag(axis)] = new_pos real_positions = self.calc_to_real(positions) for real_axis_tag, user_pos in real_positions.iteritems(): self._tagged[real_axis_tag][0].position(user_pos) new_positions = self._calc_from_real() return new_positions[self._axis_tag(axis)]
class CalcController(Controller): def __init__(self, *args, **kwargs): Controller.__init__(self, *args, **kwargs) self._reals_group = None self.reals = [] self.pseudos = [] 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_axis(self, axis): pass def _pseudo_sync_hard(self): for real_axis in self.reals: real_axis.sync_hard() def _axis_tag(self, axis): return [tag for tag, axes in self._tagged.iteritems() if tag != 'real' and len(axes) == 1 and axis in axes][0] def _get_set_positions(self): setpos_dict = dict() for axis in self.pseudos: setpos_dict[self._axis_tag(axis)] = axis.user2dial(axis._set_position()) return setpos_dict def _real_setpos_update(self, _): real_setpos = dict() for axis in self.reals: real_setpos[self._axis_tag(axis)] = axis._set_position() new_setpos = self.calc_from_real(real_setpos) for tagged_axis_name, setpos in new_setpos.iteritems(): axis = self._tagged[tagged_axis_name][0] axis.settings.set("_set_position", axis.dial2user(setpos)) def _do_calc_from_real(self): real_positions_by_axis = self._reals_group.position() real_positions = dict([(self._axis_tag(axis), pos) for axis, pos in real_positions_by_axis.items()]) return self.calc_from_real(real_positions) def _calc_from_real(self, *args, **kwargs): new_positions = self._do_calc_from_real() for tagged_axis_name, dial_pos in new_positions.iteritems(): axis = self._tagged[tagged_axis_name][0] if axis in self.pseudos: user_pos = axis.dial2user(dial_pos) axis.settings.set("dial_position", dial_pos) axis.settings.set("position", user_pos) else: raise RuntimeError("cannot assign position to real motor") return new_positions def calc_from_real(self, real_positions): """Return a dict { pseudo motor tag: new position, ... }""" raise NotImplementedError def _real_move_done(self, done): if done: for axis in self.pseudos: if axis.encoder: # check position and raise RuntimeError if encoder # position doesn't correspond to axis position # (MAXE_E) axis._do_encoder_reading() def start_one(self, motion): self.start_all(motion) def start_all(self, *motion_list): positions_dict = self._get_set_positions() move_dict = dict() for tag, target_pos in self.calc_to_real(positions_dict).iteritems(): real_axis = self._tagged[tag][0] move_dict[real_axis] = target_pos # force a global position update in case phys motors never move self._calc_from_real() self._reals_group.move(move_dict, wait=False) def calc_to_real(self, positions_dict): raise NotImplementedError def stop(self, axis): self._reals_group.stop() def read_position(self, axis): return axis.settings.get("dial_position") def state(self, axis, new_state=None): st = self._reals_group.state() if st == 'READY': self._calc_from_real() return st def set_position(self, axis, new_pos): if not axis in self.pseudos: raise RuntimeError("Cannot set dial position on motor '%s` from CalcController" % axis.name) positions = self._get_set_positions() positions[self._axis_tag(axis)] = new_pos real_positions = self.calc_to_real(positions) for real_axis_tag, user_pos in real_positions.iteritems(): self._tagged[real_axis_tag][0].position(user_pos) new_positions = self._calc_from_real() return new_positions[self._axis_tag(axis)]