def __init__(self): self.gm = GeoMag("../src/geomag/WMM.COF") rospy.init_node("declination_provider") self.fix = None self.sub = rospy.Subscriber("fix", NavSatFix, self._fix) self.pub = rospy.Publisher("declination", Float32, latch=True)
def __init__(self): rospy.init_node("declination_provider") wmm_path = path.join(get_pkg_dir('declination'), "wmm", "WMM.COF") self.gm = GeoMag(wmm_path) self.fix = None self.sub = rospy.Subscriber("fix", NavSatFix, self._fix) self.pub = rospy.Publisher("declination", Float32, latch=True)
class Declination: def __init__(self): self.gm = GeoMag("../src/geomag/WMM.COF") rospy.init_node("declination_provider") self.fix = None self.declination = 0.0 self.sub = rospy.Subscriber("fix", NavSatFix, self._fix) self.pub = rospy.Publisher("declination", Float32, latch=True) def _fix(self, msg): #if self.fix: # # For now, return. Later, figure out conditions under which to recompute. # return if msg.latitude and msg.longitude: self.fix = msg if not msg.altitude: msg.altitude = 0 result = self.gm.calc(msg.latitude, msg.longitude, msg.altitude) if self.declination != result.dec: self.pub.publish(radians(result.dec)) self.declination = result.dec def spin(self): rospy.spin()
class Compute: def __init__(self): rospy.init_node("declination_provider") wmm_path = path.join(get_pkg_dir('declination'), "wmm", "WMM.COF") self.gm = GeoMag(wmm_path) self.fix = None self.sub = rospy.Subscriber("fix", NavSatFix, self._fix) self.pub = rospy.Publisher("declination", Float32, latch=True) def _fix(self, msg): if self.fix: # For now, return. Later, figure out conditions under which to recompute. return if msg.latitude and msg.longitude: self.fix = msg if not msg.altitude: msg.altitude = 0 result = self.gm.calc(msg.latitude, msg.longitude, msg.altitude) result_rad = radians(result.dec) self.pub.publish(result_rad) rospy.loginfo("Computed magnetic declination to be %f rad (%f degrees)" \ % (result_rad, result.dec)) def spin(self): rospy.spin()
def main(name): script_path = os.path.dirname(os.path.abspath(__file__)) gm = GeoMag(script_path + os.sep + 'geomag' + os.sep + 'WMM.COF') socket_map = generate_map(name) gps_socket = socket_map['gps'] decl_socket = socket_map['decl'] rt = RateTimer(1) while True: raw = gps_socket.recv() if rt.expired(): gps = loads(raw) try: date = datetime.strptime(gps[TIME], '%Y-%m-%d %H:%M:%S').date() decl = gm.GeoMag(gps[LAT], gps[LON], time=date).dec decl_socket.send('%f' % decl) except: pass
def main(name): script_path = os.path.dirname(os.path.abspath(__file__)) gm = GeoMag(script_path + os.sep + 'geomag' + os.sep + 'WMM.COF') socket_map = generate_map(name) gps_socket = socket_map['gps'] decl_socket = socket_map['decl'] i = 0 while True: data = gps_socket.recv() if i == 20: i = 0 gps_data = GpsData() gps_data.ParseFromString(data) if gps_data.time and gps_data.fix >= 2: date = datetime.strptime(gps_data.time, '%Y-%m-%d %H:%M:%S').date() decl = gm.GeoMag(gps_data.lat, gps_data.lon, time = date).dec print time(), decl decl_socket.send('%f' % decl) i += 1
class Declination: def __init__(self): self.gm = GeoMag("../src/geomag/WMM.COF") rospy.init_node("declination_provider") self.fix = None self.sub = rospy.Subscriber("fix", NavSatFix, self._fix) self.pub = rospy.Publisher("declination", Float32, latch=True) def _fix(msg): if self.fix: # For now, return. Later, figure out conditions under which to recompute. return if msg.latitude and msg.longitude: self.fix = msg if not msg.altitude: msg.altitude = 0 result = self.gm.calc(msg.latitude, msg.longitude, msg.altitude) self.pub.publish(result.dec) def spin(self): rospy.spin()
#!/usr/bin/python import roslib roslib.load_manifest('lrm_outdoor') import rospy from geomag.geomag import GeoMag if __name__ == "__main__": rospy.init_node("test_declination") gm = GeoMag("../src/geomag/WMM.COF") #mag = gm.calc(43.411454, -80.472708) mag = gm.calc(-22.411454, -44.472708) print mag.dec
def point_declination(lat, lon): mag = GeoMag().GeoMag(lat, lon) declination = mag.dec return float(declination)