Addpython motor simulation for taipan
This commit is contained in:
91
site_ansto/instrument/TEST_SICS/fakeGalil/SIM_GALIL_taipan.py
Executable file
91
site_ansto/instrument/TEST_SICS/fakeGalil/SIM_GALIL_taipan.py
Executable file
@@ -0,0 +1,91 @@
|
||||
#!/usr//bin/env python
|
||||
# vim: ts=8 sts=4 sw=4 expandtab
|
||||
# Author: Douglas Clowes (dcl@ansto.gov.au) 2012-06-29
|
||||
from twisted.internet import reactor
|
||||
from twisted.python import log
|
||||
from twisted.internet.task import LoopingCall
|
||||
import random
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
import inspect
|
||||
from galilfactory import GalilFactory
|
||||
from counterclient import CounterClientFactory
|
||||
from powdersample import CubicPowderSample
|
||||
|
||||
log.startLogging(sys.stdout)
|
||||
|
||||
beam_monitor_counter = None
|
||||
detector_counter = None
|
||||
beam_monitor_rate = None
|
||||
nickel = CubicPowderSample()
|
||||
|
||||
def stopCallbackM1M2(motor):
|
||||
global nickel
|
||||
global beam_monitor_rate
|
||||
mu = m2.getPosition() / 2.0
|
||||
nickel.set_wavelength_from_theta_pg002(mu)
|
||||
x = m1.getPosition()
|
||||
y = nickel.funx(abs(x), abs(mu), 0.2)
|
||||
baseline = 1000
|
||||
height = int(5000 * y) + baseline
|
||||
beam_monitor_rate = height
|
||||
print "My Height at", x, "is", height
|
||||
if beam_monitor_counter:
|
||||
beam_monitor_counter.setCountRate(height)
|
||||
if detector_counter:
|
||||
stopCallbackS2(m1)
|
||||
print "Motor M1, M2 at:", m1.getPosition(), m2.getPosition(), ", wavelength=", nickel.wavelength, ", mEv=", nickel.mEv
|
||||
|
||||
|
||||
def stopCallbackS2(motor):
|
||||
global nickel
|
||||
global beam_monitor_rate
|
||||
if beam_monitor_rate == None:
|
||||
m1.stopCallback(m1)
|
||||
x = s2.getPosition()
|
||||
y = nickel.calc(abs(x))
|
||||
baseline = 2000
|
||||
height = int(beam_monitor_rate * y) + baseline
|
||||
print "My Height at", x, "is", height
|
||||
if detector_counter:
|
||||
detector_counter.setCountRate(height)
|
||||
print "Motor S2 at:", s2.getPosition()
|
||||
|
||||
def device_iterator():
|
||||
now = time.time()
|
||||
m1.doIteration(now)
|
||||
m2.doIteration(now)
|
||||
s2.doIteration(now)
|
||||
|
||||
basePort = 62034 # Echidna
|
||||
basePort = 62134 # Wombat
|
||||
basePort = 62430 # Quokka
|
||||
basePort = 62730 # Taipan
|
||||
devices = {}
|
||||
for dev in range(0, 6):
|
||||
port = basePort + dev
|
||||
controllerName = "mc%d" % (dev + 1)
|
||||
factory = GalilFactory(port)
|
||||
devices[controllerName] = factory.device
|
||||
reactor.listenTCP(port, factory)
|
||||
|
||||
s2 = devices["mc2"].motors["F"]
|
||||
s2.moveCallback = s2.stopCallback = stopCallbackS2
|
||||
m1 = devices["mc3"].motors["E"]
|
||||
m1.moveCallback = m1.stopCallback = stopCallbackM1M2
|
||||
m2 = devices["mc1"].motors["F"]
|
||||
m2.moveCallback = m2.stopCallback = stopCallbackM1M2
|
||||
m1.stopCallback(m1)
|
||||
m2.stopCallback(m2)
|
||||
s2.stopCallback(s2)
|
||||
|
||||
beam_monitor_counter = CounterClientFactory()
|
||||
detector_counter = CounterClientFactory()
|
||||
connector1 = reactor.connectTCP("localhost", 33001, beam_monitor_counter)
|
||||
connector2 = reactor.connectTCP("localhost", 33000, detector_counter)
|
||||
print "Connector1:", connector1.getDestination()
|
||||
print "Connector2:", connector2.getDestination()
|
||||
lc = LoopingCall(device_iterator)
|
||||
lc.start(0.05)
|
||||
reactor.run()
|
||||
Reference in New Issue
Block a user