From d2ed38ef510d98f5abbb4e8bc388f629b2931393 Mon Sep 17 00:00:00 2001 From: becker Date: Mon, 22 Jan 2024 12:01:05 +0100 Subject: [PATCH] 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! --- serial/marker_x_serial.ino.ino | 25 +++++++++++++++++++++---- serial/marker_x_serial.py | 13 +++++++------ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/serial/marker_x_serial.ino.ino b/serial/marker_x_serial.ino.ino index 7ac6179..964928e 100644 --- a/serial/marker_x_serial.ino.ino +++ b/serial/marker_x_serial.ino.ino @@ -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); } diff --git a/serial/marker_x_serial.py b/serial/marker_x_serial.py index a2eb605..4f587d0 100644 --- a/serial/marker_x_serial.py +++ b/serial/marker_x_serial.py @@ -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__":