After running main.py
I get an error:
[pawel@phantom ~]$ python3 main.py
Current position: {"x": 0, "y": 0, "z": 0}
Homing
Traceback (most recent call last):
File "main.py", line 64, in <module>
values = [a for a in values if a >= 0 ]
File "main.py", line 64, in <listcomp>
values = [a for a in values if a >= 0 ]
TypeError: '>=' not supported between instances of 'str' and 'int'
[pawel@phantom ~]$
I assume that problem lies in plugin stage.py
code. It looks like function doesn’t return correct value. The files main.py
and stage.py
are here.
After putting command print(values)
I get: 'generator' object is not subscriptable
.
The main.py
part consists of
def mm(self, position, measurements, absolute=True):
"""Move the stage to a given position.
WARNING! If you specify zeros, the stage might move a long way, as
the default is absolute moves. Position should be a dictionary
with keys called "x", "y", and "z", although we will (for now) also
accept an iterable of three numbers.
"""
try:
pos = {k: int(position[k]) for k in ["x", "y", "z"]}
except:
pos = {k: int(position[i]) for i, k in enumerate(["x", "y", "z"][:len(position)])}
pos['absolute'] = absolute
pos['measurements'] = measurements
response = self.post_json("/extensions/com.openflexure.stage-mapping/actions/stage/move-measure/MoveMeasureAPI", pos)
return response
microscope = ofm_client.find_first_microscope()
microscope = ofm_client.MicroscopeClient("192.168.0.226")
microscope.moveMeasure = mm
# homing routine
pos = microscope.position
print("Current position: " + json.dumps(pos))
print("Homing")
pos['x'] = 0
pos['y'] = 0
pos['z'] = 0
#microscope.move(pos)
zStep = 10
zRange = 1500
maxValue = -1
maxPosition = -1
for z in range(-micronToStep(zRange/2), micronToStep(zRange/2) - micronToStep(zStep), micronToStep(zStep)):
pos = microscope.position
pos['x'] = 0
pos['y'] = 0
pos['z'] = z
values = microscope.moveMeasure(microscope, pos, 5)
values = [a for a in values if a >= 0 ]
values = np.asarray(values)
value = np.median(values)
and the stage.py
contain function MoveMeasureAPI:
i2c = busio.I2C(board.SCL, board.SDA)
ads = ADS.ADS1115(i2c)
ads.gain = 16
ads.mode = ADS.Mode.SINGLE
chan = AnalogIn(ads, ADS.P0)
class MoveMeasureAPI(ActionView):
args = {
"absolute": fields.Boolean(
missing=False, example=False, description="Move to an absolute position"
),
"x": fields.Int(missing=0, example=100),
"y": fields.Int(missing=0, example=100),
"z": fields.Int(missing=0, example=20),
"measurements": fields.Int(missing=0, example=100),
}
def post(self, args):
"""
Move the microscope stage in x, y, z
"""
microscope = find_component("org.openflexure.microscope")
# Handle absolute positioning (calculate a relative move from current position and target)
if (args.get("absolute")) and (microscope.stage): # Only if stage exists
target_position: List[int] = axes_to_array(args, ["x", "y", "z"])
logging.debug("TARGET: %s", (target_position))
position: Tuple[int, int, int] = (
target_position[i] - microscope.stage.position[i] for i in range(3)
)
logging.debug("DELTA: %s", (position))
else:
# Get coordinates from payload
position = axes_to_array(args, ["x", "y", "z"], [0, 0, 0])
logging.debug(position)
for x in range(position[0],):
# Move if stage exists
if microscope.stage:
# Explicitally acquire lock with 1s timeout
with microscope.stage.lock(timeout=1):
microscope.stage.move_rel(position)
else:
logging.warning("Unable to move. No stage found.")
v=[]
for i in range(0, args['measurements']):
v.push(chan.value)
return v