update
Arduino File now moves two servos and turns the led on and off Python Script is now able to find the correct USB Port with an Arduino connected. Error was in USB Address. We used '\' instead of '/'. My bad. Sorry. Now it works! Nicenstein!
This commit is contained in:
@@ -3,21 +3,38 @@
|
||||
#define LED 13
|
||||
char msg;
|
||||
Servo s;
|
||||
Servo s3;
|
||||
unsigned int rr = 0;
|
||||
void setup() {
|
||||
//start serial connection
|
||||
Serial.begin(9600);
|
||||
pinMode(LED, OUTPUT);
|
||||
s.attach(2);
|
||||
s3.attach(3);
|
||||
}
|
||||
|
||||
void move0()
|
||||
{
|
||||
s.write(0);
|
||||
s3.write(0);
|
||||
}
|
||||
|
||||
void move1()
|
||||
{
|
||||
s.write(180);
|
||||
s3.write(180);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
msg = Serial.read();
|
||||
if(msg == '1'){
|
||||
digitalWrite(LED, HIGH);
|
||||
s.write(rr);
|
||||
rr = (rr +10) % 180;
|
||||
//delay(100);
|
||||
move0();
|
||||
// s.write(rr);
|
||||
// s3.write(rr);
|
||||
// rr = (rr +10) % 180;
|
||||
delay(500);
|
||||
move1();
|
||||
digitalWrite(LED, LOW);
|
||||
}
|
||||
// else digitalWrite(LED, LOW);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ def init():
|
||||
def init_serial():
|
||||
for com in range(0,4):
|
||||
try:
|
||||
PORT = '\dev\ttyACM' + str(com)
|
||||
PORT = '/dev/ttyACM' + str(com)
|
||||
BAUD = 9600
|
||||
board = serial.Serial(PORT, BAUD)
|
||||
board.close()
|
||||
@@ -38,8 +38,8 @@ def init_serial():
|
||||
return com
|
||||
|
||||
def talker(dictionary, params, videostream, port):
|
||||
#DEVICE = '/dev/ttyACM' + str(port)
|
||||
DEVICE = '/dev/ttyACM0'
|
||||
DEVICE = '/dev/ttyACM' + str(port)
|
||||
#DEVICE = '/dev/ttyACM0'
|
||||
BAUD = 9600
|
||||
ser = serial.Serial(DEVICE, BAUD, timeout=1)
|
||||
#greeting = '0'
|
||||
@@ -54,11 +54,11 @@ def talker(dictionary, params, videostream, port):
|
||||
frame = imutils.resize(frame)
|
||||
(corners, ids, rejected) = cv2.aruco.detectMarkers(frame, dictionary, parameters=params)
|
||||
if len(corners) > 0:
|
||||
frame = marker_detected(frame, corners, 0)
|
||||
frame = marker_detected(frame, corners, port)
|
||||
cv2.imshow("markerXserial", frame)
|
||||
cv2.waitKey(1)
|
||||
|
||||
def marker_detected(frame, corners, ser):
|
||||
def marker_detected(frame, corners, port):
|
||||
(h, w) = frame.shape[:2]
|
||||
thresh_left = w//2 -100
|
||||
thresh_right = w//2 +100
|
||||
@@ -77,7 +77,7 @@ def marker_detected(frame, corners, ser):
|
||||
(bl[0] > thresh_left and bl[0] < thresh_right) or
|
||||
(br[0] > thresh_left and br[0] < thresh_right)):
|
||||
print('stop123')
|
||||
DEVICE = '/dev/ttyACM0'
|
||||
DEVICE = '/dev/ttyACM'+str(port)
|
||||
BAUD = 9600
|
||||
ser2 = serial.Serial(DEVICE, BAUD, timeout=1)
|
||||
ser2.write('1'.encode('utf-8'))
|
||||
@@ -95,6 +95,7 @@ def marker_detected(frame, corners, ser):
|
||||
|
||||
def main():
|
||||
(dictionary, params, vs, com) = init()
|
||||
print(com)
|
||||
talker(dictionary=dictionary, params=params, videostream=vs, port=com)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user