From 73b1420c3a1bf33cafc7e7017c07ee29b6aaa486 Mon Sep 17 00:00:00 2001 From: mwinter Date: Mon, 30 Oct 2023 18:08:11 +0000 Subject: [PATCH] changes to alignment software for final position --- arduino/multistepper/multistepper.ino | 4 +-- openstagecontrol/stepper_control_gui.json | 35 +---------------------- python/vernier_tracker.py | 13 ++++----- supercollider/installation_control.scd | 31 ++++++++++---------- 4 files changed, 24 insertions(+), 59 deletions(-) diff --git a/arduino/multistepper/multistepper.ino b/arduino/multistepper/multistepper.ino index 00d725b..a290c84 100644 --- a/arduino/multistepper/multistepper.ino +++ b/arduino/multistepper/multistepper.ino @@ -36,8 +36,8 @@ bool ySafeMode = false; long yLimitPos = 0; int microsteps = 1; -float maxSpeedConstant = 100 * microsteps; -float accelerationConstant = 50 * microsteps; +float maxSpeedConstant = 300 * microsteps; +float accelerationConstant = 100 * microsteps; void setup() { diff --git a/openstagecontrol/stepper_control_gui.json b/openstagecontrol/stepper_control_gui.json index 033e0ca..efb559e 100644 --- a/openstagecontrol/stepper_control_gui.json +++ b/openstagecontrol/stepper_control_gui.json @@ -628,7 +628,7 @@ "target": "", "bypass": false, "decimals": 2, - "mode": "push", + "mode": "toggle", "lock": false, "visible": true, "interaction": true, @@ -1273,39 +1273,6 @@ "ignoreDefaults": false, "onCreate": "", "onValue": "" - }, - { - "type": "frame", - "top": "auto", - "left": "auto", - "id": "frame_3", - "linkId": "", - "width": 600, - "height": 400, - "css": "> .frame {\n background-color: black;\n border: 2px solid grey;\n}\n:host {\n top:calc(50% - 200rem);\n left:calc(50% - 800rem);\n z-index: 10;\n}", - "default": "", - "value": "http://10.0.0.5:5000", - "address": "/frame_3", - "preArgs": "", - "colorWidget": "auto", - "html": "@{this.id}", - "lock": false, - "visible": true, - "interaction": true, - "comments": "", - "expand": "false", - "colorText": "auto", - "colorStroke": "auto", - "colorFill": "auto", - "alphaStroke": "auto", - "alphaFillOff": "auto", - "alphaFillOn": "auto", - "lineWidth": "auto", - "borderRadius": "auto", - "padding": "auto", - "target": "", - "onCreate": "", - "onValue": "" } ], "tabs": [], diff --git a/python/vernier_tracker.py b/python/vernier_tracker.py index e958e4f..1d499f2 100644 --- a/python/vernier_tracker.py +++ b/python/vernier_tracker.py @@ -86,10 +86,10 @@ def track(frame, roi, dKernel): replaceCrop(frame, roiFineOuter, thresh) meanCourse = pow(cropCoarse.mean(), 1) - #print(meanCourse) + print(meanCourse) mean = 0 direction = 1 - if(meanCourse > 20): + if(meanCourse > 40): # this could potentially be made more efficient by cropping from cropFineOuter cropFineInner = crop(frame, roiFineInner) # this could potentially be made more efficient by cropping from cropFineInner @@ -129,7 +129,7 @@ def picameraToCVTrack(): distanceX = track(frame, roiX, dilationKernel) distanceY = track(frame, roiY, dilationKernel) * -1 - oscClient.send_message("/trackerpos", [distanceX, distanceY]) + oscClient.send_message("/trackerpos", [distanceX, distanceY * -1]) drawRoi(frame, roiX) drawRoi(frame, roiY) @@ -208,7 +208,7 @@ picam2 = Picamera2() #picam2.start_preview(Preview.QTGL) #max resolution is (4056, 3040) which is more like 10 fps #config = picam2.create_preview_configuration(main={"size": (2028, 1520)}, lores={"size": (768, 768), "format": "YUV420"}, transform=Transform(vflip=False)) -config = picam2.create_preview_configuration(main={"size": (4056, 3040)}, lores={"size": (768, 768), "format": "YUV420"}, transform=Transform(vflip=False)) +config = picam2.create_preview_configuration(main={"size": (4056, 3040)}, lores={"size": (768, 768), "format": "YUV420"}, transform=Transform(hflip=True, vflip=False)) picam2.configure(config) app = QApplication([]) @@ -237,8 +237,8 @@ cv2.resizeWindow("Frame", 1350, 1350) cv2.setMouseCallback("Frame", moveROI) #picam2.controls.ScalerCrop = (800, 0, 3040, 3040) -picam2.controls.ScalerCrop = (1375, 550, 1800, 1800) -picam2.controls.ScalerCrop = (1100, 400, 2125, 2125) +#picam2.controls.ScalerCrop = (1375, 550, 1800, 1800) +picam2.controls.ScalerCrop = (925, 630, 2025, 2025) #picam2.controls.Brightness = 0.2 picam2.controls.Contrast = 1.1 #picam2.set_controls({"ExposureValue": 2}) @@ -251,7 +251,6 @@ picam2.set_controls({"Saturation": 0}) (w0, h0) = picam2.stream_configuration("main")["size"] (w1, h1) = picam2.stream_configuration("lores")["size"] s1 = picam2.stream_configuration("lores")["stride"] -print(h1) picam2.start() diff --git a/supercollider/installation_control.scd b/supercollider/installation_control.scd index 7735f56..440a1ba 100644 --- a/supercollider/installation_control.scd +++ b/supercollider/installation_control.scd @@ -14,6 +14,7 @@ imgPositions = 9.collect({nil}); curPos = Point.new(0, 0); tarPos = Point.new(0, 0); netAddress = NetAddr.new("127.0.0.1", 8080); +lastSelect = 0; ~serialPort = SerialPort("/dev/ttyACM0", baudrate: 115200, crtscts: true); // recieve motor feedback @@ -27,7 +28,7 @@ netAddress = NetAddr.new("127.0.0.1", 8080); byte = ~serialPort.read; if(byte==13, { if(str[1].asString == "[", { - valArray = str.asString.interpret;//.postln; + valArray = str.asString.interpret.postln; curPos = Point.new(valArray[0], valArray[1]); limitSwitchNeg = valArray[2]; limitSwitchPos = valArray[3]; @@ -82,7 +83,7 @@ jogControl = {arg axis; count.postln; jogRate = pow(count, 2) * 500; if(axis == '/jog_horizontal', { - tarPos.x = curPos.x + (jogRate * jogDirection); + tarPos.x = curPos.x + (jogRate * jogDirection * -1); }, { tarPos.y = curPos.y + (jogRate * jogDirection); }); @@ -99,13 +100,6 @@ jogControl = {arg axis; automation = false; //netAddress.sendMsg("/STATE/SET", "{automate: 0}"); }, axis, netAddress); - OSCFunc({arg msg; - //tarPos.x = curPos.x + (1000 * msg[1]); - //moveTo.value(tarPos); - if(msg[1] == 0, {count = 0; jogRate = 0; jog.pause()}, {jogRate = 10; jogDirection = msg[1]; jog.play(AppClock)}); - automation = false; - //netAddress.sendMsg("/STATE/SET", "{automate: 0}"); - }, axis, NetAddr.localAddr) }; jogHorizontal = jogControl.value('/jog_horizontal'); @@ -115,7 +109,8 @@ imgSelect = { //var lastSelect = nil; OSCFunc({arg msg; var imgIndex; - if(msg[1] > 0, { + msg.postln; + if((msg[1] > 0), { imgIndex = msg[1] - 1; imgIndex.postln; if(imgPositions[imgIndex] != nil, {tarPos = imgPositions[imgIndex].deepCopy; moveTo.value(tarPos)}); @@ -125,6 +120,8 @@ imgSelect = { //netAddress.sendMsg("/STATE/SET", "{automate: 0}"); lastSelect = imgIndex; }, { + lastSelect.postln; + if(msg[1] == ((lastSelect + 1) * -1), {"here".postln; lastSelect = 0}) //lastSelect = 0; /* imgIndex = msg[1].neg - 1; @@ -170,18 +167,17 @@ automate = OSCFunc({arg msg; trackerPos = OSCFunc({arg msg; //imgPositions.postln[lastSelect.postln]; - if(lastSelect != nil, { + if(lastSelect.postln > 0, { var distX, distY, isFocusing; distX = curPos.x - imgPositions[lastSelect].x; distY = curPos.y - imgPositions[lastSelect].y; isFocusing = false; - if((imgPositions[lastSelect] != nil) && (distX.abs < 500) && (msg[1].abs > 6000), { - tarPos.x = curPos.x + (10 * msg[1].sign * -1); + if((imgPositions[lastSelect] != nil) && (distX.abs < 500) && (msg[1].abs > 8000), { + tarPos.x = curPos.x + (10 * msg[1].sign);// * -1); isFocusing = true; - //NetAddr.localAddr.sendMsg('/jog_horizontal', msg[1].sign.postln * -1); }); - if((imgPositions[lastSelect] != nil) && (distY.abs < 500) && (msg[2].abs > 6000), { - tarPos.y = curPos.y + (10 * msg[2].sign * -1); + if((imgPositions[lastSelect] != nil) && (distY.abs < 500) && (msg[2].abs > 8000), { + tarPos.y = curPos.y + (10 * msg[2].sign);// * -1); isFocusing = true; }); if(isFocusing, {moveTo.value(tarPos)}); @@ -189,11 +185,14 @@ trackerPos = OSCFunc({arg msg; //msg.postln; }, '/trackerpos'); ) + +//in case of emergency ~serialPort.close ~serialPort = SerialPort.new("/dev/ttyACM0", baudrate: 115200, crtscts: true); ~serialListener.reset ~serialListener.play(AppClock); +//This is legacy code - should be removed soonish ( // TODO: // set position to 0