def reset5(): print("X-Plane Connect example script") print("Setting up simulation") with xpc.XPlaneConnect() as client: # Verify connection try: # If X-Plane does not respond to the request, a timeout error # will be raised. client.getDREF("sim/test/test_float") except: print("Error establishing connection to X-Plane.") print("Exiting...") return # Set position of the player aircraft print("Setting position") # Lat Lon Alt Pitch Roll Yaw Gear posi = [31.246, -109.63, 2000, 0, 0, 0, 0] client.sendPOSI(posi) # Set angle of attack, velocity, and orientation using the DATA command print("Setting orientation") data = [ \ [18, 0, -998, 0, -998, -998, -998, -998, -998], \ [3, 130, 130, 130, 130, -998, -998, -998, -998], \ [16, 0, 0, 0, -998, -998, -998, -998, -998] \ ] client.sendDATA(data) # Set control surfaces and throttle of the player aircraft using sendCTRL print("Setting controls") ctrl = [0.0, 0.0, 0.0, 0.8] client.sendCTRL(ctrl) client.sendDREF("sim/operation/quit", 1.0)
def set_waypoint(waypoint): print("Setting next waypoint") with xpc.XPlaneConnect() as client: # Verify connection try: # If X-Plane does not respond to the request, a timeout error # will be raised. client.getDREF("sim/test/test_float") except: print("Error establishing connection to X-Plane.") print("Exiting...") client.sendWYPT(1, waypoint)
def reset_wp(): with xpc.XPlaneConnect() as client: # Verify connection try: # If X-Plane does not respond to the request, a timeout error # will be raised. client.getDREF("sim/test/test_float") except: print("Error establishing connection to X-Plane.") print("Exiting...") return client.sendWYPT(3, [])
def pedal_neutral(): with xpc.XPlaneConnect() as client: # Verify connection try: # If X-Plane does not respond to the request, a timeout error # will be raised. client.getDREF("sim/test/test_float") except: print("Error establishing connection to X-Plane.") print("Exiting...") return pedal_n = [-998, -998, 0.0, -998, -998, -998, -998] client.sendCTRL(pedal_n)
def speedbr_up_full(): with xpc.XPlaneConnect() as client: # Verify connection try: # If X-Plane does not respond to the request, a timeout error # will be raised. client.getDREF("sim/test/test_float") except: print("Error establishing connection to X-Plane.") print("Exiting...") return head_l = [-998, -998, -998, -998, -998, -998, 1.5] client.sendPOSI(head_l)
def flaps_down_full(): with xpc.XPlaneConnect() as client: # Verify connection try: # If X-Plane does not respond to the request, a timeout error # will be raised. client.getDREF("sim/test/test_float") except: print("Error establishing connection to X-Plane.") print("Exiting...") return flaps_uf = [-998, -998, -998, -998, -998, -1, -998] client.sendCTRL(flaps_uf)
def check_fuel(): print("Setting next waypoint") with xpc.XPlaneConnect() as client: # Verify connection try: # If X-Plane does not respond to the request, a timeout error # will be raised. client.getDREF("sim/test/test_float") except: print("Error establishing connection to X-Plane.") print("Exiting...") dataref = "sim/flightmodel/weight/m_fuel_total" fuel = client.getDREF(dataref) print(fuel)
def throttle_down_half(): print('throttle_down_half') with xpc.XPlaneConnect() as client: # Verify connection try: # If X-Plane does not respond to the request, a timeout error # will be raised. client.getDREF("sim/test/test_float") except: print("Error establishing connection to X-Plane.") print("Exiting...") return throttle_dh = [-998, -998, -998, -0.5, -998, -998, -998] client.sendCTRL(throttle_dh)
def mid_left(): print('mid_left') with xpc.XPlaneConnect() as client: # Verify connection try: # If X-Plane does not respond to the request, a timeout error # will be raised. client.getDREF("sim/test/test_float") except: print("Error establishing connection to X-Plane.") print("Exiting...") return mid_l = [0.0, -1.0, -998, -998, -998, -998, -998] client.sendCTRL(mid_l)
def reset(self): print("reset") with xpc.XPlaneConnect() as client: # Verify connection try: # If X-Plane does not respond to the request, a timeout error # will be raised. client.getDREF("sim/test/test_float") except: print("Error establishing connection to X-Plane.") print("Exiting...") return # Setting the starting waypoint set_waypoint(self.waypoints[0]) # Setting simulation speed simulation_dref = "sim/time/sim_speed" client.sendDREF(simulation_dref, 1000.0) res = client.getDREF(simulation_dref) print(res) # Selecting the current and XPlane window current_window = pygetwindow.getActiveWindow() xplane_window = pygetwindow.getWindowsWithTitle("X-System")[0] # Focuss on the Xplane window xplane_window.activate() # Performing the reset command ctr+; on the focussed window keyDown('ctrl') keyDown(';') keyUp('ctrl') keyUp(';') time.sleep(3) # Releasing brakes keyDown('b') keyUp('b') # Return to the old window I was on current_window.activate() # Gives the simulator enough time to reload time.sleep(3) # Get observation obs_incomplete = observation() # time.sleep(3) # Add the waypoint as input aswell current_waypoint = np.array(self.current_waypoint) obs = np.append(obs_incomplete, current_waypoint) print(obs.shape) return obs
def heading_right(): print("X-Plane Connect example script") print("Setting up simulation") with xpc.XPlaneConnect() as client: # Verify connection try: # If X-Plane does not respond to the request, a timeout error # will be raised. client.getDREF("sim/test/test_float") except: print("Error establishing connection to X-Plane.") print("Exiting...") return head_r = [-988, -998, -988, -988, -988, 1, -988] client.sendPOSI(head_r)
def send_waypoints(): print("X-Plane Connect example script") print("Setting up simulation") with xpc.XPlaneConnect() as client: # Verify connection try: # If X-Plane does not respond to the request, a timeout error # will be raised. client.getDREF("sim/test/test_float") except: print("Error establishing connection to X-Plane.") print("Exiting...") return res = client.getPOSI(0) print(res)
def test_(): with xpc.XPlaneConnect() as client: # Verify connection try: # If X-Plane does not respond to the request, a timeout error # will be raised. client.getDREF("sim/test/test_float") except: print("Error establishing connection to X-Plane.") print("Exiting...") return val = client.getPOSI() print(val[0]) arr = np.array([val[0]], dtype='c16') print(arr)
def test_waypoint(): print("X-Plane Connect example script") print("Setting up simulation") with xpc.XPlaneConnect() as client: # Verify connection try: # If X-Plane does not respond to the request, a timeout error # will be raised. client.getDREF("sim/test/test_float") except: print("Error establishing connection to X-Plane.") print("Exiting...") return client.sendWYPT(1,[52.308099999999996,4.764170000000007, 0, 53.07139999999998,7.195830000000001,74146.982,53.633700000000005,9.985260000000011,0]) print('sent')
def record_waypoint(self): print("Setting up simulation") with xpc.XPlaneConnect() as client: # Verify connection try: # If X-Plane does not respond to the request, a timeout error # will be raised. client.getDREF("sim/test/test_float") except: print("Error establishing connection to X-Plane.") print("Exiting...") return for _ in range(100): time.sleep(2) pt = client.getPOSI()[0:3] print(pt)
def check_failures(): print("Checking for failures") with xpc.XPlaneConnect() as client: # Verify connection try: # If X-Plane does not respond to the request, a timeout error # will be raised. client.getDREF("sim/test/test_float") except: print("Error establishing connection to X-Plane.") print("Exiting...") return failures_dref = "sim/operation/failures/failures" failures = client.getDREF(failures_dref) for x in failures: if x > 0.0: return True return False
def observation(): print("Retrieving observation") with xpc.XPlaneConnect() as client: # Verify connection try: # If X-Plane does not respond to the request, a timeout error # will be raised. client.getDREF("sim/test/test_float") except: print("Error establishing connection to X-Plane.") print("Exiting...") return air_speed_dref = "sim/flightmodel/position/true_airspeed" air_speed = client.getDREF(air_speed_dref) position_val = client.getPOSI(0) position = np.array(position_val) observation = np.append(position, [air_speed]) return observation[0:3]
def check_route(): with xpc.XPlaneConnect() as client: # Verify connection try: # If X-Plane does not respond to the request, a timeout error # will be raised. client.getDREF("sim/test/test_float") except: print("Error establishing connection to X-Plane.") print("Exiting...") return file = open("customGym/custom_gym/envs/myxpc/take_off.json") data = json.load(file) for points in data: latitude = points['lat'] longitude = points['lon'] altitude = points['alt'] time.sleep(1) client.sendWYPT(1, np.array([latitude, longitude, altitude]))