def load(self, cal_file): config = PropertyNode() try: name, ext = os.path.splitext(cal_file) if ext == '.json': props_json.load(cal_file, config) self.valid = True elif ext == '.xml': props_xml.load(cal_file, config) self.valid = True else: return False except: print(cal_file + ": load error:\n" + str(sys.exc_info()[1])) return False root.pretty_print() self.min_temp = config.getFloat('min_temp_C') self.max_temp = config.getFloat('max_temp_C') node = config.getChild('p') if node: p1, p2, p3 = node.getString('bias').split() self.p_bias = np.array([p1, p2, p3], dtype=np.float64) p1, p2, p3 = node.getString('scale').split() self.p_scale = np.array([p1, p2, p3], dtype=np.float64) node = config.getChild('q') if node: p1, p2, p3 = node.getString('bias').split() self.q_bias = np.array([p1, p2, p3], dtype=np.float64) p1, p2, p3 = node.getString('scale').split() self.q_scale = np.array([p1, p2, p3], dtype=np.float64) node = config.getChild('r') if node: p1, p2, p3 = node.getString('bias').split() self.r_bias = np.array([p1, p2, p3], dtype=np.float64) p1, p2, p3 = node.getString('scale').split() self.r_scale = np.array([p1, p2, p3], dtype=np.float64) node = config.getChild('ax') if node: p1, p2, p3 = node.getString('bias').split() self.ax_bias = np.array([p1, p2, p3], dtype=np.float64) p1, p2, p3 = node.getString('scale').split() self.ax_scale = np.array([p1, p2, p3], dtype=np.float64) node = config.getChild('ay') if node: p1, p2, p3 = node.getString('bias').split() self.ay_bias = np.array([p1, p2, p3], dtype=np.float64) p1, p2, p3 = node.getString('scale').split() self.ay_scale = np.array([p1, p2, p3], dtype=np.float64) node = config.getChild('az') if node: p1, p2, p3 = node.getString('bias').split() self.az_bias = np.array([p1, p2, p3], dtype=np.float64) p1, p2, p3 = node.getString('scale').split() self.az_scale = np.array([p1, p2, p3], dtype=np.float64) tokens = config.getString('mag_affine').split() if len(tokens) == 16: r = 0 c = 0 for i, x in enumerate(tokens): self.mag_affine[r, c] = float(x) c += 1 if c > 3: c = 0 r += 1 self.mag_affine_inv = np.linalg.inv(self.mag_affine) else: print("mag_affine requires 16 values") #print 'mag_affine:\n', self.mag_affine #print 'mag_affine_inv:\n', self.mag_affine_inv return True
def load(self, cal_file): config = PropertyNode() try: name, ext = os.path.splitext(cal_file) if ext == '.json': props_json.load(cal_file, config) self.valid = True elif ext == '.xml': props_xml.load(cal_file, config) self.valid = True else: return False except: print cal_file + ": load error:\n" + str(sys.exc_info()[1]) return False root.pretty_print() self.min_temp = config.getFloat('min_temp_C') self.max_temp = config.getFloat('max_temp_C') node = config.getChild('p') if node: p1, p2, p3 = node.getString('bias').split() self.p_bias = np.array([p1, p2, p3], dtype=np.float64) p1, p2, p3 = node.getString('scale').split() self.p_scale = np.array([p1, p2, p3], dtype=np.float64) node = config.getChild('q') if node: p1, p2, p3 = node.getString('bias').split() self.q_bias = np.array([p1, p2, p3], dtype=np.float64) p1, p2, p3 = node.getString('scale').split() self.q_scale = np.array([p1, p2, p3], dtype=np.float64) node = config.getChild('r') if node: p1, p2, p3 = node.getString('bias').split() self.r_bias = np.array([p1, p2, p3], dtype=np.float64) p1, p2, p3 = node.getString('scale').split() self.r_scale = np.array([p1, p2, p3], dtype=np.float64) node = config.getChild('ax') if node: p1, p2, p3 = node.getString('bias').split() self.ax_bias = np.array([p1, p2, p3], dtype=np.float64) p1, p2, p3 = node.getString('scale').split() self.ax_scale = np.array([p1, p2, p3], dtype=np.float64) node = config.getChild('ay') if node: p1, p2, p3 = node.getString('bias').split() self.ay_bias = np.array([p1, p2, p3], dtype=np.float64) p1, p2, p3 = node.getString('scale').split() self.ay_scale = np.array([p1, p2, p3], dtype=np.float64) node = config.getChild('az') if node: p1, p2, p3 = node.getString('bias').split() self.az_bias = np.array([p1, p2, p3], dtype=np.float64) p1, p2, p3 = node.getString('scale').split() self.az_scale = np.array([p1, p2, p3], dtype=np.float64) tokens = config.getString('mag_affine').split() if len(tokens) == 16: r = 0 c = 0 for i, x in enumerate(tokens): self.mag_affine[r,c] = float(x) c += 1 if c > 3: c = 0 r += 1 self.mag_affine_inv = np.linalg.inv(self.mag_affine) else: print "mag_affine requires 16 values" #print 'mag_affine:\n', self.mag_affine #print 'mag_affine_inv:\n', self.mag_affine_inv return True
from util import myprof, timer parser = argparse.ArgumentParser(description="Rice Creak UAS flight code") parser.add_argument("--config", required=True, help="path to config tree") parser.add_argument("--verbose", action="store_true", help="enable additional console verbocity") args = parser.parse_args() # load master config file config_file = os.path.join(args.config, "main.json") result = props_json.load(config_file, root) if result: print("Loaded master configuration file:", config_file) if args.verbose: root.pretty_print() config_node = getNode("/config") config_node.setString("path", args.config) else: print("*** Cannot load master config file:", config_file) print() print("Cannot continue without a valid configuration, sorry.") exit(-1) # shared property nodes comms_node = getNode("/comms", True) imu_node = getNode("/sensors/imu", True) status_node = getNode("/status", True) status_node.setFloat("frame_time", 0.0) # create singleton class instances
# correct way to create a path with a new child node gps = getNode("/sensors/gps[5]", create=True) gps.alt_m = 275.3 sensors = getNode("/sensors") print "gps len = ", sensors.getLen("gps"); # az get's created a parent node imu = getNode("/sensors/imu[2]", create=True) # this works, but is bad form because az is originally created as a # PropertyNode() branch that can't have a value, only childredn imu.az = -9.80 # this should work root.sensors.imu[2].az = -9.81 root.pretty_print() print "alt_m:", root.sensors.gps[5].alt_m config = getNode('/', create=True) #file = '/home/curt/Source/AuraUAS/aura-data/config/main-skywalker.xml' #props_xml.load(file, config) #props_xml.save("testing.xml", config) #props_json.save("testing.json", config) newroot = PropertyNode() props_json.load("/home/curt/Source/AuraUAS/aura-data/config/main-skywalker.json", newroot) print "pretty:" newroot.pretty_print() quit() print "sensor children:", sensors.getChildren()