Пример #1
0
        def call(self):
            if self._controller.verbose: self.logger.info('call...')
            # Wait for controller to start all motors moving and set start time
            if self._controller._start_time:
                if self._controller.verbose:
                    self.logger.info('start_time=%r' %
                                     (self._controller._start_time))
            else:
                if self._controller.verbose: self.logger.info('wait()...')
                timeout = 60
                self.start_event.wait(timeout)
                if not self.start_event.isSet():
                    raise Exception(
                        "%rs timeout waiting for startMove() to be called on %s at position %r."
                        % (timeout, self._controller.name,
                           self._demand_position))
                if self._controller.verbose: self.logger.info('...wait()')
            # Wait for delay before actually move start and then a time given by
            # how far through the scan this point is

            grat_pitch = enemirror2grating(
                gd=self._controller.grating_density,
                energy=self._demand_position,
                pmang=self._controller.mirr_pitch_midpoint,
                groff=self._controller.grating_offset,
                pmoff=self._controller.plane_mirror_offset,
                ecg=self._controller.energy_calibration_gradient,
                ecr=self._controller.energy_calibration_reference)

            complete = abs((grat_pitch - self._controller._grat_pitch_start) /
                           (self._controller._grat_pitch_end -
                            self._controller._grat_pitch_start))
            sleeptime_s = (self._controller._pgm_runupdown_time +
                           (complete * self._controller.getTotalTime()))

            delta = datetime.now() - self._controller._start_time
            delta_s = delta.seconds + delta.microseconds / 1000000.
            if delta_s > sleeptime_s:
                self.logger.warn(
                    'Sleep time already past!!! sleeptime_s=%r, delta_s=%r, sleeptime_s-delta_s=%r'
                    % (sleeptime_s, delta_s, sleeptime_s - delta_s))
            else:
                if self._controller.verbose:
                    self.logger.info(
                        'sleeping... sleeptime_s=%r, delta_s=%r, sleeptime_s-delta_s=%r'
                        % (sleeptime_s, delta_s, sleeptime_s - delta_s))
                time.sleep(sleeptime_s - delta_s)

            energy = angles2energy(
                gd=self._controller.grating_density,
                grang=self._controller._pgm_grat_pitch() / 1000.,
                pmang=self._controller._pgm_mirr_pitch() / 1000.,
                groff=self._controller.grating_offset,
                pmoff=self._controller.plane_mirror_offset,
                ecg=self._controller.energy_calibration_gradient,
                ecr=self._controller.energy_calibration_reference)
            if self._controller.verbose:
                self.logger.info('...DelayableCallable:call returning %r, %r' %
                                 (self._demand_position, energy))
            return self._demand_position, energy
Пример #2
0
    def testGratPitch(self):
        grat_pitch = enemirror2grating(gd=self.grating_density,
                                       energy=self.pgm_energy,
                                       pmang=self.mirror_pitch,
                                       groff=self.grating_offset,
                                       pmoff=self.plane_mirror_offset,
                                       ecg=self.energy_calibration_gradient,
                                       ecr=self.energy_calibration_reference)

        self.assertAlmostEqual(grat_pitch, self.grating_pitch,
                               self.decimal_places)
Пример #3
0
    def PreparePGMForMove(self):
        self._pgm_grat_pitch_speed_orig = 0.018
        self._pgm_grat_pitch.speed=self._pgm_grat_pitch_speed_orig
#         if self._pgm_grat_pitch_speed_orig != 0.018:
#             raise Exception("PGM Grit Pitch motor speed %f is not at maximum 0.018!" % (self._pgm_grat_pitch_speed_orig))
        
        # Calculate the energy midpoint
        energy_midpoint = (self._move_end + self._move_start) / 2.
        if self.verbose:
            self.logger.info('preparePGMForMove:energy_midpoint=%r ' % (energy_midpoint))

        if installation.isLive():
            self.grating_density, self.cff, self.grating_offset, self.plane_mirror_offset, self.energy_calibration_gradient, self.energy_calibration_reference = self.getPgmEnergyParameters()
        else:
            self.grating_density, self.cff, self.grating_offset, self.plane_mirror_offset, self.energy_calibration_gradient, self.energy_calibration_reference = self.getPgmEnergyParametersFixed()
            
        # Calculate plane mirror angle for given grating density, energy, cff and offsets
        self.mirr_pitch_midpoint = enecff2mirror(gd=self.grating_density, 
                                                 energy=energy_midpoint, 
                                                 cff=self.cff, 
                                                 groff=self.grating_offset, 
                                                 pmoff=self.plane_mirror_offset, 
                                                 ecg=self.energy_calibration_gradient, 
                                                 ecr=self.energy_calibration_reference)
        # Calculate grating angles for given grating density, energy, mirror angle and offsets
        self._grat_pitch_start = enemirror2grating(gd=self.grating_density, 
                                                   energy=self._move_start, 
                                                   pmang=self.mirr_pitch_midpoint, 
                                                   groff=self.grating_offset, 
                                                   pmoff=self.plane_mirror_offset, 
                                                   ecg=self.energy_calibration_gradient, 
                                                   ecr=self.energy_calibration_reference)
        self._grat_pitch_end = enemirror2grating(gd=self.grating_density, 
                                                 energy=self._move_end, 
                                                 pmang=self.mirr_pitch_midpoint, 
                                                 groff=self.grating_offset, 
                                                 pmoff=self.plane_mirror_offset, 
                                                 ecg=self.energy_calibration_gradient, 
                                                 ecr=self.energy_calibration_reference)
        if not self.isIDMoveEnabled():
            self.k=1.0
            
        
        print self.k
        ### Calculate main cruise moves & speeds from start/end/step
        self._pgm_grat_pitch_speed = abs(self._grat_pitch_end - self._grat_pitch_start) / self.getTotalTime()
        print self._pgm_grat_pitch_speed
        self._pgm_grat_pitch_speed=self._pgm_grat_pitch_speed*self.k * self.pgmspeedfactor
        print self._pgm_grat_pitch_speed
        
        ### Calculate ramp distance from required speed and ramp times
        #check speed within limits
        if self._pgm_grat_pitch_speed<=0.000 or self._pgm_grat_pitch_speed>0.018:
            raise Exception("Calculated PGM Grit Pitch motor speed %f is outside limits [%f, %f]!" % (self._pgm_grat_pitch_speed, 0.000, 0.018))
        
        # Set the speed before we read out ramp times in case it is dependent
        self._pgm_grat_pitch.speed = self._pgm_grat_pitch_speed 
        # Should really be / | | | | | \ not /| | | | |\
        self._pgm_runupdown_time = self._pgm_grat_pitch.timeToVelocity
        self._pgm_runupdown = self._pgm_grat_pitch_speed / 2 * self._pgm_runupdown_time
        ### Move motor at full speed to start position
        if self.verbose:
            self.logger.info('preparePGMForMove:_pgm_mirr_pitch.asynchronousMoveTo(%r) @ %r ' % (self.mirr_pitch_midpoint * 1000., self._pgm_mirr_pitch.speed))
        self._pgm_mirr_pitch.asynchronousMoveTo(self.mirr_pitch_midpoint * 1000.)
        self._pgm_grat_pitch.speed = self._pgm_grat_pitch_speed_orig
        if self.getGratingMoveDirectionPositive():
            if self.verbose:
                self.logger.info('preparePGMForMove:asynchronousMoveTo(%r) @ %r (+ve)' % ((self._grat_pitch_start - self._pgm_runupdown) * 1000., self._pgm_grat_pitch_speed_orig))
            self._pgm_grat_pitch.asynchronousMoveTo((self._grat_pitch_start - self._pgm_runupdown) * 1000.)
        else:
            if self.verbose:
                self.logger.info('preparePGMForMove:asynchronousMoveTo(%r) @ %r (-ve)' % ((self._grat_pitch_start + self._pgm_runupdown) * 1000., self._pgm_grat_pitch_speed_orig))
            self._pgm_grat_pitch.asynchronousMoveTo((self._grat_pitch_start + self._pgm_runupdown) * 1000.)
Пример #4
0
    def prepareForMove(self):
        if self.verbose: self.logger.info('prepareForMove()...')
        self._pgm_grat_pitch_speed_orig = self._pgm_grat_pitch.speed

        # Calculate the energy midpoint
        energy_midpoint = (self._move_end + self._move_start) / 2.
        if self.verbose:
            self.logger.info('prepareForMove:energy_midpoint=%r ' %
                             (energy_midpoint))

        if installation.isLive():
            (self.grating_density, self.cff, self.grating_offset,
             self.plane_mirror_offset, self.energy_calibration_gradient,
             self.energy_calibration_reference
             ) = self.getPgmEnergyParameters()
        else:
            (self.grating_density, self.cff, self.grating_offset,
             self.plane_mirror_offset, self.energy_calibration_gradient,
             self.energy_calibration_reference
             ) = self.getPgmEnergyParametersFixed()

        # Calculate plane mirror angle for given grating density, energy, cff and offsets
        self.mirr_pitch_midpoint = enecff2mirror(
            gd=self.grating_density,
            energy=energy_midpoint,
            cff=self.cff,
            groff=self.grating_offset,
            pmoff=self.plane_mirror_offset,
            ecg=self.energy_calibration_gradient,
            ecr=self.energy_calibration_reference)

        # Calculate grating angles for given grating density, energy, mirror angle and offsets
        self._grat_pitch_start = enemirror2grating(
            gd=self.grating_density,
            energy=self._move_start,
            pmang=self.mirr_pitch_midpoint,
            groff=self.grating_offset,
            pmoff=self.plane_mirror_offset,
            ecg=self.energy_calibration_gradient,
            ecr=self.energy_calibration_reference)

        self._grat_pitch_end = enemirror2grating(
            gd=self.grating_density,
            energy=self._move_end,
            pmang=self.mirr_pitch_midpoint,
            groff=self.grating_offset,
            pmoff=self.plane_mirror_offset,
            ecg=self.energy_calibration_gradient,
            ecr=self.energy_calibration_reference)

        ### Calculate main cruise moves & speeds from start/end/step
        self._pgm_grat_pitch_speed = (
            abs(self._grat_pitch_end - self._grat_pitch_start) /
            self.getTotalTime())
        ### Calculate ramp distance from required speed and ramp times
        # Set the speed before we read out ramp times in case it is dependent
        self._pgm_grat_pitch.speed = self._pgm_grat_pitch_speed
        # Should really be / | | | | | \ not /| | | | |\
        self._pgm_runupdown_time = self._pgm_grat_pitch.timeToVelocity
        self._pgm_runupdown = self._pgm_grat_pitch_speed / 2 * self._pgm_runupdown_time
        ### Move motor at full speed to start position
        if self.verbose:
            self.logger.info(
                'prepareForMove:_pgm_mirr_pitch.asynchronousMoveTo(%r) @ %r ' %
                (self.mirr_pitch_midpoint * 1000., self._pgm_mirr_pitch.speed))
        self._pgm_mirr_pitch.asynchronousMoveTo(self.mirr_pitch_midpoint *
                                                1000.)

        self._pgm_grat_pitch.speed = self._pgm_grat_pitch_speed_orig
        if self.getGratingMoveDirectionPositive():
            if self.verbose:
                self.logger.info(
                    'prepareForMove:asynchronousMoveTo(%r) @ %r (+ve)' %
                    ((self._grat_pitch_start - self._pgm_runupdown) * 1000.,
                     self._pgm_grat_pitch_speed_orig))
            self._pgm_grat_pitch.asynchronousMoveTo(
                (self._grat_pitch_start - self._pgm_runupdown) * 1000.)
        else:
            if self.verbose:
                self.logger.info(
                    'prepareForMove:asynchronousMoveTo(%r) @ %r (-ve)' %
                    ((self._grat_pitch_start + self._pgm_runupdown) * 1000.,
                     self._pgm_grat_pitch_speed_orig))
            self._pgm_grat_pitch.asynchronousMoveTo(
                (self._grat_pitch_start + self._pgm_runupdown) * 1000.)
        self.waitWhileMoving()
        ### Calculate trigger delays
        if self.verbose:
            self.logger.info('...prepareForMove')