def track_object(objs, labels): #global delay global x_deviation, y_deviation, tolerance, arr_track_data if (len(objs) == 0): print("no objects to track") ut.stop() ut.red_light("OFF") arr_track_data = [0, 0, 0, 0, 0, 0] return #ut.head_lights("OFF") k = 0 flag = 0 for obj in objs: lbl = labels.get(obj.id, obj.id) k = arr_valid_objects.count(lbl) if (k > 0): x_min, y_min, x_max, y_max = list(obj.bbox) flag = 1 break #print(x_min, y_min, x_max, y_max) if (flag == 0): print("selected object no present") return x_diff = x_max - x_min y_diff = y_max - y_min print("x_diff: ", round(x_diff, 5)) print("y_diff: ", round(y_diff, 5)) obj_x_center = x_min + (x_diff / 2) obj_x_center = round(obj_x_center, 3) obj_y_center = y_min + (y_diff / 2) obj_y_center = round(obj_y_center, 3) #print("[",obj_x_center, obj_y_center,"]") x_deviation = round(0.5 - obj_x_center, 3) y_deviation = round(0.5 - obj_y_center, 3) print("{", x_deviation, y_deviation, "}") #move_robot() thread = Thread(target=move_robot) thread.start() #thread.join() #print(cmd) arr_track_data[0] = obj_x_center arr_track_data[1] = obj_y_center arr_track_data[2] = x_deviation arr_track_data[3] = y_deviation
def move_robot(): global x_deviation, y_deviation, tolerance, arr_track_data print("moving robot .............!!!!!!!!!!!!!!") print(x_deviation, y_deviation, tolerance, arr_track_data) if(abs(x_deviation)<tolerance and abs(y_deviation)<tolerance): cmd="Stop" delay1=0 ut.stop() ut.red_light("ON") else: ut.red_light("OFF") if (abs(x_deviation)>abs(y_deviation)): if(x_deviation>=tolerance): cmd="Move Left" delay1=get_delay(x_deviation,'l') ut.left() time.sleep(delay1) ut.stop() if(x_deviation<=-1*tolerance): cmd="Move Right" delay1=get_delay(x_deviation,'r') ut.right() time.sleep(delay1) ut.stop() else: if(y_deviation>=tolerance): cmd="Move Forward" delay1=get_delay(y_deviation,'f') ut.forward() time.sleep(delay1) ut.stop() if(y_deviation<=-1*tolerance): cmd="Move Backward" delay1=get_delay(y_deviation,'b') ut.back() time.sleep(delay1) ut.stop() arr_track_data[4]=cmd arr_track_data[5]=delay1
def track_object(objs,labels): global x_deviation, y_max, tolerance if(len(objs)==0): print("no objects to track") ut.stop() ut.red_light("OFF") return k=0 flag=0 for obj in objs: lbl=labels.get(obj.id, obj.id) k = arr_valid_objects.count(lbl) if (k>0): x_min, y_min, x_max, y_max = list(obj.bbox) flag=1 break #print(x_min, y_min, x_max, y_max) if(flag==0): print("selected object no present") return x_diff=x_max-x_min y_diff=y_max-y_min obj_x_center=x_min+(x_diff/2) obj_x_center=round(obj_x_center,3) obj_y_center=y_min+(y_diff/2) obj_y_center=round(obj_y_center,3) x_deviation=round(0.5-obj_x_center,3) y_max=round(y_max,3) print("{",x_deviation,y_max,"}") thread = Thread(target = move_robot) thread.start()
def move_robot(): global x_deviation, y_max, tolerance if(abs(x_deviation)<tolerance): if(y_max>0.9): ut.red_light("ON") ut.stop() print("reached person...........") else: ut.red_light("OFF") ut.forward() print("moving robot ...FORWARD....!!!!!!!!!!!!!!") else: ut.red_light("OFF") if(x_deviation>=tolerance): delay1=get_delay(x_deviation) ut.left() time.sleep(delay1) ut.stop() print("moving robot ...Left....<<<<<<<<<<") if(x_deviation<=-1*tolerance): delay1=get_delay(x_deviation) ut.right() time.sleep(delay1) ut.stop() print("moving robot ...Right....>>>>>>>>")
def move_robot(): global x_deviation, y_max, tolerance, arr_track_data print("moving robot .............!!!!!!!!!!!!!!") print(x_deviation, tolerance, arr_track_data) y = 1 - y_max #distance from bottom of the frame if (abs(x_deviation) < tolerance): delay1 = 0 if (y < 0.1): cmd = "Stop" ut.red_light("ON") ut.stop() else: cmd = "forward" ut.red_light("OFF") ut.forward() else: ut.red_light("OFF") if (x_deviation >= tolerance): cmd = "Move Left" delay1 = get_delay(x_deviation) ut.left() time.sleep(delay1) ut.stop() if (x_deviation <= -1 * tolerance): cmd = "Move Right" delay1 = get_delay(x_deviation) ut.right() time.sleep(delay1) ut.stop() arr_track_data[4] = cmd arr_track_data[5] = delay1