Skip to content

Commit cc65859

Browse files
committed
Remove motor axis offset handling from Motor class
Eliminated all code related to axis offsets in the Motor class, including offset attributes, calculations, and set/get methods. This simplifies position handling to use only step sizes. Also added a debug log for USB device detection in Serial class.
1 parent 1bd2777 commit cc65859

2 files changed

Lines changed: 7 additions & 58 deletions

File tree

uc2rest/motor.py

Lines changed: 6 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ def __init__(self, parent=None):
3636
self.stepSizeY = 1
3737
self.stepSizeZ = 1
3838
self.stepSizeA = 1
39-
self.offsetA = 0
40-
self.offsetX = 0
41-
self.offsetY = 0
42-
self.offsetZ = 0
4339

4440
self.DEFAULT_ACCELERATION = 1000000
4541

@@ -79,12 +75,10 @@ def _callback_motor_status(self, data):
7975
try:
8076
nSteppers = len(data["steppers"])
8177
stepSizes = np.array((self.stepSizeA, self.stepSizeX, self.stepSizeY, self.stepSizeZ))
82-
_physicalStepSizes = np.array((self.stepSizeA, self.stepSizeX, self.stepSizeY, self.stepSizeZ))
83-
_physicalOffsets = np.array((self.offsetA, self.offsetX, self.offsetY, self.offsetZ))
8478
for iMotor in range(nSteppers):
8579
stepperID = data["steppers"][iMotor]["stepperid"]
86-
# Hardware returns steps, convert to physical units: (steps * stepSize - offset)
87-
self.currentPosition[stepperID] = data["steppers"][iMotor]["position"] * stepSizes[stepperID] - _physicalOffsets[stepperID]
80+
# Hardware returns steps, convert to physical units: (steps * stepSize)
81+
self.currentPosition[stepperID] = data["steppers"][iMotor]["position"] * stepSizes[stepperID]
8882
if callable(self._callbackPerKey[0]):
8983
self._callbackPerKey[0](self.currentPosition) # we call the function with the value
9084
except Exception as e:
@@ -177,27 +171,23 @@ def stopFocusScanning(self):
177171
'''################################################################################################################################################
178172
HIGH-LEVEL Functions that rely on basic REST-API functions
179173
################################################################################################################################################'''
180-
def setup_motor(self, axis, minPos, maxPos, stepSize, backlash, offset=0):
174+
def setup_motor(self, axis, minPos, maxPos, stepSize, backlash):
181175
if axis == "X":
182176
self.minPosX = minPos
183177
self.maxPosX = maxPos
184178
self.stepSizeX = stepSize
185-
self.offsetX = offset
186179
elif axis == "Y":
187180
self.minPosY = minPos
188181
self.maxPosY = maxPos
189182
self.stepSizeY = stepSize
190-
self.offsetY = offset
191183
elif axis == "Z":
192184
self.minPosZ = minPos
193185
self.maxPosZ = maxPos
194186
self.stepSizeZ = stepSize
195-
self.offsetZ = offset
196187
elif axis == "A":
197188
self.minPosA = minPos
198189
self.maxPosA = maxPos
199190
self.stepSizeA = stepSize
200-
self.offsetA = offset
201191
self.backlash[self.xyztTo1230(axis)] = backlash
202192

203193
def xyztTo1230(self, axis):
@@ -429,16 +419,6 @@ def move_stepper(self, steps=(0,0,0,0), speed=(1000,1000,1000,1000), is_absolute
429419
if type(steps)==tuple:
430420
steps = np.array(steps)
431421

432-
# optionally add the offset to the steps
433-
if isAbsoluteArray[0]:
434-
steps[0] += self.offsetA
435-
if isAbsoluteArray[1]:
436-
steps[1] += self.offsetX
437-
if isAbsoluteArray[2]:
438-
steps[2] += self.offsetY
439-
if isAbsoluteArray[3]:
440-
steps[3] += self.offsetZ
441-
442422
# Store the target position in physical units BEFORE conversion to hardware steps
443423
targetPositionPhysical = steps.copy()
444424

@@ -557,11 +537,10 @@ def move_stepper(self, steps=(0,0,0,0), speed=(1000,1000,1000,1000), is_absolute
557537
# Update currentPosition to track expected position in physical units
558538
# steps are now in hardware units, so we need to convert back to physical
559539
stepSizes = np.array((self.stepSizeA, self.stepSizeX, self.stepSizeY, self.stepSizeZ))
560-
offSets = np.array((self.offsetA, self.offsetX, self.offsetY, self.offsetZ))
561540
for iMotor in range(self.nMotors):
562541
if isAbsoluteArray[iMotor]:
563-
# For absolute: convert hardware steps back to physical units: (steps * stepSize - offset)
564-
self.currentPosition[iMotor] = steps[iMotor] * stepSizes[iMotor] - offSets[iMotor]
542+
# For absolute: convert hardware steps back to physical units: (steps * stepSize)
543+
self.currentPosition[iMotor] = steps[iMotor] * stepSizes[iMotor]
565544
else:
566545
# For relative: convert step delta to physical delta and add to current position
567546
self.currentPosition[iMotor] = self.currentPosition[iMotor] + (steps[iMotor] * stepSizes[iMotor])
@@ -692,15 +671,14 @@ def get_position(self, axis=None, timeout=1):
692671
}
693672
_position = np.array((0.,0.,0.,0.)) # T,X,Y,Z
694673
_physicalStepSizes = np.array((self.stepSizeA, self.stepSizeX, self.stepSizeY, self.stepSizeZ))
695-
_physicalOffsets = np.array((self.offsetA, self.offsetX, self.offsetY, self.offsetZ))
696674

697675
# this may be an asynchronous call.. #FIXME!
698676
r = self._parent.post_json(path, payload, getReturn = True, nResponses=1, timeout=timeout)[0]
699677
# returns {"motor": }
700678
if "motor" in r :
701679
for index, istepper in enumerate(r["motor"]["steppers"]):
702680
if index >3: break # TODO: We would need to handle other values too soon
703-
_position[istepper["stepperid"]]=istepper["position"]*_physicalStepSizes[self.motorAxisOrder[index]]-_physicalOffsets[self.motorAxisOrder[index]]
681+
_position[istepper["stepperid"]]=istepper["position"]*_physicalStepSizes[self.motorAxisOrder[index]]
704682

705683

706684
return _position
@@ -945,36 +923,6 @@ def get_joystick_direction(self, axis=None, timeout=1):
945923
return result
946924
return None
947925

948-
def set_offset(self, axis=1, offset=0):
949-
'''
950-
This sets the offset relative to the homed position, helpful if you have a reference point and you need to compute the offset
951-
'''
952-
if axis == 0 or str(axis).upper() == "A":
953-
self.offsetA = offset
954-
elif axis == 1 or str(axis) == "X":
955-
self.offsetX = offset
956-
elif axis == 2 or str(axis) == "Y":
957-
self.offsetY = offset
958-
elif axis == 3 or str(axis) == "Z":
959-
self.offsetZ = offset
960-
else:
961-
self._parent.logger.error("Axis not recognized")
962-
963-
def get_offset(self, axis=1):
964-
'''
965-
This gets the offset relative to the homed position, helpful if you have a reference point and you need to compute the offset
966-
'''
967-
if axis == 0 or axis == "A":
968-
return self.offsetA
969-
elif axis == 1 or axis == "X":
970-
return self.offsetX
971-
elif axis == 2 or axis == "Y":
972-
return self.offsetY
973-
elif axis == 3 or axis == "Z":
974-
return self.offsetZ
975-
else:
976-
return False
977-
978926
def get_motor(self, axis=1, timeout=1):
979927
path = "/motor_get"
980928
payload = {

uc2rest/mserial.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ def findCorrectSerialDevice(self):
184184
if self.tryToConnect(port):
185185
self.is_connected = True
186186
self.manufacturer = port.manufacturer
187+
self._logger.debug(f"Found correct USB device: {port.device} - {port.description}")
187188
return self.serialdevice
188189

189190
self.is_connected = False

0 commit comments

Comments
 (0)