Skip to content

Commit

Permalink
Merge branch 'master' into mergemaster
Browse files Browse the repository at this point in the history
  • Loading branch information
beniroquai authored Feb 26, 2024
2 parents 9b8501b + 1b05844 commit fe12f33
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 61 deletions.
2 changes: 1 addition & 1 deletion uc2rest/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def home(self, axis=None, timeout=None, speed=None, direction=None, endposreleas
{
"stepperid": axis,
"timeout":timeout*1000,
"speed":speed,
"speed":direction*abs(speed),
"direction":direction,
"endposrelease":endposrelease,
"endstoppolarity":endstoppolarity
Expand Down
32 changes: 1 addition & 31 deletions uc2rest/laser.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def set_laser(self, channel=1, value=0, auto_filterswitch=False,

}
#self._parent.logger.debug("Setting Laser "+str(channel)+", value: "+str(value))
r = self._parent.post_json(path, payload, getReturn=is_blocking)
r = self._parent.post_json(path, payload, getReturn=is_blocking, timeout=.5)
return r

def set_laserpin(self, laserid=1, laserpin=0):
Expand All @@ -61,33 +61,3 @@ def set_laserpin(self, laserid=1, laserpin=0):
r = self._parent.post_json(path, payload)
return r

def get_laserpins(self):
path = '/laser_get'

r = self._parent.get_json(path)

if type(r) is dict:
# cast laser pins
if "LASER1pin" in r: r["LASER1pin"] = int(r["LASER1pin"])
else: r["LASER1pin"] = 0
if r.__contains__("LASER2pin"): r["LASER2pin"] = int(r["LASER2pin"])
else: r["LASER2pin"] = 0
if r.__contains__("LASER3pin"): r["LASER3pin"] = int(r["LASER3pin"])
else: r["LASER3pin"] = 0
else:
r={}
r["LASER1pin"] = 0
r["LASER2pin"] = 0
r["LASER3pin"] = 0

return r

def get_laserpin(self, laserid=1):
path = '/laser_get'

payload = {
"task": path,
}

r = self._parent.post_json(path, payload,timeout=2)
return r["LASER"+str(laserid)+"pin"]
25 changes: 9 additions & 16 deletions uc2rest/motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ def __init__(self, parent=None):
self.stepSizeA = 1

self.DEFAULT_ACCELERATION = 10000

self.motorAxisOrder = [0,1,2,3] # motor axis is 1,2,3,0 => X,Y,Z,T # FIXME: Hardcoded

# register a callback function for the motor status on the serial loop
if hasattr(self._parent, "serial"):
self._parent.serial.register_callback(self._callback_motor_status, pattern="steppers")

# move motor to wake them up #FIXME: Should not be necessary!
#self.move_stepper(steps=(1,1,1,1), speed=(1000,1000,1000,1000), is_absolute=(False,False,False,False), is_blocking=False)
#self.move_stepper(steps=(-1,-1,-1,-1), speed=(1000,1000,1000,1000), is_absolute=(False,False,False,False), is_blocking=False)
#self.move_stepper(steps=(1,1,1,1), speed=(1000,1000,1000,1000), is_absolute=(False,False,False,False))
#self.move_stepper(steps=(-1,-1,-1,-1), speed=(1000,1000,1000,1000), is_absolute=(False,False,False,False))

def _callback_motor_status(self, data):
''' cast the json in the form:
Expand Down Expand Up @@ -98,7 +98,7 @@ def setTrigger(self, axis="X", pin=1, offset=0, period=1):
}}
r = self._parent.post_json(path, payload)
return r

# {"task": "/motor_act", "stagescan": {"nStepsLine": 100, "dStepsLine": 1, "nTriggerLine": 1, "nStepsPixel": 100, "dStepsPixel": 1, "nTriggerPixel": 1, "delayTimeStep": 10, "stopped": 0, "nFrames": 5}}"}}
def startStageScanning(self, nStepsLine=100, dStepsLine=1, nTriggerLine=1, nStepsPixel=100, dStepsPixel=1, nTriggerPixel=1, delayTimeStep=10, nFrames=5):
path = "/motor_act"
Expand All @@ -117,17 +117,10 @@ def startStageScanning(self, nStepsLine=100, dStepsLine=1, nTriggerLine=1, nStep
}}
r = self._parent.post_json(path, payload)
return r

def stopStageScanning(self):
path = "/motor_act"
payload = {
"task": path,
"stagescan":{
"stopped": 1
}}
r = self._parent.post_json(path, payload)
return r

self.startStageScanning(stopped=1)

def setIsCoreXY(self, isCoreXY = False):
self.isCoreXY = isCoreXY

Expand Down Expand Up @@ -529,7 +522,7 @@ def set_motor_enable(self, enable=None, enableauto=None):
r = self._parent.post_json(path, payload)
return r

def get_position(self, axis=None, timeout=1):
def get_position(self, axis=None, timeout=.2):
# pulls all current positions from the stepper controller
path = "/motor_get"
payload = {
Expand All @@ -540,7 +533,7 @@ def get_position(self, axis=None, timeout=1):
_physicalStepSizes = np.array((self.stepSizeA, self.stepSizeX, self.stepSizeY, self.stepSizeZ))

# this may be an asynchronous call.. #FIXME!
r = self._parent.post_json(path, payload, getReturn = True, nResponses=1)
r = self._parent.post_json(path, payload, getReturn = True, nResponses=1, timeout=timeout)
if "motor" in r:
for index, istepper in enumerate(r["motor"]["steppers"]):
_position[istepper["stepperid"]]=istepper["position"]*_physicalStepSizes[self.motorAxisOrder[index]]
Expand Down
8 changes: 3 additions & 5 deletions uc2rest/mserial.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Serial:
def __init__(self, port, baudrate=115200, timeout=5,
identity="UC2_Feather", parent=None, DEBUG=False):

self.serialdevice= None
self.serialdevice = None
self.serialport = port
self.baudrate = baudrate
self.timeout = timeout
Expand Down Expand Up @@ -179,7 +179,7 @@ def _process_commands(self):
# Check if the last command went through successfully
#if not self.command_queue.empty() and not reading_json:
# currentIdentifier, command = self.command_queue.get()

# device not ready yet
if self.serialdevice is None:
self.is_connected = False
Expand Down Expand Up @@ -294,11 +294,9 @@ def sendMessage(self, command, nResponses=1, timeout = 20):
try:
json_command = json.dumps(command)+"\n"
with self.lock:
t0 = time.time()
self.serialdevice.flush()
self._logger.debug("[SendMessage]: "+str(json_command))
self.serialdevice.write(json_command.encode('utf-8') )
#self._logger.debug("[SendMessage] took: "+str(time.time()-t0))
except Exception as e:
if self.DEBUG: self._logger.error(e)
return "Failed to Send"
Expand Down Expand Up @@ -394,7 +392,7 @@ def __init__(self, port, baudrate, timeout=1):

def flush(self):
pass

def isOpen(self):
return self.is_open

Expand Down
14 changes: 6 additions & 8 deletions uc2rest/temperature.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class Temperature(object):

def __init__(self, parent):
self._parent = parent

'''
##############################################################################################################################
Temperature Controllers
Expand All @@ -12,8 +12,8 @@ def __init__(self, parent):
def stop_heating(self):
r = self.set_temperature(active=0)
return r
def set_temperature(self, active=1, Kp=1000, Ki=0.1, Kd=0.1, target=37, timeout=60000000, updaterate=1000):

def set_temperature(self, active=1, Kp=1000, Ki=0.1, Kd=0.1, target=37, timeout=600000000, updaterate=1000):
# {"task": "/heat_act", "active":1, "Kp":1000, "Ki":0.1, "Kd":0.1, "target":37, "timeout":60000000, "updaterate":1000}
path = "/heat_act"
payload = {
Expand All @@ -28,7 +28,7 @@ def set_temperature(self, active=1, Kp=1000, Ki=0.1, Kd=0.1, target=37, timeout=
}
r = self._parent.post_json(path, payload, getReturn=False)
return r

def get_temperature(self, timeout=0.5):
path = "/heat_get"
r = self._parent.get_json(path, timeout=timeout)
Expand All @@ -40,7 +40,7 @@ def get_temperature(self, timeout=0.5):


if __name__ == "__main__":

#%%
import uc2rest
import time
Expand All @@ -52,5 +52,3 @@ def get_temperature(self, timeout=0.5):
time.sleep(1)
ESP32.temperature.stop_heating()
ESP32.close()


0 comments on commit fe12f33

Please sign in to comment.