diff --git a/dennis_nodes/tutel_nodes_max_value_pure_variations/tutel_max_value_pure.py b/dennis_nodes/tutel_nodes_max_value_pure_variations/tutel_max_value_pure.py index c5ca932..b7beee0 100644 --- a/dennis_nodes/tutel_nodes_max_value_pure_variations/tutel_max_value_pure.py +++ b/dennis_nodes/tutel_nodes_max_value_pure_variations/tutel_max_value_pure.py @@ -38,10 +38,10 @@ class tutel(): self.min_threshold = DEPTH_CAMERA_MIN_THRESHOLD #Serial Pipeline init - #self.com = self.init_serial() - #self.device = DEVICE+str(self.com) - #self.baud = BAUD - #self.serial_pipeline = serial.Serial(self.device, self.baud, timeout = 1) + self.com = self.init_serial() + self.device = DEVICE+str(self.com) + self.baud = BAUD + self.serial_pipeline = serial.Serial(self.device, self.baud, timeout = 1) #Tutel_control self.pub = rospy.Publisher(tutel_topic, Twist, queue_size = 1) @@ -75,7 +75,7 @@ class tutel(): rospy.init_node("turtle_control", anonymous=True) #update rate can be increased - self.rate = rospy.Rate(15) + self.rate = rospy.Rate(30) #Sub init self.rgb_sub = rospy.Subscriber(astra_rgb_topic, Image, self.callback_rgb) @@ -112,7 +112,7 @@ class tutel(): print(e) if not self.routine: - print("NO SEARCH JUST DETECT") + #print("NO SEARCH JUST DETECT") (corners, ids, rejected) = cv2.aruco.detectMarkers(rgb_image, self.arucoDict, parameters = self.arucoParams) if corners: for id_x in ids: @@ -121,12 +121,12 @@ class tutel(): self.search = False break if self.search: - print("SEARCH TIME") + #print("SEARCH TIME") if(time.time() - self.search_time) > 31.5: - print("TIMES UP") + #print("TIMES UP") self.search_time = time.time() if (time.time() - self.search_time) < 31.415925: - print("LOOKING AROUND") + #print("LOOKING AROUND") self.t.linear.x = 0.0 * self.vel_fac self.t.angular.z = 0.2 * self.vel_fac self.pub.publish(self.t) @@ -154,7 +154,7 @@ class tutel(): break else: if corners: - print("I SAW SOMETHING") + #print("I SAW SOMETHING") x = np.where(ids == self.target_id) if len(x[0]) > 0: fitting_corners = corners[x[0][0]] @@ -163,13 +163,13 @@ class tutel(): elif(self.lastConernerTime - time.time()) < 1./2: self.depth_state = False if self.position is POSITIONS[0]: - print("I NEED TO GO LEFT!") + #print("I NEED TO GO LEFT!") 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.2 * self.vel_fac self.pub.publish(self.t) elif self.position is POSITIONS[1]: - print("I NEED TO GO RIGHT") + #print("I NEED TO GO RIGHT") 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.2 * self.vel_fac @@ -182,7 +182,7 @@ class tutel(): self.target_id = id_x self.search = False break - print("Routine initialised") + #print("Routine initialised") #some additional info on screen id_str = "IDs: " + str(ids) + " Target_ID:" + str(self.target_id) cv2.putText(rgb_image, id_str, (10,30), cv2.FONT_HERSHEY_TRIPLEX, 1, (255,0,0), 2, cv2.LINE_8) @@ -200,9 +200,9 @@ class tutel(): 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: + #if self.depth_counter == 0: #pass - self.last_depth = 10.0 + #self.last_depth = 10.0 #self.x = (0,0) #self.y = (0,0) #self.number_of_operations = 0 @@ -233,15 +233,17 @@ class tutel(): #self.pixel_length = max(pixels) #self.pixel_depth = ((self.pixel_length/2858.4636643479)**(-1/1.0056840993))*10 #self.pixel_depth = (self.pixel_depth + ((((self.x[1] - self.x[0] + self.y[1] - self.y[0]) / 2)/2914.29872964688)**(-1/1.01590290349592))*10)/2 - print(self.pixel_depth) + print(self.pixel_depth, depth_values, self.last_depth) if self.pixel_depth > self.max_threshold: - if (self.pixel_depth > self.last_depth-50 and self.pixel_depth < self.last_depth) or self.last_depth == 10: + if self.pixel_depth < self.last_depth 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-50 and max(depth_values) < self.last_depth) or self.last_depth == 10): + if len(depth_values)>0 and ((max(depth_values) > self.min_threshold and max(depth_values) < self.last_depth) or self.last_depth == 10): self.last_depth = max(depth_values) + elif max(depth_values) < self.min_threshold: + self.last_depth = self.pixel_depth else: self.last_depth = self.last_depth print(self.depth_counter, self.last_depth) @@ -249,6 +251,7 @@ class tutel(): if self.last_depth < self.min_threshold and self.last_depth != 0: self.depth_counter += 1 if self.depth_counter > 1: + print(self.last_depth) self.routine = True print("Only a few cm") self.t.linear.x = 0.1 * self.vel_fac @@ -263,6 +266,7 @@ class tutel(): self.t.linear.x = 0.0 * self.vel_fac while(True): self.pub.publish(self.t) + self.move_arm(self) #print("We reached our destination") #self.move_arm(self) else: @@ -317,7 +321,7 @@ class tutel(): #self.t.linear.x = 0.0 * self.vel_fac #self.t.angular.z = -0.2 * self.vel_fac #self.pub.publish(self.t) - marker_x = ((x[0] + (x[1]-x[0])//2 - 5), (x[0] + (x[1]-x[0])//2 + 5)) + marker_x = ((self.x[0] + (self.x[1]-self.x[0])//2 - 5), (self.x[0] + (self.x[1]-self.x[0])//2 + 5)) if marker_x[1] < self.w//2: #print("LEFT") self.t.linear.x = 0.0 @@ -325,7 +329,7 @@ class tutel(): elif marker_x[0] > self.w//2: #print("RIGHT") self.t.linear.x = 0.0 - self.t.angular.z = 0.2 + self.t.angular.z = -0.2 else: self.t.linear.x = 0.2 self.t.angular.z = 0.0 @@ -339,8 +343,9 @@ class tutel(): def move_arm(self): - self.s.write('1'.encode('utf-8')) - time.sleep(1) + #self.s.write('1'.encode('utf-8')) + #time.sleep(1) + print("move arm") def main(): if len(sys.argv) != 4: