def calculate_distances(rxers, telem): """ Calculate the maximum distance received by each receiver in a telemetry file""" _rx_records = {} for _line in telem: # Payload Position _lat = _line['latitude'] _lon = _line['longitude'] _alt = _line['altitude'] if _lat == 0.0 and _lon == 0.0: continue # List of receivers _rx_list = _line['_receivers'] for _rx in _rx_list: if _rx not in rxers: # Don't know this receiver. continue # Grab receiver info _rx_lat = rxers[_rx]['lat'] _rx_lon = rxers[_rx]['lon'] _rx_alt = rxers[_rx]['alt'] # Calculate distance _pos_info = position_info((_rx_lat, _rx_lon, _rx_alt), (_lat, _lon, _alt)) _distance = _pos_info['straight_distance'] if _rx not in _rx_records: # Initialise entry. _rx_records[_rx] = { 'distance': 0, 'pos_info': {}, 'rx_info': rxers[_rx], 'raw': "" } if _distance > _rx_records[_rx]['distance']: _rx_records[_rx]['distance'] = _distance _rx_records[_rx]['pos_info'] = _pos_info _rx_records[_rx]['raw'] = _line['_sentence'] return _rx_records
def test_agrees_with_others(self): tests = [((51.51, 100.123, 1000), (51.82, 100.2, 3000)), ((-43.0, -3.1, 300000), (-45.1, -2.2, 0)), ((32.712, -20.5, -200), (31.0, -10.1, 500000)), ((-43.0, -3.1, 300000), (51.82, 100.2, 3000)), ((31.0, -10.1, 500000), (51.51, 100.123, 1000)), ((32.712, -20.5, -200), (32.712, -20.5, 10000))] for me, balloon in tests: a = position_info(me, balloon) b = cusf_balloon_azel(*(me + balloon)) c = dlfldigi(*(me + balloon)) assert self.equal_sf(a["bearing"], b[0]) assert self.equal_sf(abs(a["elevation"]), b[1]) assert self.equal_sf(a["bearing"], c[0]) assert self.equal_sf(a["great_circle_distance"], c[1])
print "Found Launch site at " + repr( balloon ) + ". Balloon position will be used as soon as it is uploaded." else: print 'Found "' + position_data["payload"].encode( 'utf-8') + '" at ' + repr(balloon) + " Sentence: " + str( position_data["sentence_id"] ) + " at " + position_data["time"] + " UTC." except: print "ERROR: Document Parsing Error:", exc_info()[0] print "DEBUG info:" print position_data sleep(10) continue p = earthmaths.position_info(listener, balloon) bearing = round(p["bearing"]) elevation = round(p["elevation"]) distance = round(p["straight_distance"] / 1000, 1) print("Balloon Azimuth: " + str(bearing) + " Elevation: " + str(elevation) + " at " + str(distance) + " km.") if loopcount == 0: #Set rotator on first loop rotator_bearing = bearing rotator_elevation = elevation print("Moving rotator to Azimuth: " + str(rotator_bearing) + " Elevation: " + str(rotator_elevation)) udp_string = "<PST><TRACK>0</TRACK><AZIMUTH>" + str( rotator_bearing) + "</AZIMUTH><ELEVATION>" + str( rotator_elevation) + "</ELEVATION></PST>" udp_socket.sendto(udp_string, udp_config) else:
sleep(10) continue try: balloon = (position_data["latitude"], position_data["longitude"], position_data["altitude"]) if "Not launched" in position_data: # No telemetry data, position is launch site print "Found Launch site at " + repr(balloon) + ". Balloon position will be used as soon as it is uploaded." else: print 'Found "' + position_data["payload"].encode('utf-8') + '" at ' + repr(balloon) + " Sentence: " + str(position_data["sentence_id"]) + " at " + position_data["time"] + " UTC." except: print "ERROR: Document Parsing Error:", exc_info()[0] print "DEBUG info:" print position_data sleep(10) continue p = earthmaths.position_info(listener, balloon) bearing = round(p["bearing"]) elevation = round(p["elevation"]) distance = round(p["straight_distance"]/1000,1) print("Balloon Azimuth: " + str(bearing) + " Elevation: " + str(elevation) + " at " + str(distance) + " km.") if loopcount == 0: #Set rotator on first loop rotator_bearing = bearing rotator_elevation = elevation print("Moving rotator to Azimuth: " + str(rotator_bearing) + " Elevation: " + str(rotator_elevation)) udp_string = "<PST><TRACK>0</TRACK><AZIMUTH>" + str(rotator_bearing) + "</AZIMUTH><ELEVATION>" + str(rotator_elevation) + "</ELEVATION></PST>" udp_socket.sendto(udp_string, udp_config) else: if bearing > (rotator_bearing + hysteresis): rotator_bearing = (bearing + overshoot)%360 update_rotator = 1 elif bearing < (rotator_bearing - hysteresis):
def calc_p(self, balloon): p = earthmaths.position_info(self.listener, balloon) p["bearing"] = self.wrap_bearing(p["bearing"]) p["elevation"] = self.wrap_bearing(p["elevation"]) self.check_range(p) return p