adding untracked files
parent
374d67df52
commit
8678b2e4ec
@ -0,0 +1,171 @@
|
||||
// Include the AccelStepper library:
|
||||
#include <AccelStepper.h>
|
||||
|
||||
// Define stepper motor connections and motor interface type. Motor interface type must be set to 1 when using a driver:
|
||||
|
||||
// Set stepper 1 pins
|
||||
#define m1LimitNegPin 2
|
||||
#define m1LimitPosPin 3
|
||||
#define m1DirPin 4
|
||||
#define m1StepPin 5
|
||||
#define m1PowerPin 6
|
||||
|
||||
// Set stepper 2 pins
|
||||
#define m2LimitNegPin 9
|
||||
#define m2LimitPosPin 10
|
||||
#define m2DirPin 11
|
||||
#define m2StepPin 12
|
||||
#define m2PowerPin 13
|
||||
|
||||
#define motorInterfaceType 1
|
||||
|
||||
// Create a new instance of the AccelStepper class:
|
||||
AccelStepper m1Stepper = AccelStepper(motorInterfaceType, m1StepPin, m1DirPin);
|
||||
AccelStepper m2Stepper = AccelStepper(motorInterfaceType, m2StepPin, m2DirPin);
|
||||
|
||||
unsigned long previousMillis = 0;
|
||||
unsigned long currentMillis = 0;
|
||||
|
||||
void setup() {
|
||||
|
||||
pinMode(m1PowerPin, OUTPUT);
|
||||
pinMode(m1LimitNegPin, INPUT);
|
||||
pinMode(m1LimitPosPin, INPUT);
|
||||
|
||||
pinMode(m2PowerPin, OUTPUT);
|
||||
pinMode(m2LimitNegPin, INPUT);
|
||||
pinMode(m2LimitPosPin, INPUT);
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
// Set the maximum speed in steps per second:
|
||||
m1Stepper.setMaxSpeed(200);
|
||||
m1Stepper.setAcceleration(100);
|
||||
m1Stepper.setCurrentPosition(0);
|
||||
|
||||
m2Stepper.setMaxSpeed(200);
|
||||
m2Stepper.setAcceleration(100);
|
||||
m2Stepper.setCurrentPosition(0);
|
||||
}
|
||||
|
||||
|
||||
int integerValue=0;
|
||||
bool negativeNumber = false; // track if number is negative
|
||||
char incomingByte;
|
||||
|
||||
void loop() {
|
||||
|
||||
currentMillis = millis();
|
||||
|
||||
int m1EorNeg = digitalRead(m1LimitNegPin);
|
||||
int m1EorPos = digitalRead(m1LimitPosPin);
|
||||
|
||||
int m2EorNeg = digitalRead(m2LimitNegPin);
|
||||
int m2EorPos = digitalRead(m2LimitPosPin);
|
||||
|
||||
if (currentMillis - previousMillis >= 1000 == true ) {
|
||||
Serial.println("------Stepper 1------");
|
||||
Serial.print("m1EorPos:");
|
||||
Serial.println(m1EorNeg);
|
||||
Serial.print("m1EorNeg: ");
|
||||
Serial.println(m1EorPos);
|
||||
Serial.print("m1CurPos: ");
|
||||
Serial.println(m1Stepper.currentPosition() * -1);
|
||||
Serial.print("m1TarPos: ");
|
||||
Serial.println(m1Stepper.targetPosition() * -1);
|
||||
Serial.println("");
|
||||
|
||||
Serial.println("------Stepper 2------");
|
||||
Serial.print("m2EorPos: ");
|
||||
Serial.println(m2EorNeg);
|
||||
Serial.print("m2EorNeg: ");
|
||||
Serial.println(m2EorPos);
|
||||
Serial.print("m2CurPos: ");
|
||||
Serial.println(m2Stepper.currentPosition() * -1);
|
||||
Serial.print("m2TarPos: ");
|
||||
Serial.println(m2Stepper.targetPosition() * -1);
|
||||
Serial.println("");
|
||||
|
||||
previousMillis = currentMillis;
|
||||
}
|
||||
|
||||
// limit switch logic for stepper 1
|
||||
if ((m1EorNeg < m1EorPos) && (m1Stepper.targetPosition() > m1Stepper.currentPosition())) {
|
||||
m1Stepper.setSpeed(0);
|
||||
m1Stepper.moveTo(m1Stepper.currentPosition());
|
||||
digitalWrite(m1PowerPin, HIGH);
|
||||
} else if ((m1EorNeg > m1EorPos) && (m1Stepper.targetPosition() < m1Stepper.currentPosition())) {
|
||||
m1Stepper.setSpeed(0);
|
||||
m1Stepper.moveTo(m1Stepper.currentPosition());
|
||||
digitalWrite(m1PowerPin, HIGH);
|
||||
} else if (m1Stepper.targetPosition() == m1Stepper.currentPosition()) {
|
||||
digitalWrite(m1PowerPin, HIGH);
|
||||
} else {
|
||||
digitalWrite(m1PowerPin, LOW);
|
||||
m1Stepper.run();
|
||||
}
|
||||
|
||||
// limit switch logic for stepper 2
|
||||
if ((m2EorNeg < m2EorPos) && (m2Stepper.targetPosition() > m2Stepper.currentPosition())) {
|
||||
m2Stepper.setSpeed(0);
|
||||
m2Stepper.moveTo(m2Stepper.currentPosition());
|
||||
digitalWrite(m2PowerPin, HIGH);
|
||||
} else if ((m2EorNeg > m2EorPos) && (m2Stepper.targetPosition() < m2Stepper.currentPosition())) {
|
||||
m2Stepper.setSpeed(0);
|
||||
m2Stepper.moveTo(m1Stepper.currentPosition());
|
||||
digitalWrite(m2PowerPin, HIGH);
|
||||
} else if (m2Stepper.targetPosition() == m2Stepper.currentPosition()) {
|
||||
digitalWrite(m2PowerPin, HIGH);
|
||||
} else {
|
||||
digitalWrite(m2PowerPin, LOW);
|
||||
m2Stepper.run();
|
||||
}
|
||||
|
||||
if (Serial.available() > 0) { // something came across serial
|
||||
integerValue = 0; // throw away previous integerValue
|
||||
negativeNumber = false; // reset for negative
|
||||
|
||||
while(1) { // force into a loop until 'n' is received
|
||||
incomingByte = Serial.read();
|
||||
if (incomingByte == ' ') break; // exit the while(1), we're done receiving
|
||||
if (incomingByte == -1) continue; // if no characters are in the buffer read() returns -1
|
||||
if (incomingByte == '-') {
|
||||
negativeNumber = true;
|
||||
continue;
|
||||
}
|
||||
integerValue *= 10; // shift left 1 decimal place
|
||||
integerValue = ((incomingByte - 48) + integerValue); // convert ASCII to integer, add, and shift left 1 decimal place
|
||||
}
|
||||
|
||||
if (negativeNumber)
|
||||
integerValue = -integerValue;
|
||||
|
||||
integerValue = -integerValue; // this makes up for the fact that things are backwards
|
||||
m1Stepper.moveTo(integerValue);
|
||||
|
||||
|
||||
integerValue = 0; // throw away previous integerValue
|
||||
negativeNumber = false; // reset for negative
|
||||
|
||||
while(1) { // force into a loop until 'n' is received
|
||||
incomingByte = Serial.read();
|
||||
if (incomingByte == '\n') break; // exit the while(1), we're done receiving
|
||||
if (incomingByte == -1) continue; // if no characters are in the buffer read() returns -1
|
||||
if (incomingByte == '-') {
|
||||
negativeNumber = true;
|
||||
continue;
|
||||
}
|
||||
integerValue *= 10; // shift left 1 decimal place
|
||||
integerValue = ((incomingByte - 48) + integerValue); // convert ASCII to integer, add, and shift left 1 decimal place
|
||||
}
|
||||
|
||||
if (negativeNumber)
|
||||
integerValue = -integerValue;
|
||||
|
||||
integerValue = -integerValue; // this makes up for the fact that things are backwards
|
||||
m2Stepper.moveTo(integerValue);
|
||||
|
||||
}
|
||||
|
||||
//delay(100);
|
||||
}
|
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 12 MiB |
Binary file not shown.
After Width: | Height: | Size: 2.6 MiB |
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 31 MiB |
Binary file not shown.
After Width: | Height: | Size: 7.3 MiB |
Binary file not shown.
After Width: | Height: | Size: 17 MiB |
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 3.2 MiB |
Binary file not shown.
@ -0,0 +1,99 @@
|
||||
#This is a proof of concept for motion tracking of the vernier in very early stages
|
||||
# TODO: stabilize the tracker and connect the plumbing via OSC to the SuperCollider app
|
||||
# and get the stream to feed to the Open Stage Control GUI for calibration
|
||||
|
||||
import cv2
|
||||
import sys
|
||||
|
||||
# Read video (eventually will be the live capture from the camera)
|
||||
video = cv2.VideoCapture("/home/mwinter/Sketches/a_history_of_the_domino_problem/recs/a_history_of_the_domino_problem_final_documentation_hq.mp4")
|
||||
|
||||
# Exit if video not opened.
|
||||
if not video.isOpened():
|
||||
print("Could not open video")
|
||||
sys.exit()
|
||||
|
||||
# Read first frame.
|
||||
video.set(cv2.CAP_PROP_POS_FRAMES, 5000)
|
||||
ok, frame = video.read()
|
||||
if not ok:
|
||||
print('Cannot read video file')
|
||||
sys.exit()
|
||||
|
||||
# Define an initial bounding box
|
||||
#bbox = (287, 23, 86, 320)
|
||||
|
||||
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
|
||||
#frame = cv2.GaussianBlur(frame,(5,5),cv2.BORDER_DEFAULT)
|
||||
r1 = cv2.selectROI('Tracking', frame)
|
||||
r2 = cv2.selectROI('Tracking', frame)
|
||||
#r = (606, 448, 35, 177);
|
||||
#cv2.destroyWindow('select')
|
||||
#print(r)
|
||||
crop1 = frame[int(r1[1]):int(r1[1]+r1[3]), int(r1[0]):int(r1[0]+r1[2])]
|
||||
crop2 = frame[int(r2[1]):int(r2[1]+r2[3]), int(r2[0]):int(r2[0]+r2[2])]
|
||||
|
||||
|
||||
|
||||
while True:
|
||||
# Read a new frame
|
||||
ok, frame = video.read()
|
||||
if not ok:
|
||||
break
|
||||
|
||||
crop1 = frame[int(r1[1]):int(r1[1]+r1[3]), int(r1[0]):int(r1[0]+r1[2])]
|
||||
crop1 = cv2.cvtColor(crop1, cv2.COLOR_RGB2GRAY)
|
||||
crop1 = cv2.GaussianBlur(crop1,(5,5),cv2.BORDER_DEFAULT)
|
||||
|
||||
crop2 = frame[int(r2[1]):int(r2[1]+r2[3]), int(r2[0]):int(r2[0]+r2[2])]
|
||||
crop2 = cv2.cvtColor(crop2, cv2.COLOR_RGB2GRAY)
|
||||
crop2 = cv2.GaussianBlur(crop2,(5,5),cv2.BORDER_DEFAULT)
|
||||
|
||||
ret1, thresh1 = cv2.threshold(crop1, 230, 255, cv2.THRESH_OTSU + cv2.THRESH_BINARY)
|
||||
cnts1 = cv2.findContours(thresh1.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
||||
cnts1 = cnts1[1]
|
||||
|
||||
ret2, thresh2 = cv2.threshold(crop2, 230, 255, cv2.THRESH_OTSU + cv2.THRESH_BINARY)
|
||||
cnts2 = cv2.findContours(thresh2.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
||||
cnts2 = cnts2[1]
|
||||
|
||||
center = None
|
||||
|
||||
for c in cnts1[0:2]:
|
||||
# calculate moments for each contour
|
||||
M = cv2.moments(c)
|
||||
# calculate x,y coordinate of center
|
||||
if M["m00"] != 0:
|
||||
cX = int(M["m10"] / M["m00"])
|
||||
cY = int(M["m01"] / M["m00"])
|
||||
#else:
|
||||
# cX, cY = 0, 0
|
||||
#print(cY)
|
||||
cv2.circle(frame, (int(r1[0]) + cX, int(r1[1]) + cY), 5, (255, 255, 255), -1)
|
||||
|
||||
# only proceed if at least one contour was found
|
||||
if len(cnts2) > 0:
|
||||
# find the largest contour in the mask, then use
|
||||
# it to compute the minimum enclosing circle and
|
||||
# centroid
|
||||
c = max(cnts2, key=cv2.contourArea)
|
||||
((x, y), radius) = cv2.minEnclosingCircle(c)
|
||||
M = cv2.moments(c)
|
||||
center = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"]))
|
||||
|
||||
# only proceed if the radius meets a minimum size
|
||||
if radius > 5:
|
||||
# draw the circle and centroid on the frame,
|
||||
# then update the list of tracked points
|
||||
cv2.circle(frame, (int(x), int(y)), int(radius), (0, 255, 255), 2)
|
||||
cv2.circle(frame, center, 5, (0, 0, 255), -1)
|
||||
|
||||
# Display result
|
||||
cv2.imshow("Tracking", frame)
|
||||
#cv2.imshow("Crop", crop)
|
||||
|
||||
# Exit if ESC pressed
|
||||
k = cv2.waitKey(1) & 0xff
|
||||
if k == 27 :
|
||||
cv2.destroyWindow('Tracking')
|
||||
break
|
Loading…
Reference in New Issue