def __init__(self, starting_port, config_file=None): if config_file is not None: with open(config_file, 'r') as yml: cfg = yaml.load(yml, Loader=yaml.SafeLoader) yml.close() assign_all_ports(cfg, starting_port) else: cfg = None self.pubsub_config = cfg MicroServerComs.__init__(self, "Display", config=cfg, timeout=0) self._system_command = SystemCommand(cfg) self.altitude = None self.airspeed = None self.tas = None self.heading = None self.roll = None self.pitch = None self.yaw = None self.climb_rate = None self.turn_rate = None self.gps_utc = None self.gps_lat = None self.gps_lng = None self.gps_ground_speed = None self.gps_ground_track = None self.ground_vector_confidence = None self.magnetic_declination = None self.update_period = 1.0 / 30.0 self.callback = None
def __init__(self, pubsub_cfg, starting_port): if isinstance(pubsub_cfg, str): with open(pubsub_cfg, 'r') as yml: cfg = yaml.load(yml, Loader=yaml.SafeLoader) yml.close() else: cfg = pubsub_cfg assign_all_ports(cfg, starting_port) MicroServerComs.__init__(self, "Autopilot", config=cfg) self.magnetic_declination = None self._system_command = SystemCommand(cfg) self.altitude = None self.altitude_confidence = 0 self.airspeed = None self.airspeed_confidence = 0 self.heading = None self.heading_confidence = 0 self.roll = None self.roll_confidence = 0 self.roll_rate = None self.roll_rate_confidence = 0 self.pitch = None self.pitch_confidence = 0 self.pitch_rate = None self.pitch_rate_confidence = 0 self.yaw = None self.yaw_confidence = 0 self.climb_rate = None self.climb_rate_confidence = 0 self.turn_rate = None self.turn_rate_confidence = 0 self.gps_utc = None self.gps_lat = None self.gps_lng = None self.gps_ground_speed = None self.gps_ground_track = None self.gps_signal_quality = 0 self.last_update_time = 0
) opt.add_argument( '--roll-conf-mult', type=float, default=1.0, help='roll confidence = degrees variation * roll_conf_mult') opt.add_argument( '--pitch-conf-mult', type=float, default=1.0, help='pitch confidence = degrees variation * pitch_conf_mult') args = opt.parse_args() with open(args.pubsub_config, 'r') as yml: MicroServerComs._pubsub_config = yaml.load(yml) assign_all_ports(MicroServerComs._pubsub_config, args.starting_port) yml.close() InternalPublisher.TheInternalPublisher = InternalPublisher.InternalPublisher( MicroServerComs._pubsub_config) if os.path.exists(args.airspeed_config): with open(args.airspeed_config, 'r') as yml: airspeed_config = yaml.load(yml) yml.close() else: airspeed_config = dict() airspeed_config['rais_id'] = args.starting_port heading_calibration = None if os.path.exists(args.heading_calibration): with open(args.heading_calibration, 'r') as yml: heading_calibration = yaml.load(yml)
else: datestamp = Globals.datestamp() log_prefix = os.path.join('Logs', 'Sensors', datestamp) log_start = "Sensors beginning with logging prefix %s" % log_prefix try: os.makedirs(log_prefix) except: pass rootlogger.addHandler( logging.FileHandler(os.path.join(log_prefix, 'info.log'))) console_handler = logging.StreamHandler(sys.stdout) console_handler.setLevel(logging.INFO) rootlogger.addHandler(console_handler) rootlogger.log(99, log_start) with open(args.config_file, 'r') as yml: config = yaml.load(yml) yml.close() with open(args.pubsub_config, 'r') as yml: pubsub_config = yaml.load(yml) assign_all_ports(pubsub_config, args.starting_port) yml.close() slave = SenseControlSlave(config, pubsub_config) command = hmi(slave) cmd_thread = threading.Thread(target=command.cmdloop) cmd_thread.start() while not command.stop: slave.ReadSensors() slave.listen(timeout=0.01, loop=False)
class AirspeedCalData(MicroServerComs): def __init__(self, cfg): MicroServerComs.__init__(self, "AdminCommand", channel='admincommand', config=cfg) def send(self, a): self.command = b'airspeed' self.args = bytes(a, 'utf-8') print("Airspeed %s published %s" % (a, str(self.pubchannel.getpeername()))) self.publish() if __name__ == "__main__": if len(sys.argv) != 4: print( "Usage: AirspeedCalData.py <starting_port> <pubsub.yaml> <current_ias>" ) sys.exit(-1) with open(sys.argv[2], 'r') as yml: config = yaml.load(yml) yml.close() starting_port = int(sys.argv[1]) ias = float(sys.argv[3]) assign_all_ports(config, starting_port) aspd = AirspeedCalData(config) aspd.send(sys.argv[3])
if __name__ == "__main__": if len(sys.argv) < 6: print ("Usage: RAISDiscriminator <starting_port_number1> <input_config1> [starting_port_numbern input_confign...] <starting_output_port> <output_config>") sys.exit(-1) input_config = list() get_port = True for i in range(1,len(sys.argv)-2): if get_port: starting_port = int(sys.argv[i]) get_port = False else: with open(sys.argv[i], "r") as inp: cfg = yaml.load(inp) assign_all_ports(cfg, starting_port) input_config.append(cfg) get_port = True rootlogger = logging.getLogger() rootlogger.setLevel(1) datestamp = Globals.datestamp() log_prefix = os.path.join('Logs', 'RAIS', datestamp) log_start = "RAIS Discriminator beginning with logging prefix %s"%log_prefix try: os.makedirs(log_prefix) except: pass file_handler = logging.FileHandler(os.path.join(log_prefix, 'info.log')) file_handler.setLevel(logging.DEBUG)