Skip to content

Commit

Permalink
Fix dimensionless units for SCU motion controller (#163)
Browse files Browse the repository at this point in the history
* no sensor SCU units management

Was having issues with the SCU motion controller with no sensor. Units are dimensionless but with name 'steps'. This was not coherent everywhere.

* patch for multiple detected devices
  • Loading branch information
seb5g authored Dec 31, 2024
1 parent a201de7 commit f9fa993
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions instrumental/drivers/motion/_smaract/scu.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

from __future__ import division

from instrumental import u, Q_
from instrumental import u as ureg

from instrumental.log import get_logger
from instrumental.drivers import Facet
from instrumental.drivers import ParamSet
Expand All @@ -17,9 +18,14 @@

log = get_logger(__name__)

ureg._on_redefinition = 'ignore'
Q_ = ureg.Quantity


def list_instruments():
ids, Nids = NiceSCU.GetAvailableDevices(2048)
NiceSCU.InitDevices(OPERATING_MODES['SA_SYNCHRONOUS_COMMUNICATION'])
ids = [NiceSCU.GetDeviceID(ind) for ind in range(Nids)]
pset = []
if Nids > 0:
if Nids == 1:
Expand Down Expand Up @@ -90,6 +96,9 @@ def _initialize(self):
self._frequency = 100
self._open(self.device_id)

if self.units not in ureg:
ureg.define(f'{self.units} = 1 = {self.units}')

def _open(self, device_id):
try:
NiceSCU.ReleaseDevices()
Expand All @@ -116,10 +125,13 @@ def get_devices(cls):
return devs

def has_sensor(self):
ret = self._actuator.GetSensorPresent_S()
if ret == NiceSCU._defs['SA_SENSOR_PRESENT']:
return True
else:
try:
ret = self._actuator.GetSensorPresent_S()
if ret == NiceSCU._defs['SA_SENSOR_PRESENT']:
return True
else:
return False
except SmarActError:
return False

@Facet(units='ms')
Expand Down Expand Up @@ -196,18 +208,19 @@ def move_to(self, value, move_type='rel'):
self._internal_counter += value

def move_home(self, autozero=True):
if not self.has_sensor:
if not self.has_sensor():

log.info('No possible homing as no sensor is present, trying to go to 0 internal counter')
self.move_to(Q_(-self._internal_counter, ''), 'rel')
log.info('No possible homing as no sensor is present, setting current position as 0 in internal counter')
self._internal_counter = 0
self.move_to(Q_(self._internal_counter, self.units), 'abs')

else:
self._actuator.MoveToReference_S(self.hold_time.magnitude,
NiceSCU._defs['SA_AUTO_ZERO'] if autozero else
NiceSCU._defs['SA_NO_AUTO_ZERO'])

def check_position(self):
return Q_(self._internal_counter, '')
return Q_(self._internal_counter, self.units)


class SCULinear(SCU):
Expand Down

0 comments on commit f9fa993

Please sign in to comment.