From 293dcbd4a347d2ac9d0347fcbdb7fabab6abbaa4 Mon Sep 17 00:00:00 2001 From: becker Date: Mon, 22 Jan 2024 13:25:30 +0100 Subject: [PATCH] update communication between script and arduino now implemented. Moves servos and a led blinks. Needs to be tested asap. --- marker_attack_node/marker_attack_3.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/marker_attack_node/marker_attack_3.py b/marker_attack_node/marker_attack_3.py index edec1f1..928d4b6 100644 --- a/marker_attack_node/marker_attack_3.py +++ b/marker_attack_node/marker_attack_3.py @@ -8,6 +8,7 @@ import cv2 import time import numpy as np import serial +import subprocess from std_msgs.msg import String from sensor_msgs.msg import Image from cv_bridge import CvBridge, CvBridgeError @@ -35,7 +36,10 @@ class marker_attacker(): self.arucoDict = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_ARUCO_ORIGINAL) self.arucoParams = cv2.aruco.DetectorParameters_create() self.maxMinDepth = 550 - + self.com = self.init_serial() + DEVICE = '/dev/ttyACM'+str(self.com) + BAUD = 9600 + self.s = serial.Serial(DEVICE, BAUD, timeout=1) ### For turtle controll self.pub = rospy.Publisher(turlte_bot_topic, Twist, queue_size=1) # self.wait_for_subscribers() @@ -169,13 +173,14 @@ class marker_attacker(): self.depth_counter += 1 #Sometimes the data is inacurate make sure we get the data at least 5times if self.depth_counter > 4: print("We are really there") - self.target_id += 1 - self.target_id = self.target_id % 2 - self.depth_counter = 0 - self.last_depth = 10 - self.depth_point = (-1,-1) - self.leftright = -1 - self.rState = 0 #Start searching for the next tag + #self.target_id += 1 + #self.target_id = self.target_id % 2 + self.move_arm(self) + #self.depth_counter = 0 + #self.last_depth = 10 + #self.depth_point = (-1,-1) + #self.leftright = -1 + #self.rState = 0 #Start searching for the next tag else: self.depth_counter = 0 #We dont need to sleep twice @@ -183,6 +188,7 @@ class marker_attacker(): def init_serial(): for com in range(0,4): + subprocess.run(["fuser","/dev/ttyUSB"+str(com),"-k"]) try: PORT = '/dev/ttyUSB' + str(com) BAUD = 9600 @@ -192,6 +198,10 @@ class marker_attacker(): except: pass return com + + def move_arm(self): + self.s.write('1'.encode('utf-8')) + time.sleep(1) def main(): if len(sys.argv) != 4: