|
|
|
@ -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
|
|
|
|
|