def _scan_multi_robot(self, num=0): """ Automatic scanning of robots in the network :param num: :return: """ if config.LOCAL_IP_STR: local_ip = config.LOCAL_IP_STR else: local_ip = conn.get_local_ip() local_port = 8889 local_addr = (local_ip, local_port) self._scan_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # socket for sending cmd self._scan_socket.bind(local_addr) # thread for receiving cmd ack receive_thread = threading.Thread(target=self._receive_task, args=(num, )) # receive_thread.daemon = True receive_thread.start() robot_list = [] # scan by number ip_list = self._scan_ip(num) for ip in ip_list: te_ap_conf = config.te_conf if config.LOCAL_IP_STR: local_ip = config.LOCAL_IP_STR else: local_ip = conn.get_local_ip() local_port = random.randint(config.ROBOT_SDK_PORT_MIN, config.ROBOT_SDK_PORT_MAX) local_addr = (local_ip, local_port) te_ap_conf.default_sdk_addr = (local_addr) te_ap_conf.default_cmd_addr = (ip, te_ap_conf.default_cmd_addr_port) logger.info("MultiDrone: _scan_multi_robot, dron ip {0} uses addr {1}".format( te_ap_conf.default_cmd_addr, local_addr)) drone_client = client.TextClient(te_ap_conf) drone_obj = robot.Drone(drone_client) if not hasattr(robot.Drone, "ip_addr"): drone_obj.ip_addr = ip robot_list.append(drone_obj) self._scan_socket.close() return robot_list
# YOLO END if __name__ == '__main__': # fill in your lan address: robomaster.config.LOCAL_IP_STR = "192.168.31.22" # fill in robot lan address: robomaster.config.ROBOT_IP_STR = "192.168.31.143" # TT无人机默认 udp 模式,不设置也不影响 # DEFAULT_PROTO_TYPE = "udp" yolo = YOLO() # For YOLO tl_drone = robot.Drone() # tl_drone.initialize(conn_type="ap") tl_drone.initialize(conn_type="sta") # 获取飞机电池电量信息 tl_battery = tl_drone.battery battery_info = tl_battery.get_battery() print("Drone battery soc: {0}".format(battery_info)) # stop motor spinning tl_flight = tl_drone.flight tl_flight.motor_off() # initialize the camera tl_camera = tl_drone.camera t = time.time()
def init_device(self, timeout=5): # todo timeout self.tello = robot.Drone() # todo timeout,挪到 REPL 里,作为连接的前置行为 self.tello.initialize() self.pub_notification("Device(Tello) Connected!", type="SUCCESS")