if not (joystick.get_button(0) == 1) and joystick.get_axis(5) > 0.05: tiltDelta = scale(joystick.get_axis(5), 10) tilt = clip(tilt + tiltDelta, tiltMin, tiltMax) pan = clip(pan + panDelta, panMin, panMax) # Reset camera on B if joystick.get_button(1) == 1: tilt = 0 pan = 0 if joystick.get_button(5) == 1: print("Flying to altitude: 1.5") drone.flyToAltitude(1.25) drone.moveCamera(tilt, pan) # All movement updated here if userMovement: drone.update(cmd=movePCMDCmd(True, roll, pitch, yaw, gaz)) elif drone.findSphero: roll = (drone.objectCenterX - (drone.frameWidth >> 1)) * drone.moveScaler pitch = ((drone.frameHeight >> 1) - drone.objectCenterY) * drone.moveScaler roll = clip(roll, -50, 50) pitch = clip(pitch, -50, 50) # print("Finding Sphero") # print(roll)
if joystick.get_button(0) == 1 and joystick.get_axis(5) > 0.05: panDelta = scale(joystick.get_axis(5), 10) tilt = clip(tilt + tiltDelta, tiltMin, tiltMax) pan = clip(pan + panDelta, panMin, panMax) # Reset camera on LB if joystick.get_button(4) == 1: tilt = 0 pan = 0 if joystick.get_button(5) == 1: print("Flying to altitude: 1.5") drone.flyToAltitude(1.5) drone.moveCamera(tilt, pan) # Barcode testing # Press Y to center if len(drone.barcodes) > 0 and joystick.get_button(3) == 1: printCounter += 1 if printCounter > 5: print("Centering") printCounter = 0 frameCenterX = drone.frameWidth / 2 frameCenterY = drone.frameHeight / 2 i = drone.barcodes[0] x = (i.location[0][0] + i.location[1][0] + i.location[2][0] + i.location[3][0]) / 4 y = (i.location[0][1] + i.location[1][1] + i.location[2][1] + i.location[3][1]) / 4 xDistance = frameCenterX - x
cv2.namedWindow("Drone") def video_end(): print("Ending video...") cv2.destroyWindow("Drone") # Have to send waitKey several times on Unix to make window disappear for i in range(1, 5): cv2.waitKey(1) print("Connecting to drone..") drone = Bebop() drone.video_callbacks(video_start, video_end, video_frame) drone.videoEnable() drone.moveCamera(-90, 0) print("Connected.") pygame.init() size = [100, 100] screen = pygame.display.set_mode(size) pygame.display.set_caption("Drone Teleop") # Loop until the user clicks the close button. done = False # Used to manage how fast the screen updates clock = pygame.time.Clock() if pygame.joystick.get_count() == 0: print("No joysticks found")
color = (0, 0, 255) text = "Go Right" elif center_x - width * 0.5 < 50: color = (255, 0, 0) text = "Go Left" cv2.line(frame, barcode.location[0], barcode.location[1], color=color, thickness=2) cv2.line(frame, barcode.location[1], barcode.location[2], color=color, thickness=2) cv2.line(frame, barcode.location[2], barcode.location[3], color=color, thickness=2) cv2.line(frame, barcode.location[0], barcode.location[3], color=color, thickness=2) cv2.circle(frame, (center_x, center_y), 3, color=color, thickness=2) cv2.putText(frame, org=(width - 100, height - 100), text=text, color=color, fontFace=cv2.FONT_HERSHEY_PLAIN, fontScale=1,) break cv2.imshow("Drone feed", frame) cv2.waitKey(10) print("Connecting to drone..") drone = Bebop( metalog=None, onlyIFrames=False, jpegStream=True, fps = 0) drone.videoCbk = videoCallback drone.videoEnable() drone.moveCamera(-90, 0) print("Connected.") for i in xrange(10000): drone.update( ); print("Battery:", drone.battery)