This commit is contained in:
raiots 2024-06-23 17:11:22 +08:00
parent 01b4131b95
commit f14adf0b65
1 changed files with 7 additions and 2 deletions

View File

@ -91,11 +91,12 @@ class AutoControl:
self.target = [0, 0, 0, 0]
self.tag_detector = apriltag.Detector(families='tag36h11')
self.yaw_controller = PIDController(1, 0, 0.1, time.time())
self.yaw_controller = PIDController(0.3, 0, 0.1, time.time())
self.for_back_controler = PIDController(100, 0, 0.1, time.time())
self.left_right_controler = PIDController(50, 0, 0.1, time.time()) # 摄像头左右视野较小
self.loss_target_times = 0
self.is_get_tag = False
self.get_tag_times = 0
def detect(self, front_img):
cv2.imshow("ROI select", front_img)
@ -154,6 +155,8 @@ class AutoControl:
if self.target[1] > self.uav.front_cam_shape[1] * 0.9:
print(self.target[1], self.uav.front_cam_shape[0]/10)
logging.warn("ready to land")
self.uav.yaw_velocity = 0
self.uav.for_back_velocity = 10
self.uav.status = Status.LANDING
self.uav.tello.set_video_direction(Tello.CAMERA_DOWNWARD)
@ -169,6 +172,8 @@ class AutoControl:
tag_list.append(tag)
if tag_list:
self.get_tag_times += 1
if self.get_tag_times == 5:
self.is_get_tag = True
for_vel = -1 * self.for_back_controler.control(tag_list[0].pose_t[0], time.time())
self.uav.for_back_velocity = int(for_vel)