def post_telemetry(self, location, heading): """ Post the drone's telemetry information. :param location: The location to post. :type location: Location :param heading: The UAV's heading. :type heading: Float """ print (location) print(heading) missing_data = True while missing_data: try: telem_upload_data = interop_api_pb2.Telemetry() print("after telem upload data initialization interopclient") telem_upload_data.longitude = location.get_lon() print("after get lon interopclient") telem_upload_data.altitude = location.get_alt() print("after get alt interopclient") telem_upload_data.latitude = (location.get_lat() + GCSSettings.MSL_ALT) print("after get lat interopclient") telem_upload_data.heading = heading missing_data = False except ConnectionError: sleep(GCSSettings.INTEROP_DISCONNECT_RETRY_RATE) print("before post_telemery statement interopclient") self.client1.post_telemetry(telem_upload_data)
def test_post_bad_telemetry(self): """Test sending some (incorrect) telemetry.""" t = interop_api_pb2.Telemetry() t.latitude = 38 t.longitude = -76 t.altitude = 100 t.heading = 400 # Out of range. with self.assertRaises(InteropError): self.client.post_telemetry(t) with self.assertRaises(InteropError): self.async_client.post_telemetry(t).result()
def test_post_telemetry(self): """Test sending some telemetry.""" t = interop_api_pb2.Telemetry() t.latitude = 38 t.longitude = -76 t.altitude = 100 t.heading = 90 # Raises an exception on error. self.client.post_telemetry(t) self.async_client.post_telemetry(t).result()
def submit_telemetry(self, mav): while True: if self.client is None: self.login_status = False print("Interop connection lost") self.login() else: telemetry = interop_api_pb2.Telemetry() telemetry.latitude = mav.lat telemetry.longitude = mav.lon telemetry.altitude = mav.altitude telemetry.heading = mav.orientation['yaw'] self.telemetry_json = json_format.MessageToJson(telemetry) self.client.post_telemetry(telemetry) time.sleep(0.1)
def post(self, request): """Posts the UAS position with a POST request.""" telemetry_proto = interop_api_pb2.Telemetry() try: json_format.Parse(request.body, telemetry_proto) except Exception as e: return HttpResponseBadRequest( 'Failed to parse request. Error: %s' % str(e)) if (not telemetry_proto.HasField('latitude') or not telemetry_proto.HasField('longitude') or not telemetry_proto.HasField('altitude') or not telemetry_proto.HasField('heading')): return HttpResponseBadRequest('Request missing fields.') # Check the values make sense. if telemetry_proto.latitude < -90 or telemetry_proto.latitude > 90: return HttpResponseBadRequest('Latitude out of range [-90, 90]: %f' % telemetry_proto.latitude) if telemetry_proto.longitude < -180 or telemetry_proto.longitude > 180: return HttpResponseBadRequest( 'Longitude out of range [-180, 180]: %f' % telemetry_proto.longitude) if telemetry_proto.altitude < -1500 or telemetry_proto.altitude > 330000: return HttpResponseBadRequest( 'Altitude out of range [-1500, 330000]: %f' % telemetry_proto.altitude) if telemetry_proto.heading < 0 or telemetry_proto.heading > 360: return HttpResponseBadRequest( 'Heading out of range [0, 360]: %f' % telemetry_proto.heading) # Store telemetry. gpos = GpsPosition( latitude=telemetry_proto.latitude, longitude=telemetry_proto.longitude) gpos.save() apos = AerialPosition( gps_position=gpos, altitude_msl=telemetry_proto.altitude) apos.save() telemetry = UasTelemetry( user=request.user, uas_position=apos, uas_heading=telemetry_proto.heading) telemetry.save() return HttpResponse('UAS Telemetry Successfully Posted.')
def simulate_telemetry(test, client, mission, hit_waypoint): """Simulates sending telemetry.""" t = interop_api_pb2.Telemetry() if hit_waypoint: wpt = random.choice(mission.mission_waypoints.all()) t.latitude = wpt.latitude t.longitude = wpt.longitude t.altitude = wpt.altitude_msl t.heading = random.uniform(0, 360) else: t.latitude = random.uniform(0, 90) t.longitude = random.uniform(0, 180) t.altitude = random.uniform(0, 800) t.heading = random.uniform(0, 360) r = client.post(telemetry_url, data=json_format.MessageToJson(t), content_type='application/json') test.assertEqual(r.status_code, 200, r.content)
#print(DictObj["flyZones"][0]["boundaryPoints"]) #print (mission) #print(type(mission)) try: x = urllib.request.urlopen('http://10.10.130.104:56781/mavlink/') #print(x.read()) # Catching the exception generated except Exception as e: print(str(e)) from urllib.request import urlopen #print(type(mav_json)) #print(mav_json["GPS_RAW_INT"]["msg"]["lat"]/1e7) #print(mav_json["GPS_RAW_INT"]["msg"]["lon"]/1e7) #print(mav_json["GPS_RAW_INT"]["msg"]["alt"]/1e3) #print(mav_json["VFR_HUD"]["msg"]["heading"]) while (True): time.sleep(0.8) mav_json = json.load(urlopen("http://10.10.130.104:56781/mavlink/")) print("sent") #print(mav_json["GPS_RAW_INT"]) telemetry = interop_api_pb2.Telemetry() telemetry.latitude = mav_json["GPS_RAW_INT"]["msg"]["lat"] / 1e7 telemetry.longitude = mav_json["GPS_RAW_INT"]["msg"]["lon"] / 1e7 telemetry.altitude = (mav_json["VFR_HUD"]["msg"]["alt"]) * 3.281 telemetry.heading = mav_json["VFR_HUD"]["msg"]["heading"] client.post_telemetry(telemetry)