Ejemplo n.º 1
0
 def move(
     self,
     context: builtin.hooks.AContext,
     a: ADemandPosition = None,
     b: ADemandPosition = None,
     c: ADemandPosition = None,
     u: ADemandPosition = None,
     v: ADemandPosition = None,
     w: ADemandPosition = None,
     x: ADemandPosition = None,
     y: ADemandPosition = None,
     z: ADemandPosition = None,
     moveTime: AMoveTime = 0,
 ) -> None:
     """Move the given CS axes using a deferred co-ordinated move"""
     child = context.block_view(self.mri)
     child.deferMoves.put_value(True)
     # Convert move time into milliseconds
     child.csMoveTime.put_value(moveTime * 1000.0)
     # Add in the motors we need to move
     attribute_values = {}
     for axis in CS_AXIS_NAMES:
         demand = locals()[axis.lower()]
         if demand is not None:
             attribute_values["demand%s" % axis] = demand
     fs = child.put_attribute_values_async(attribute_values)
     # Wait for the demand to have been received by the PV
     for attr, value in sorted(attribute_values.items()):
         child.when_value_matches(attr, value, timeout=1.0)
     # Start the move
     child.deferMoves.put_value(False)
     # Wait for them to get there
     context.wait_all_futures(fs, timeout=moveTime + DEFAULT_TIMEOUT)
Ejemplo n.º 2
0
 def execute_profile(self, context: builtin.hooks.AContext) -> None:
     child = context.block_view(self.mri)
     fs1 = context.subscribe([self.mri, "pointsScanned", "value"],
                             self.points_scanned.set_value)
     fs2 = context.subscribe([self.mri, "pointsBuilt", "value"],
                             self.set_scan_length)
     try:
         child.executeProfile()
         # Now wait for up to 2*min_delta time to make sure any
         # update_completed_steps come in
         child.when_value_matches("pointsScanned",
                                  self.total_points,
                                  timeout=0.1)
     finally:
         context.unsubscribe(fs1)
         context.unsubscribe(fs2)
Ejemplo n.º 3
0
 def on_init(self, context: builtin.hooks.AContext) -> None:
     super().on_init(context)
     # Check the port name matches our CS number
     child = context.block_view(self.mri)
     cs_port = child.port.value
     assert cs_port.endswith(str(
         self.cs)), "CS Port %s doesn't end with port number %d" % (cs_port,
                                                                    self.cs)
Ejemplo n.º 4
0
 def move(self,
          context: builtin.hooks.AContext,
          demand: ADemand,
          duration: ADuration = 0) -> None:
     """Move the counter to the demand value, taking duration seconds like
     a motor would do"""
     start = time.time()
     child = context.block_view(self.mri)
     distance = demand - child.counter.value
     remaining = duration
     # "Move" the motor, ticking at UPDATE_TICK rate
     while remaining > 0:
         child.counter.put_value(demand - distance * remaining / duration)
         context.sleep(min(remaining, UPDATE_TICK))
         remaining = start + duration - time.time()
     # Final move to make sure we end up at the right place
     child.counter.put_value(demand)
Ejemplo n.º 5
0
    def write_profile(
        self,
        context: builtin.hooks.AContext,
        timeArray: ATimeArray,
        csPort: ACSPort = None,
        velocityMode: AVelocityMode = None,
        userPrograms: AUserPrograms = None,
        a: ADemandTrajectory = None,
        b: ADemandTrajectory = None,
        c: ADemandTrajectory = None,
        u: ADemandTrajectory = None,
        v: ADemandTrajectory = None,
        w: ADemandTrajectory = None,
        x: ADemandTrajectory = None,
        y: ADemandTrajectory = None,
        z: ADemandTrajectory = None,
    ) -> None:
        child = context.block_view(self.mri)

        # make sure a matching trajectory program is installed on the pmac
        if child.trajectoryProgVersion.value != TRAJECTORY_PROGRAM_NUM:
            if child.trajectoryProgVersion.value >= FALLBACK_TRAJ_PROGRAM_NUM:
                self.log.warning(
                    f"pmac trajectory program is version {FALLBACK_TRAJ_PROGRAM_NUM}"
                    f" version {TRAJECTORY_PROGRAM_NUM} is recommended"
                )
            else:
                raise (
                    IncompatibleError(
                        f"pmac trajectory program {child.trajectoryProgVersion.value} "
                        f"detected. Malcolm requires {TRAJECTORY_PROGRAM_NUM}"
                    )
                )

        # The axes taking part in the scan
        use_axes = []
        for axis in CS_AXIS_NAMES:
            if locals()[axis.lower()] is not None:
                use_axes.append(axis)
        if csPort is not None:
            # This is a build
            action = child.buildProfile
            self.total_points = 0
            child.numPoints.put_value(MAX_NUM_POINTS)
            try:
                child.cs.put_value(csPort)
            except ValueError as e:
                raise ValueError(
                    f"Cannot set CS to {csPort}, did you use a compound_motor_block "
                    f"for a raw motor?\n{e}"
                )
            # Tell the trajectory scans which of the arrays to use
            arrays = {f"use{axis}": axis in use_axes for axis in CS_AXIS_NAMES}
            child.put_attribute_values(arrays)
        else:
            # This is an append
            action = child.appendProfile

        # Fill in the arrays
        num_points = len(timeArray)
        attribute_values = dict(
            timeArray=timeArray,
            pointsToBuild=num_points,
            velocityMode=_zeros_or_right_length(velocityMode, num_points),
            userPrograms=_zeros_or_right_length(userPrograms, num_points),
        )
        for axis in use_axes:
            demand = locals()[axis.lower()]
            attribute_values[f"positions{axis}"] = demand
        child.put_attribute_values(attribute_values)
        # Write the profile
        action()
        # Record how many points we have now written in total
        self.total_points += num_points
Ejemplo n.º 6
0
 def abort_profile(self, context: builtin.hooks.AContext) -> None:
     child = context.block_view(self.mri)
     child.abortProfile()
Ejemplo n.º 7
0
 def servo_frequency(self,
                     context: builtin.hooks.AContext) -> AServoFrequency:
     return context.block_view(self.mri).servoFreq.value
Ejemplo n.º 8
0
 def on_configure(self, context: builtin.hooks.AContext) -> None:
     childBlock = context.block_view(self.mri)
     childBlock.demand.put_value(self.demand)
Ejemplo n.º 9
0
 def servo_frequency(self,
                     context: builtin.hooks.AContext) -> AServoFrequency:
     child = context.block_view(self.mri)
     freq = 8388608000.0 / child.i10.value
     return freq