update
communication between script and arduino now implemented. Moves servos and a led blinks. Needs to be tested asap.
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user