def createXicaAirline(): """ Function createXicaAirline ============================== This function has no input parameters Returns an airline with 2 aircraft and 4 flights """ # creates first aircraft with some values AC1 = aircraft.Aircraft() AC1.callsign = "EC234" AC1.type = "A320" AC1.seats = 280 # creates a second aircraft with other values AC2 = aircraft.Aircraft() AC2.callsign = "EC504" AC2.type = "A321" AC2.seats = 310 # creates first flight with some values FL1 = flight.Flight() FL1.dep = "Barcelona" FL1.arr = "Budapest" FL1.time_dep = 8 * 60 FL1.time_arr = 11 * 60 FL1.passengers = 54 # creates second flight with some values FL2 = flight.Flight() FL2.dep = "Barcelona" FL2.arr = "Istambul" FL2.time_dep = 9 * 60 FL2.time_arr = 12.5 * 60 FL2.passengers = 154 # creates third flight with some values FL3 = flight.Flight() FL3.dep = "Istambul" FL3.arr = "Budapest" FL3.time_dep = 17 * 60 FL3.time_arr = 19.25 * 60 FL3.passengers = 140 # creates fourth flight with some values FL4 = flight.Flight() FL4.dep = "Budapest" FL4.arr = "Barcelona" FL4.time_dep = 20 * 60 FL4.time_arr = 23 * 60 FL4.passengers = 97 # creates the airline Xica = airline.Airline() Xica.name = "Xica Airline" airline.add_aircraft(Xica, AC1) airline.add_aircraft(Xica, AC2) airline.add_operation(Xica, FL1) airline.add_operation(Xica, FL2) airline.add_operation(Xica, FL3) airline.add_operation(Xica, FL4) return Xica
def build(): '''Returns: if aircraft is set, airport is set and performance computation is required, it returns the following tupla: (acft, apt, rwy, qnh_hPa, T_degC) ''' in_menu = True aircraft_is_set = False airport_is_set = False load_ofp = False qnh_hPa = 1013.15 T_degC = 15.0 while in_menu: for (key, choice) in main_menu.items(): print('{} {}'.format(key, choice)) uchoice = input('Choice: ') # Processing user choice uchoice = checkChoice(uchoice) # Calling required menu's voice if uchoice == AIRPORT: (apt, rwy, qnh_hPa, T_degC) = airportMenu() airport_is_set = True elif uchoice == AIRCRAFT: acft_config = aircraftMenu() acft = aircraft.Aircraft(acft_config) acft.print() aircraft_is_set = True elif uchoice == LOAD_OFP: pass elif uchoice == COMPUTE: if airport_is_set and aircraft_is_set: return acft, apt, rwy, qnh_hPa, T_degC else: if not airport_is_set: print('Airport not set') if not aircraft_is_set: print('Aircraft not set') if not load_ofp: print('OFP not loaded') elif uchoice == EXIT: in_menu = False exit(0) else: print('Choice not yet implemented')
def create_aircraft(self, ac_id, kwargs): new_ac = aircraft.Aircraft(ivy_link=self.ivy, ac_id=ac_id, **kwargs) flight_plan_runner = FlightPlanPerformingObserver( new_ac, self._plan_generator(new_ac)) new_ac.observe('navigation__cur_block', flight_plan_runner) new_ac.observe('navigation__circle_count', flight_plan_runner) new_ac.observe('pprz_mode__ap_mode', flight_plan_runner) new_ac.observe('flight_param', flight_plan_runner) new_ac.observe( 'flight_param', RecordFlight( ac=new_ac, log_dir=self.log_dir, log_file_name=functools.partial(self._get_log_file_name, ac=new_ac), log_file_format=self.log_file_format, )) return new_ac
# Create Frame mainFrame = ttk.Frame(root, padding="3 3 3 3") mainFrame.grid(column=0, row=0, sticky=(N, W, E, S)) mainFrame.columnconfigure(0, weight=1) mainFrame.rowconfigure(0, weight=1) # Add Display section displayFrame = mydisplay.Display(root, mainFrame) displayFrame.grid(column=0, row=0, stick='w') # Add horizontal line ttk.Separator(mainFrame, orient=HORIZONTAL).grid(column=0, row=1, sticky='ew') # Add Aircraft section aircraftFrame = aircraft.Aircraft(root, mainFrame) aircraftFrame.grid(column=0, row=2, sticky='w') # Add horizontal line ttk.Separator(mainFrame, orient=HORIZONTAL).grid(column=0, row=3, sticky='ew') # Add Origin Section originFrame = origin.Origin(root, mainFrame) originFrame.grid(column=0, row=4, sticky='w') # Add horizontal line ttk.Separator(mainFrame, orient=HORIZONTAL).grid(column=0, row=5, sticky='ew') # Create Volumne section volumeFrame = volume.Volume(root, mainFrame, originFrame) volumeFrame.grid(column=0, row=6, sticky='w')
import aircraft, flight, assignment ac1 = aircraft.Aircraft() ac1.callsign = 'AC320' ac1.type = 'A320' ac1.seats = 80 ac2 = aircraft.Aircraft() ac2.callsign = 'PAPA' ac2.type = 'A320' ac2.seats = 94234 f1 = flight.Flight() f1.dep = "Barcelona" f1.arr = "Vigo" f1.time_dep = 8 * 60 f1.time_arr = 9 * 60 + 50 f1.passengers = 48 f2 = flight.Flight() f2.dep = "Vigo" f2.arr = "New York" f2.time_dep = 15 * 60 f2.time_arr = 20 * 60 f2.passengers = 74 f3 = flight.Flight()
def main(): #initialize pygame module and set window pygame.init() #DISPLAY WINDOW SIZE. CHANGE TO SUIT YOUR SCREEN IF NECESSARY width, height = 1800,900 pygame.display.set_icon(pygame.image.load('res/gameicon.jpg')) screen = pygame.display.set_mode((width,height), HWSURFACE|OPENGL|DOUBLEBUF) pygame.display.set_caption("Pylot") glViewport(0,0,width,height) glEnable(GL_DEPTH_TEST) default_view = np.identity(4) #boolean variables for camera view, lose screen, and pause FPV = True LOSE = False PAUSE = False KEYBOARD = False DATA = True #SIMULATION FRAMERATE #pygame limits framerate to this value. Increasing framerate improves accuracy of simulation (max limit = 60) but may cause some lag in graphics target_framerate = 60 #initialize graphics objects #loading screen is rendered and displayed while the rest of the objects are read and prepared glClearColor(0.,0.,0.,1.0) glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) loading = graphics.Text(150) loading.draw(-0.2,-0.05,"Loading...",(0,255,0,1)) pygame.display.flip() #initialize game over screen gameover = graphics.Text(150) #initialize graphics aircraft graphics_aircraft = graphics.Mesh("res/Cessna.obj","shaders/aircraft.vs","shaders/aircraft.fs","res/cessna_texture.jpg",width,height) graphics_aircraft.set_orientation([0.,0.,0.,0.]) graphics_aircraft.set_position([0.,0.,-500.]) #initialize HUD HUD = graphics.HeadsUp(width, height) #initialize flight data overlay data = graphics.FlightData() #initialize field field = graphics.Mesh("res/field.obj","shaders/field.vs","shaders/field.fs","res/field_texture.jpg",width,height) field.set_position(np.array([0.,0.,0.])) #initialize camera object cam = graphics.Camera() a_obj = aircraft.Aircraft() dt = simulation.load_file('11.24_input.json', a_obj) simulation.initialize(a_obj) #initialize other pygame elements if pygame.joystick.get_count()>0.: joy = pygame.joystick.Joystick(0) joy.init() else: KEYBOARD = True thr = 0. UP = False DOWN = False RIGHT = False LEFT = False WW = False SS = False AA = False DD = False #DEFLECTION LIMITS FOR CONTROL SURFACES d_ail = 15. d_ele = 15. d_rud = 15. #clock object for tracking frames and timestep clock = pygame.time.Clock() #ticks clock before starting game loop clock.tick_busy_loop() #game loop while True: #event loop checks for game inputs such as joystick and keyboard commands for event in pygame.event.get(): if event.type == QUIT: return if KEYBOARD == False: if event.type == pygame.JOYBUTTONDOWN: if event.button ==2: FPV = not FPV cam.pos_storage.clear() cam.up_storage.clear() cam.target_storage.clear() else: if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: UP = True if event.key == pygame.K_DOWN: DOWN = True if event.key == pygame.K_LEFT: LEFT = True if event.key == pygame.K_RIGHT: RIGHT = True if event.key == pygame.K_w: WW = True if event.key == pygame.K_s: SS = True if event.key == pygame.K_a: AA = True if event.key == pygame.K_d: DD = True if event.key == pygame.K_SPACE: FPV = not FPV cam.pos_storage.clear() cam.up_storage.clear() cam.target_storage.clear() if event.type == pygame.KEYUP: if event.key == pygame.K_UP: UP = False if event.key == pygame.K_DOWN: DOWN = False if event.key == pygame.K_LEFT: LEFT = False if event.key == pygame.K_RIGHT: RIGHT = False if event.key == pygame.K_w: WW = False if event.key == pygame.K_s: SS = False if event.key == pygame.K_a: AA = False if event.key == pygame.K_d: DD = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_i: DATA = not DATA #pause simulation if event.key == pygame.K_p: PAUSE = not PAUSE #quit game if event.key == pygame.K_q: return #maintains framerate even if sim is paused if PAUSE == True: clock.tick(target_framerate) #if game is not paused, runs sim if PAUSE == False: #set default background color for sky glClearColor(0.65,1.0,1.0,1.0) glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) #timestep for simulation is based on framerate t= clock.tick(target_framerate)/1000. # if joystick is being used, gets joystick input and creates control_state dicitonary if KEYBOARD == False: control_state = { "aileron": (joy.get_axis(0)**3)*-d_ail, "elevator": (joy.get_axis(1)**3)*-d_ele, "rudder": (joy.get_axis(3)**3)*-d_rud, "throttle": (-joy.get_axis(2)+1.)*0.5, "flaps": 0. } # if joystick is not being used, gets keyboard input and creates control_state dictionary else: if UP == True and DOWN == False: ele = 1. elif UP == False and DOWN == True: ele = -1. else: ele = 0. if LEFT == True and RIGHT == False: ail = 1. elif LEFT == False and RIGHT == True: ail = -1. else: ail = 0. if AA == True and DD == False: rud = 1. elif AA == False and DD == True: rud = -1. else: rud = 0. if WW == True and SS == False and thr<=1.0: thr += 0.05 elif WW == False and SS == True and thr>=0.0: thr -= 0.05 control_state = { "aileron": ail*d_ail, "elevator": ele*d_ele, "rudder": rud*d_rud, "throttle": thr, "flaps": 0. } #SIMULATION CALCULATIONS GO BELOW HERE FOR EACH TIME STEP #IT IS RECOMMENDED THAT YOU MAKE AN OBJECT FOR THE SIMULATION AIRCRAFT AND CREATE A FUNCTION IN SAID OBJECT TO CALCULATE THE NEXT TIME STEP. #THIS FUNCTION CAN THEN BE CALLED HERE simulation.run_sim(a_obj, dt) #INPUT POSITION, ORIENTATION, AND VELOCITY OF AIRCRAFT INTO THIS DICTIONARY WHICH WILL THEN UPDATE THE GRAPHICS aircraft_condition = { "Position":a_obj.state_vars[6:9],#input position of form [x,y,z] "Orientation":a_obj.state_vars[-4:],#input orientation in quaternion form [e0,ex,ey,ez] "Velocity":a_obj.state_vars[:4] #input Velocity of form [u,v,w] } flight_data = { "Graphics Time Step": t,#sec "Physics Time Step": dt,#sec "Airspeed": a_obj.V_now,#feet/sec "AoA":a_obj.alpha_now ,#deg "Sideslip": a_obj.beta_now ,#deg "Altitude":-a_obj.state_vars[8] ,#feet "Latitude":a_obj.state_vars[6] ,#deg "Longitude":a_obj.state_vars[7] ,#deg "Time":0. ,#sec "Bank":a_obj.bank ,#deg "Elevation":a_obj.elevation ,#deg "Heading":a_obj.heading ,#deg "Gnd Speed":a_obj.V_now ,#feet/sec "Gnd Track":0. ,#deg "Climb":a_obj.climb, #feet/min # "Throttle":control_state["throttle"]*100 ,#% # "Elevator":control_state["elevator"] ,#deg # "Ailerons":control_state["aileron"] ,#deg # "Rudder":control_state["rudder"] ,#deg # "Flaps":control_state["flaps"] ,#deg "Throttle":a_obj.tau_o ,#% "Elevator":a_obj.de_o ,#deg "Ailerons":a_obj.da_o ,#deg "Rudder":a_obj.dr_o ,#deg "Flaps":0.,#deg "Axial G-Force":0. ,#g's "Side G-Force":0. ,#g's "Normal G-Force":0. ,#g's "Roll Rate": a_obj.p_o ,#deg/s "Pitch Rate":a_obj.q_o ,#deg/s "Yaw Rate":a_obj.r_o #deg/s } #apply position and orientation to graphics graphics_aircraft.set_orientation(graphics.swap_quat(aircraft_condition["Orientation"])) graphics_aircraft.set_position(aircraft_condition["Position"]) #test game over conditions if graphics_aircraft.position[2]>0.: LOSE = True #if you get a game over, display lose screen if LOSE == True: glClearColor(0,0,0,1.0) glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) gameover.draw(-0.2,-0.05,"Game Over",(0,255,0,1)) PAUSE = True #otherwise, render graphics #Third person view elif FPV == False: #get view matrix and render scene view = cam.third_view(graphics_aircraft) graphics_aircraft.set_view(view) field.set_view(view) graphics_aircraft.render() field.render() if DATA == True: data.render(flight_data) #cockpit view elif FPV == True: view = cam.cockpit_view(graphics_aircraft) field.set_view(view) field.render() if DATA == True: data.render(flight_data) HUD.render(aircraft_condition,view) #update screen display pygame.display.flip()
# -*- coding: utf-8 -*- import aircraft Aeris_4A_atmos = aircraft.Aircraft() Aeris_4A_atmos.name = "Aeris_4A_atmos" Aeris_4A_atmos.bnamber_prefix = 'A4Aatm' Aeris_4A_atmos.preRunwayHill = 40 Aeris_4A_atmos.RunwayHill = 10 Aeris_4A_atmos.MaxTakeoffMass = 15000 Aeris_4A_atmos.mass0 = 12230 Aeris_4A_atmos.landingspeed0 = 80 Aeris_4A_atmos.CruiseSpeed = 160 basic_aircraft = Aeris_4A_atmos
def __init__(self, options, path): """Prepare the network, criterion, solver, and data. Args: options, dict: Hyperparameters. """ print('Prepare the network and data.') self._options = options self._path = path # Network. if self._options['dataset'] == 'cub200': num_classes = 200 elif self._options['dataset'] == 'aircraft': num_classes = 100 else: raise NotImplementedError("Dataset " + self._options['dataset'] + " is not implemented.") self._net = BCNN(num_classes=num_classes, pretrained=options['target'] == 'fc') # Load the model from disk. if options['target'] == 'all': self._net.load_state_dict(torch.load(self._path['model'])) self._net = torch.nn.parallel.DistributedDataParallel( self._net.cuda(), device_ids=[self._options['local_rank']], output_device=self._options['local_rank']) if dist.get_rank() == 0: print(self._net) # Criterion. self._criterion = torch.nn.CrossEntropyLoss().cuda() # Solver. self._solver = torch.optim.SGD( self._net.module.trainable_params, lr=self._options['base_lr'] * dist.get_world_size(), momentum=0.9, weight_decay=self._options['weight_decay']) self._scheduler = torch.optim.lr_scheduler.ReduceLROnPlateau( self._solver, mode='max', factor=0.1, patience=3, verbose=True, threshold=1e-4) train_transforms = torchvision.transforms.Compose([ torchvision.transforms.Resize(size=448), # Let smaller edge match torchvision.transforms.RandomHorizontalFlip(), torchvision.transforms.RandomCrop(size=448), torchvision.transforms.ToTensor(), torchvision.transforms.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)) ]) test_transforms = torchvision.transforms.Compose([ torchvision.transforms.Resize(size=448), torchvision.transforms.CenterCrop(size=448), torchvision.transforms.ToTensor(), torchvision.transforms.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)) ]) if self._options['dataset'] == 'cub200': train_data = cub200.CUB200(root=self._path['dataset'], train=True, download=True, transform=train_transforms) test_data = cub200.CUB200(root=self._path['dataset'], train=False, download=True, transform=test_transforms) elif self._options['dataset'] == 'aircraft': train_data = aircraft.Aircraft(root=self._path['dataset'], train=True, download=True, transform=train_transforms) test_data = aircraft.Aircraft(root=self._path['dataset'], train=False, download=True, transform=test_transforms) else: raise NotImplementedError("Dataset " + self._options['dataset'] + " is not implemented.") # Partition dataset among workers using DistributedSampler train_sampler = distributed.DistributedSampler( train_data, num_replicas=dist.get_world_size(), rank=dist.get_rank()) test_sampler = distributed.DistributedSampler( test_data, num_replicas=dist.get_world_size(), rank=dist.get_rank()) self._train_loader = torch.utils.data.DataLoader( train_data, batch_size=self._options['batch_size'], shuffle=False, num_workers=4, pin_memory=True, sampler=train_sampler) self._test_loader = torch.utils.data.DataLoader( test_data, batch_size=self._options['batch_size'], shuffle=False, num_workers=4, pin_memory=True, sampler=test_sampler)
import airline, aircraft, flight # Test aircraft ac = aircraft.Aircraft() ac.callsign = "AC320" ac.type = "A320" ac.seats = 80 aircraft.show_aircraft(ac) # Test flight fl = flight.Flight() fl.dep = "Barcelona" fl.arr = "Vigo" fl.time_dep = 60 * 8 fl.time_arr = 60 * 9 + 10 fl.passengers = 81 flight.show_flight(fl) print(flight.fits_flight_in_aircraft(fl, ac)) # Test airline al = airline.Airline() al.name = "Rabos Airlines" al.aircrafts.append(ac) al.operations.append(fl) airline.show_airline(al)
def flight_simulator(filename, t0): a_obj = aircraft.Aircraft() dt, t_lim = simulation.load_file(filename, a_obj) simulation.initialize(a_obj) simulation.run_sim(a_obj, t0, dt, t_lim)