Skip to content

Commit

Permalink
mercury examples
Browse files Browse the repository at this point in the history
  • Loading branch information
SilasM2001 committed Apr 2, 2024
1 parent 34fb887 commit e84bb14
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 6 deletions.
29 changes: 26 additions & 3 deletions basil/HL/mercury.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class Mercury(HardwareLayer):
Therefore '\x03' has to be set a read termination in the transport layer! And a read termination
of 0.1 s should be set!
Despite the manual telling SCPI compatibility, this is not correct for our devices with our
firmware.
'''
firmware. The manual explaining every "native" command: https://twiki.cern.ch/twiki/pub/ILCBDSColl/Phase2Preparations/MercuryNativeCommands_MS176E101.pdf
The overall manual: https://www.le.infn.it/~chiodini/allow_listing/pi/Manuals/C-863_Benutzerhandbuch_Kurzversion_MS205Dqu200.pdf'''

def __init__(self, intf, conf):
super(Mercury, self).__init__(intf, conf)
Expand Down Expand Up @@ -44,11 +44,27 @@ def _write_command(self, command, address=None):
for a in self._addresses:
self.write(bytearray.fromhex("01%d" % (a + 30)) + command.encode())


def get_address(self, address):
self._write_command("TB", address)
return self.read()

def get_position(self, address=None):
def motor_on(self,address=None):
self._write_command("MN", address)

Check warning on line 53 in basil/HL/mercury.py

View check run for this annotation

Codecov / codecov/patch

basil/HL/mercury.py#L52-L53

Added lines #L52 - L53 were not covered by tests

def motor_off(self,address=None):
self._write_command("MF", address)

Check warning on line 56 in basil/HL/mercury.py

View check run for this annotation

Codecov / codecov/patch

basil/HL/mercury.py#L55-L56

Added lines #L55 - L56 were not covered by tests

def LL(self,address=None): #logic active low
self._write_command("LL", address)

Check warning on line 59 in basil/HL/mercury.py

View check run for this annotation

Codecov / codecov/patch

basil/HL/mercury.py#L58-L59

Added lines #L58 - L59 were not covered by tests

def set_home(self,address=None): #Defines the current position as 0
self._write_command("DH", address)

Check warning on line 62 in basil/HL/mercury.py

View check run for this annotation

Codecov / codecov/patch

basil/HL/mercury.py#L61-L62

Added lines #L61 - L62 were not covered by tests

def go_home(self,address=None): #Moves motor to zero position
self._write_command("GH", address)

Check warning on line 65 in basil/HL/mercury.py

View check run for this annotation

Codecov / codecov/patch

basil/HL/mercury.py#L64-L65

Added lines #L64 - L65 were not covered by tests

def get_position(self, address=None):

Check warning on line 67 in basil/HL/mercury.py

View check run for this annotation

Codecov / codecov/patch

basil/HL/mercury.py#L67

Added line #L67 was not covered by tests
self._write_command("TP", address)
return int(self.read()[2:-3])

Expand All @@ -61,3 +77,10 @@ def set_position(self, value, address=None):

def move_relative(self, value, address=None):
self._write_command("MR%d" % value, address)

def abort(self, address=None):
self._write_command("AB", address)

Check warning on line 82 in basil/HL/mercury.py

View check run for this annotation

Codecov / codecov/patch

basil/HL/mercury.py#L81-L82

Added lines #L81 - L82 were not covered by tests

def find_edge(self, n, address=None):
self._write_command("FE%d" % n, address)

Check warning on line 85 in basil/HL/mercury.py

View check run for this annotation

Codecov / codecov/patch

basil/HL/mercury.py#L84-L85

Added lines #L84 - L85 were not covered by tests

54 changes: 51 additions & 3 deletions examples/lab_devices/MotorStage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,58 @@
''' This script shows how to use a Motor Stage
'''


import time
from basil.dut import Dut

dut = Dut('mercury_pyserial.yaml')
dut.init()
print(dut["MotorStage"].get_position())
# dut["MotorStage"].set_position(100000)

############## setup (for c-862) #######
#needed if mercury is connected the first time after power up
#MN Motor=on
#LL: switch logic active low (hardware)
dut["MotorStage"].motor_on(address=1)
time.sleep(0.1)
dut["MotorStage"].LL(address=1)
time.sleep(0.1)
#####################################


def wait_pos(target,precision,address): #waits/prints position until desired precision is reached
print("Moving motore from:",dut["MotorStage"].get_position(address),"to" ,target) #absolute target
done=False
while done is False:
pos=dut["MotorStage"].get_position(address)
print("motor at",pos,"moving to",target)
if abs(pos-target)<= precision:
done=True
else:
time.sleep(0.5)
return pos


######################examples

#print(dut["MotorStage"].get_channel(address=1),"status") # prints status code
#time.sleep(2)

########### example of an absoulute movement using sleep

print(dut["MotorStage"].get_position(address=1),"position before") #print position before movement

dut["MotorStage"].set_position(10000,address=1) #absolute movement

time.sleep(10) #wait for movement

print(dut["MotorStage"].get_position(address=1),"position after") #print position after movement

########### example of an relative movement using wait_pos

#move_r=20000 #relative movement of 20000
#target = dut["MotorStage"].get_position(address=1)+move_r #wait_pos needs absolute target

#dut["MotorStage"].move_relative(move_r,address=1) #relative movement
#wait_pos(target,500,1) #wait/print movement

########### abort any movement abruptly:
#dut["MotorStage"].abort(address=1)

0 comments on commit e84bb14

Please sign in to comment.