jam_
lvl.1
Flight distance : 8773 ft
United States
Offline
|
Turns out I glossed over the "tip" section in the documentation. Here's a way to automatically connect to the robot when it comes online:
# Try to find online robots
while True:
print("INFO: scanning...")
scan_result = conn.scan_robot_ip_list(timeout=3)
if len(scan_result) == 0:
continue
# Get the robot's sn
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(("0.0.0.0", robomaster.config.ROBOT_BROADCAST_PORT))
s.settimeout(1)
data, ip = s.recvfrom(1024)
robot_sn = conn.get_sn_form_data(data)
s.close()
time.sleep(1)
# Set up the robot
self.ep_robot = robot.Robot()
self.ep_robot.initialize(conn_type="sta", sn=robot_sn)
|
|