This commit is contained in:
2024-02-26 15:54:02 +01:00
parent 6fdfb450ca
commit 7ab7d8f60f
+15 -12
View File
@@ -15,8 +15,8 @@ from cv_bridge import CvBridge, CvBridgeError
from geometry_msgs.msg import Twist
TARGET = 0
DEPTH_CAMERA_MIN_THRESHOLD = 400
DEPTH_CAMERA_MAX_THRESHOLD = 700
DEPTH_CAMERA_MIN_THRESHOLD = 460
DEPTH_CAMERA_MAX_THRESHOLD = 750
POSITIONS = ["left", "right", "middle"]
DEVICE = 'dev/ttyACM'
BAUD = 9600
@@ -105,6 +105,7 @@ class tutel():
def callback_rgb(self, data):
try:
rgb_image = self.rgb_bridge.imgmsg_to_cv2(data, "bgr8")
cv2.rotate(rgb_image, cv2.ROTATE_180, rgb_image)
(self.h, self.w) = rgb_image.shape[:2]
except CvBridgeError as e:
print(e)
@@ -159,12 +160,12 @@ class tutel():
if self.position is POSITIONS[0]:
cv2.rectangle(rgb_image, (0,0), (20, self.h), (0,0,255), cv2.FILLED)
self.t.linear.x = 0.0 * self.vel_fac
self.t.angular.z = -0.3 * self.vel_fac
self.t.angular.z = 0.15 * self.vel_fac
self.pub.publish(self.t)
elif self.position is POSITIONS[1]:
cv2.rectangle(rgb_image, (self.w-20,0), (self.w, self.h), (0,0,255), cv2.FILLED)
self.t.linear.x = 0.0 * self.vel_fac
self.t.angular.z = 0.3 * self.vel_fac
self.t.angular.z = -0.15 * self.vel_fac
self.pub.publish(self.t)
#some additional info on screen
@@ -172,7 +173,7 @@ class tutel():
cv2.putText(rgb_image, id_str, (10,30), cv2.FONT_HERSHEY_TRIPLEX, 1, (255,0,0), 2, cv2.LINE_8)
depth_str = "Depth_State:" + str(self.depth_state) + " Depth:" + str(self.last_depth)
cv2.putText(rgb_image, depth_str, (10,60), cv2.FONT_HERSHEY_TRIPLEX, 1, (255,0,0), 2, cv2.LINE_8)
info_str = "Resolution: " + str(self.w) + "x" + str(self.h) + " Search_State: " + str(self.search) + " Max_Min_Depth: " + str(self.maxMinDepth)
info_str = "Search_State: " + str(self.search)
cv2.putText(rgb_image, info_str, (10,90), cv2.FONT_HERSHEY_TRIPLEX, 1, (255,0,0), 2, cv2.LINE_8)
self.rate.sleep()
@@ -183,6 +184,7 @@ class tutel():
def callback_depth(self, data):
if self.depth_state:
depth_image = self.depth_bridge.imgmsg_to_cv2(data, "passthrough")
cv2.rotate(depth_image, cv2.ROTATE_180, depth_image)
if self.depth_counter == 0:
#pass
self.last_depth = 10.0
@@ -209,14 +211,15 @@ class tutel():
self.pixel_length = (self.x[1] - self.x[0] + self.y[1] - self.y[0]) / 2
#Approximation function for the amount of marker side's pixel for a specific distance to the camera
#f(x)=2914.2987x^-1.0159, with x := distance between camera and marker. Values rounded down to 4 digits.
self.pixel_depth = ((pixel_length/2914.2987)**(-1/1.0159))*10 #*10 to get the depth value in mm as the depth image delivers them in mm
self.pixel_depth = ((self.pixel_length/2914.2987)**(-1/1.0159))*10 #*10 to get the depth value in mm as the depth image delivers them in mm
print(self.pixel_depth)
if self.pixel_depth > self.max_threshold:
if (self.pixel_depth > self.last_depth-100 and self.pixel_depth < self.last_depth-100) or self.last_depth == 10:
if (self.pixel_depth > self.last_depth-50 and self.pixel_depth < self.last_depth-50) or self.last_depth == 10:
self.last_depth = self.pixel_depth
else:
self.last_depth = self.last_depth
else:
if len(depth_values)>0 and ((max(depth_values) > self.last_depth-100 and max(depth_values) < self.last_depth+100) or self.last_depth == 10):
if len(depth_values)>0 and ((max(depth_values) > self.last_depth-50 and max(depth_values) < self.last_depth+50) or self.last_depth == 10):
self.last_depth = max(depth_values)
else:
self.last_depth = self.last_depth
@@ -233,10 +236,10 @@ class tutel():
self.depth_state = False
self.last_depth = 10.0
start = time.time()
while (time.time() - start) < 3.5:
while (time.time() - start) < 1.0:
self.pub.publish(self.t)
self.t.linear.x = 0.0 * self.vel_fac
self.pub.publish(self.t)
while(True):self.pub.publish(self.t)
print("We reached our destination")
#self.move_arm(self)
else:
@@ -271,12 +274,12 @@ class tutel():
elif(self.top_right[0] < thresh_left or
self.bottom_right[0] < thresh_left):
self.t.linear.x = 0.0 * self.vel_fac
self.t.angular.z = 0.1 * self.vel_fac
self.t.angular.z = 0.15 * self.vel_fac
self.pub.publish(self.t)
elif(self.top_left[0] > thresh_right or
self.bottom_left[0] > thresh_right):
self.t.linear.x = 0.0 * self.vel_fac
self.t.angular.z = -0.1 * self.vel_fac
self.t.angular.z = -0.15 * self.vel_fac
self.pub.publish(self.t)
if int(self.w / 2) > self.top_left[0]:
self.position = POSITIONS[0]