class RelayService: def __init__(self, url, username, password): self.client = AsyncClient( url=url, username=username, password=password, ) self.last_telemetry = time() def telemetry(self, lat, lon, alt, heading): t = Telemetry(latitude=lat, longitude=lon, altitude_msl=alt, uas_heading=heading) self.client.post_telemetry(t) new_time = time() print 1/(new_time-self.last_telemetry) self.last_telemetry = new_time return True def server_info(self): info = self.client.get_server_info().result() return str(info.message)
class RelayService: def __init__(self, url, username, password): self.client = AsyncClient(url=url, username=username, password=password) self.last_telemetry = time() def telemetry(self, lat, lon, alt, heading): t = Telemetry(latitude=lat, longitude=lon, altitude_msl=alt, uas_heading=heading) self.client.post_telemetry(t) new_time = time() print(1 / (new_time - self.last_telemetry)) self.last_telemetry = new_time return True def get_obstacles(self): async_future = self.client.get_obstacles() async_stationary, async_moving = async_future.result() #print("here") # stat_ob, moving_ob = self.client.get_obstacles() async_radii_stationary = [o.cylinder_radius for o in async_stationary] async_lat_stationary = [o.latitude for o in async_stationary] async_lng_stationary = [o.longitude for o in async_stationary] async_height_stationary = [o.cylinder_height for o in async_stationary] async_radii_moving = [o.sphere_radius for o in async_moving] async_lat_moving = [o.latitude for o in async_moving] async_lng_moving = [o.longitude for o in async_moving] async_height_moving = [o.altitude_msl for o in async_moving] return async_radii_stationary, async_lat_stationary, async_lng_stationary, async_height_stationary, async_radii_moving, async_lat_moving, async_lng_moving, async_height_moving def get_moving_obstacles(self): return True def server_info(self): info = self.client.get_server_info().result() return str(info.message), str(info.message_timestamp), str(info.server_time)
class Telemetria(mp_module.MPModule): def __init__(self, mpstate): super(Telemetria, self).__init__(mpstate, "telemetria", "telemetria module") self.add_command('zrobCos', self.cmd_zrobCos, "zrobCos commands") self.client = AsyncClient(INTEROP_URL, INTEROP_USERNAME, INTEROP_PASSWORD) def mavlink_packet(self, m): '''handle a mavlink packet''' if m.get_type() == 'GLOBAL_POSITION_INT': telemetry = Telemetry( float(m.lat) / 10000000, float(m.lon) / 10000000, float(m.alt) / 1000, float(m.hdg) / 100) self.client.post_telemetry(telemetry) def cmd_zrobCos(self, args): print "Niby co"
class RelayService: def __init__(self, url, username, password): self.client = AsyncClient(url=url, username=username, password=password) self.last_telemetry = time() def telemetry(self, lat, lon, alt, heading): t = Telemetry(latitude=lat, longitude=lon, altitude_msl=alt, uas_heading=heading) self.client.post_telemetry(t) new_time = time() print(1 / (new_time - self.last_telemetry)) self.last_telemetry = new_time return True def server_info(self): info = self.client.get_server_info().result() return str(info.message)
class RelayService: def __init__(self, url, username, password): self.client = AsyncClient(url=url, username=username, password=password) self.last_telemetry = time() def telemetry(self, lat, lon, alt, heading): t = Telemetry(latitude=lat, longitude=lon, altitude_msl=alt, uas_heading=heading) self.client.post_telemetry(t) new_time = time() print(1 / (new_time - self.last_telemetry)) self.last_telemetry = new_time return True # POSTs target data, where target is a json object conforming to the # interop Target class specifications def target_data(self, target): # the ** operator unwraps the dictionary (here a json object) # into an actual argument list, and then we use that to create # an instance of the interop Target class t = Target(**target) self.client.post_target(t) # GETs all target info as a json object and prints it def get_target_data(self): return str(self.client.get_targets().result()) def server_info(self): info = self.client.get_server_info().result() return str(info.server_time)
def main(url, username, password, interop_time, generator, flightsim_kml_path=None): """Probes the interop server. Args: url: The interoperability URL. username: The interoperability username. password: The interoperability password. interop_time: The time between interop requests. generator: The data generator name to use. flightsim_kml_path: The KML path to use if flightsim generator. """ # Create client and data generator. client = AsyncClient(url, username, password) if generator == 'zeros': data_generator = datagen.ZeroValueGenerator() else: data_generator = flightsim.KmlGenerator(flightsim_kml_path) # Continually execute interop requests until signaled to stop. while True: start_time = datetime.datetime.now() telemetry = data_generator.get_uas_telemetry(start_time) telemetry_resp = client.post_telemetry(telemetry) obstacle_resp = client.get_obstacles() telemetry_resp.result() obstacle_resp.result() end_time = datetime.datetime.now() elapsed_time = (end_time - start_time).total_seconds() logging.info('Executed interop. Total latency: %f', elapsed_time) delay_time = interop_time - elapsed_time if delay_time > 0: try: time.sleep(delay_time) except KeyboardInterrupt: sys.exit(0)
# Tracks upload success and prints any exceptions. def handle_upload_result(future): if future.exception(): print 'Request Failed. Exception: %s' % str(future.exception()) else: with sent_lock: sent_since_print += 1 # Continuously poll for new telemetry and send to server. last_telemetry = Telemetry(0, 0, 0, 0) while True: telemetry = Telemetry(latitude=cs.lat, longitude=cs.lng, altitude=cs.alt, uas_heading=cs.groundcourse) if telemetry != last_telemetry: client.post_telemetry(telemetry).add_done_callback( handle_upload_result) last_telemetry = telemetry now = datetime.datetime.now() since_print = (now - last_print).total_seconds() if since_print >= PRINT_SEC: with sent_lock: local_sent_since_print = sent_since_print sent_since_print = 0 print 'Upload Rate: %f' % (local_sent_since_print / since_print) last_print = now time.sleep(POLL_SEC)