Fixed bugs in MATLAB Example and added support for setting timeout.

This commit is contained in:
Jason Watkins
2015-07-06 08:34:58 -07:00
parent dcdcf22751
commit ad2f455079
2 changed files with 15 additions and 14 deletions

View File

@@ -26,6 +26,7 @@ p = inputParser;
addOptional(p,'xpHost','127.0.0.1',@ischar); addOptional(p,'xpHost','127.0.0.1',@ischar);
addOptional(p,'xpPort',49009,@isnumeric); addOptional(p,'xpPort',49009,@isnumeric);
addOptional(p,'port',0,@isnumeric); addOptional(p,'port',0,@isnumeric);
addOptional(p,'timeout',0,@isnumeric);
parse(p,varargin{:}); parse(p,varargin{:});
%% Create client %% Create client
@@ -33,7 +34,7 @@ if ~exist('gov.nasa.xpc.XPlaneConnect', 'class')
[folder, ~, ~] = fileparts(which('XPlaneConnect.openUDP')); [folder, ~, ~] = fileparts(which('XPlaneConnect.openUDP'));
javaaddpath(fullfile(folder, 'XPlaneConnect.jar')); javaaddpath(fullfile(folder, 'XPlaneConnect.jar'));
end end
socket = gov.nasa.xpc.XPlaneConnect(p.Results.xpHost, p.Results.xpPort, p.Results.port); socket = gov.nasa.xpc.XPlaneConnect(p.Results.xpHost, p.Results.xpPort, p.Results.port, p.Results.timeout);
%% Track open clients %% Track open clients
global clients; global clients;

View File

@@ -10,21 +10,21 @@ import XPlaneConnect.*
disp('xplaneconnect Example Script-'); disp('xplaneconnect Example Script-');
disp('Setting up Simulation'); disp('Setting up Simulation');
Socket = openUDP(49005); Socket = openUDP('127.0.0.1', 49009);
%% Ensure connected %% Ensure connected
getDREFs('sim/test/test_float') getDREFs('sim/test/test_float', Socket);
%% Set position of the player aircraft %% Set position of the player aircraft
disp('Setting position'); disp('Setting position');
pauseSim(1); pauseSim(1, Socket);
% Lat Lon Alt Pitch Roll Heading Gear % Lat Lon Alt Pitch Roll Heading Gear
POSI = [37.524, -122.06899, 2500, 0, 0, 0, 1]; POSI = [37.524, -122.06899, 2500, 0, 0, 0, 1];
sendPOSI(POSI); % Set own aircraft position sendPOSI(POSI, 0, Socket); % Set own aircraft position
% Lat Lon Alt Pitch Roll Heading Gear % Lat Lon Alt Pitch Roll Heading Gear
POSI = [37.52465, -122.06899, 2500, 0, 20, 0, 1]; POSI = [37.52465, -122.06899, 2500, 0, 20, 0, 1];
sendPOSI(POSI, 1); % Place another aircraft just north of us sendPOSI(POSI, 1, Socket); % Place another aircraft just north of us
%% Set rates %% Set rates
disp('Setting rates'); disp('Setting rates');
% Alpha Velocity PQR % Alpha Velocity PQR
@@ -32,30 +32,30 @@ data = struct('h',[18, 3, 16],...
'd',[0,-999,0,-999,-999,-999,-999,-999;... % Alpha data 'd',[0,-999,0,-999,-999,-999,-999,-999;... % Alpha data
130,130,130,130,-999,-999,-999,-999;... % Velocity data 130,130,130,130,-999,-999,-999,-999;... % Velocity data
0,0,0,-999,-999,-999,-999,-999]); % PQR data 0,0,0,-999,-999,-999,-999,-999]); % PQR data
sendDATA(data); sendDATA(data, Socket);
%% Set CTRL %% Set CTRL
% Throttle % Throttle
CTRL = [0,0,0,0.8]; CTRL = [0,0,0,0.8,0,0];
sendCTRL(CTRL); sendCTRL(CTRL, 0, Socket);
pause(5); pause(5);
pauseSim(0); pauseSim(0, Socket);
pause(5) % Run sim for 5 seconds pause(5) % Run sim for 5 seconds
%% Pause sim %% Pause sim
disp('Pausing simulation'); disp('Pausing simulation');
pauseSim(1); pauseSim(1, Socket);
pause(5); pause(5);
disp('Unpausing simulation'); disp('Unpausing simulation');
pauseSim(0); pauseSim(0, Socket);
pause(10) % Run sim for 10 seconds pause(10) % Run sim for 10 seconds
%% Use DREF to raise landing gear %% Use DREF to raise landing gear
disp('Raising gear'); disp('Raising gear');
gearDREF = 'sim/cockpit/switches/gear_handle_status'; gearDREF = 'sim/cockpit/switches/gear_handle_status';
sendDREF(gearDREF, 0); sendDREF(gearDREF, 0, Socket);
pause(10) % Run sim for 10 seconds pause(10) % Run sim for 10 seconds
%% Confirm gear and paus status by reading DREFs %% Confirm gear and paus status by reading DREFs
disp('Checking gear'); disp('Checking gear');
pauseDREF = 'sim/operation/override/override_planepath'; pauseDREF = 'sim/operation/override/override_planepath';
result = requestDREF({gearDREF, pauseDREF}); result = getDREFs({gearDREF, pauseDREF}, Socket);
if result{1} == 0 if result{1} == 0
disp('Gear stowed'); disp('Gear stowed');
else else