Merge branch 'master' into develop
# Conflicts: # xpcPlugin/XPlaneConnect/mac.xpl # xpcPlugin/xpcPlugin.xcodeproj/project.pbxproj
This commit is contained in:
Binary file not shown.
@@ -22,6 +22,10 @@ socket.close;
|
||||
|
||||
%% Track open clients
|
||||
global clients;
|
||||
%TODO: Remove stale clients
|
||||
for i = 1:length(clients)
|
||||
if socket == clients(i)
|
||||
clients = [clients(1:i-1) clients(i+1:length(clients))];
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
29
MATLAB/+XPlaneConnect/getCTRL.m
Normal file
29
MATLAB/+XPlaneConnect/getCTRL.m
Normal file
@@ -0,0 +1,29 @@
|
||||
function ctrl = getCTRL(ac, socket)
|
||||
% getCTRL Gets control surface information for the specified aircraft
|
||||
%
|
||||
% Inputs
|
||||
% ac: The aircraft number to get control surface data for.
|
||||
% Outputs
|
||||
% posi: An array of values matching the the format used by sendCTRL
|
||||
|
||||
|
||||
import XPlaneConnect.*
|
||||
|
||||
%% Get client
|
||||
global clients;
|
||||
if ~exist('socket', 'var')
|
||||
assert(isequal(length(clients) < 2, 1), '[getCTRL] ERROR: Multiple clients open. You must specify which client to use.');
|
||||
if isempty(clients)
|
||||
socket = openUDP();
|
||||
else
|
||||
socket = clients(1);
|
||||
end
|
||||
end
|
||||
|
||||
%% Validate input
|
||||
ac = int32(ac);
|
||||
|
||||
%% Send command
|
||||
ctrl = socket.getCTRL(ac);
|
||||
|
||||
end
|
||||
29
MATLAB/+XPlaneConnect/getPOSI.m
Normal file
29
MATLAB/+XPlaneConnect/getPOSI.m
Normal file
@@ -0,0 +1,29 @@
|
||||
function posi = getPOSI(ac, socket)
|
||||
% getPOSI Gets position information for the specified aircraft
|
||||
%
|
||||
% Inputs
|
||||
% ac: The aircraft number to get position data for.
|
||||
% Outputs
|
||||
% posi: An array of values matching the the format used by sendPOSI
|
||||
|
||||
|
||||
import XPlaneConnect.*
|
||||
|
||||
%% Get client
|
||||
global clients;
|
||||
if ~exist('socket', 'var')
|
||||
assert(isequal(length(clients) < 2, 1), '[getPOSI] ERROR: Multiple clients open. You must specify which client to use.');
|
||||
if isempty(clients)
|
||||
socket = openUDP();
|
||||
else
|
||||
socket = clients(1);
|
||||
end
|
||||
end
|
||||
|
||||
%% Validate input
|
||||
ac = int32(ac);
|
||||
|
||||
%% Send command
|
||||
posi = socket.getPOSI(ac);
|
||||
|
||||
end
|
||||
@@ -26,6 +26,7 @@ p = inputParser;
|
||||
addOptional(p,'xpHost','127.0.0.1',@ischar);
|
||||
addOptional(p,'xpPort',49009,@isnumeric);
|
||||
addOptional(p,'port',0,@isnumeric);
|
||||
addOptional(p,'timeout',100,@isnumeric);
|
||||
parse(p,varargin{:});
|
||||
|
||||
%% Create client
|
||||
@@ -33,7 +34,7 @@ if ~exist('gov.nasa.xpc.XPlaneConnect', 'class')
|
||||
[folder, ~, ~] = fileparts(which('XPlaneConnect.openUDP'));
|
||||
javaaddpath(fullfile(folder, 'XPlaneConnect.jar'));
|
||||
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
|
||||
global clients;
|
||||
|
||||
@@ -1,17 +1,8 @@
|
||||
function sendDREF( dref, value, socket )
|
||||
% sendDREF Sends a command to X-Plane that sets the given DREF.
|
||||
% sendDREFs Sends a command to X-Plane that sets the given DREF. This
|
||||
% function is now an alias to sendDREFs. It is kept only for backwards
|
||||
% compatibility.
|
||||
%
|
||||
% Inputs
|
||||
% dref: The name of the X-Plane dataref to set.
|
||||
% Value: An array of floating point values whose structure depends on the dref specified.
|
||||
% socket (optional): The client to use when sending the command.
|
||||
%
|
||||
% Use
|
||||
% 1. import XPlaneConnect.*
|
||||
% 2. dataRef = 'sim/aircraft/parts/acf_gear_deploy'; // Landing Gear
|
||||
% 3. Value = 0;
|
||||
% 4. status = setDREF(dataRef, Value);
|
||||
%
|
||||
% Contributors
|
||||
% [CT] Christopher Teubert (SGT, Inc.)
|
||||
% christopher.a.teubert@nasa.gov
|
||||
@@ -20,19 +11,8 @@ function sendDREF( dref, value, socket )
|
||||
|
||||
import XPlaneConnect.*
|
||||
|
||||
%% Get client
|
||||
global clients;
|
||||
if ~exist('socket', 'var')
|
||||
assert(isequal(length(clients) < 2, 1), '[setDREF] ERROR: Multiple clients open. You must specify which client to use.');
|
||||
if isempty(clients)
|
||||
socket = openUDP();
|
||||
else
|
||||
socket = clients(1);
|
||||
end
|
||||
end
|
||||
|
||||
%% Validate input
|
||||
value = single(value);
|
||||
|
||||
%%Send command
|
||||
socket.sendDREF(dref, value);
|
||||
sendDREFs(dref, value)
|
||||
else
|
||||
sendDREFs(dref, value, socket)
|
||||
end
|
||||
37
MATLAB/+XPlaneConnect/sendDREFs.m
Normal file
37
MATLAB/+XPlaneConnect/sendDREFs.m
Normal file
@@ -0,0 +1,37 @@
|
||||
function sendDREFs( drefs, values, socket )
|
||||
% sendDREFs Sends a command to X-Plane that sets the given DREF(s).
|
||||
%
|
||||
% Inputs
|
||||
% dref: The name or names of the X-Plane dataref(s) to set.
|
||||
% Value: An array or an multidimensional array of floating point values
|
||||
% whose structure depends on the dref specified.
|
||||
% socket (optional): The client to use when sending the command.
|
||||
%
|
||||
% Use
|
||||
% 1. import XPlaneConnect.*
|
||||
% 2. dataRef = 'sim/aircraft/parts/acf_gear_deploy'; // Landing Gear
|
||||
% 3. Value = 0;
|
||||
% 4. status = setDREF(dataRef, Value);
|
||||
%
|
||||
% Contributors
|
||||
% [JW] Jason Watkins
|
||||
% jason.w.watkins@nasa.gov
|
||||
|
||||
import XPlaneConnect.*
|
||||
|
||||
%% Get client
|
||||
global clients;
|
||||
if ~exist('socket', 'var')
|
||||
assert(isequal(length(clients) < 2, 1), '[setDREF] ERROR: Multiple clients open. You must specify which client to use.');
|
||||
if isempty(clients)
|
||||
socket = openUDP();
|
||||
else
|
||||
socket = clients(1);
|
||||
end
|
||||
end
|
||||
|
||||
%% Validate input
|
||||
values = single(values);
|
||||
|
||||
%%Send command
|
||||
socket.sendDREFs(drefs, values);
|
||||
35
MATLAB/+XPlaneConnect/sendVIEW.m
Normal file
35
MATLAB/+XPlaneConnect/sendVIEW.m
Normal file
@@ -0,0 +1,35 @@
|
||||
function sendVIEW(view, socket)
|
||||
% sendVIEW Sets the camera
|
||||
%
|
||||
%Inputs
|
||||
% view: The view to use.
|
||||
% socket (optional): The client to use when sending the command.
|
||||
%
|
||||
%Use
|
||||
% 1. import XPlaneConnect.*;
|
||||
% 2. sendView(Forwards);
|
||||
%
|
||||
% Contributors
|
||||
% [JW] Jason Watkins <jason.w.watkins@nasa.gov>
|
||||
|
||||
import XPlaneConnect.*
|
||||
|
||||
%% Get client
|
||||
global clients;
|
||||
if ~exist('socket', 'var')
|
||||
assert(isequal(length(clients) < 2, 1), '[pauseSim] ERROR: Multiple clients open. You must specify which client to use.');
|
||||
if isempty(clients)
|
||||
socket = openUDP();
|
||||
else
|
||||
socket = clients(1);
|
||||
end
|
||||
end
|
||||
|
||||
%% Validate input
|
||||
|
||||
|
||||
%% Send command
|
||||
socket.sendVIEW(view)
|
||||
|
||||
end
|
||||
|
||||
@@ -10,21 +10,21 @@ import XPlaneConnect.*
|
||||
|
||||
disp('xplaneconnect Example Script-');
|
||||
disp('Setting up Simulation');
|
||||
Socket = openUDP(49005);
|
||||
Socket = openUDP('127.0.0.1', 49009);
|
||||
|
||||
%% Ensure connected
|
||||
getDREFs('sim/test/test_float')
|
||||
getDREFs('sim/test/test_float', Socket);
|
||||
|
||||
%% Set position of the player aircraft
|
||||
disp('Setting position');
|
||||
pauseSim(1);
|
||||
pauseSim(1, Socket);
|
||||
% Lat Lon Alt Pitch Roll Heading Gear
|
||||
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
|
||||
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
|
||||
disp('Setting rates');
|
||||
% Alpha Velocity PQR
|
||||
@@ -32,30 +32,30 @@ data = struct('h',[18, 3, 16],...
|
||||
'd',[0,-999,0,-999,-999,-999,-999,-999;... % Alpha data
|
||||
130,130,130,130,-999,-999,-999,-999;... % Velocity data
|
||||
0,0,0,-999,-999,-999,-999,-999]); % PQR data
|
||||
sendDATA(data);
|
||||
sendDATA(data, Socket);
|
||||
%% Set CTRL
|
||||
% Throttle
|
||||
CTRL = [0,0,0,0.8];
|
||||
sendCTRL(CTRL);
|
||||
CTRL = [0,0,0,0.8,0,0];
|
||||
sendCTRL(CTRL, 0, Socket);
|
||||
pause(5);
|
||||
pauseSim(0);
|
||||
pauseSim(0, Socket);
|
||||
pause(5) % Run sim for 5 seconds
|
||||
%% Pause sim
|
||||
disp('Pausing simulation');
|
||||
pauseSim(1);
|
||||
pauseSim(1, Socket);
|
||||
pause(5);
|
||||
disp('Unpausing simulation');
|
||||
pauseSim(0);
|
||||
pauseSim(0, Socket);
|
||||
pause(10) % Run sim for 10 seconds
|
||||
%% Use DREF to raise landing gear
|
||||
disp('Raising gear');
|
||||
gearDREF = 'sim/cockpit/switches/gear_handle_status';
|
||||
sendDREF(gearDREF, 0);
|
||||
sendDREF(gearDREF, 0, Socket);
|
||||
pause(10) % Run sim for 10 seconds
|
||||
%% Confirm gear and paus status by reading DREFs
|
||||
disp('Checking gear');
|
||||
pauseDREF = 'sim/operation/override/override_planepath';
|
||||
result = requestDREF({gearDREF, pauseDREF});
|
||||
result = getDREFs({gearDREF, pauseDREF}, Socket);
|
||||
if result{1} == 0
|
||||
disp('Gear stowed');
|
||||
else
|
||||
|
||||
19
MATLAB/MonitorExample/MonitorExample.m
Normal file
19
MATLAB/MonitorExample/MonitorExample.m
Normal file
@@ -0,0 +1,19 @@
|
||||
%% X-Plane Connect MATLAB Example Script
|
||||
% This script demonstrates how to read and write data to the XPC plugin.
|
||||
% Before running this script, ensure that the XPC plugin is installed and
|
||||
% X-Plane is running.
|
||||
%% Import XPC
|
||||
clear all
|
||||
addpath('../')
|
||||
import XPlaneConnect.*
|
||||
|
||||
Socket = openUDP();
|
||||
while 1
|
||||
posi = getPOSI(0, Socket);
|
||||
ctrl = getCTRL(0, Socket);
|
||||
|
||||
fprintf('Loc: (%4f, %4f, %4f) Aileron:%2f Elevator:%2f Rudder:%2f\n', ...
|
||||
posi(1), posi(2), posi(3), ctrl(2), ctrl(1), ctrl(3));
|
||||
pause(0.1);
|
||||
end
|
||||
closeUDP(Socket);
|
||||
100
MATLAB/PlaybackExample/MyRecording.txt
Normal file
100
MATLAB/PlaybackExample/MyRecording.txt
Normal file
@@ -0,0 +1,100 @@
|
||||
37.184181, -120.793640, 3904.040771, 1.856917, 0.001644, 116.058609, 0.000000
|
||||
37.184143, -120.793541, 3903.825928, 2.172139, -0.034512, 115.875587, 0.000000
|
||||
37.184090, -120.793404, 3903.511719, 2.425995, -0.111958, 115.577911, 0.000000
|
||||
37.184040, -120.793282, 3903.230225, 2.497653, -0.205506, 115.289268, 0.000000
|
||||
37.183994, -120.793167, 3902.961914, 2.478850, -0.315117, 115.006279, 0.000000
|
||||
37.183949, -120.793053, 3902.683838, 2.412536, -0.447890, 114.716370, 0.000000
|
||||
37.183910, -120.792953, 3902.452881, 2.344441, -0.570747, 114.485756, 0.000000
|
||||
37.183857, -120.792824, 3902.137939, 2.253826, -0.752984, 114.194984, 0.000000
|
||||
37.183807, -120.792702, 3901.830566, 2.178489, -0.942979, 113.943779, 0.000000
|
||||
37.183765, -120.792595, 3901.561279, 2.125190, -1.116157, 113.754135, 0.000000
|
||||
37.183735, -120.792511, 3901.342773, 2.089507, -1.260052, 113.621834, 0.000000
|
||||
37.183693, -120.792404, 3901.058350, 2.051378, -1.449701, 113.479713, 0.000000
|
||||
37.183628, -120.792244, 3900.620361, 2.004393, -1.742637, 113.320374, 0.000000
|
||||
37.183571, -120.792107, 3900.232178, 1.969860, -1.999084, 113.234406, 0.000000
|
||||
37.183529, -120.791992, 3899.922852, 1.945357, -2.199157, 113.199463, 0.000000
|
||||
37.183487, -120.791885, 3899.607666, 1.922479, -2.397843, 113.190887, 0.000000
|
||||
37.183441, -120.791771, 3899.279297, 1.738008, -2.604320, 113.214371, 0.000000
|
||||
37.183395, -120.791649, 3898.942383, 1.172052, -2.819112, 113.280800, 0.000000
|
||||
37.183342, -120.791512, 3898.525879, 0.437769, -3.059577, 113.392952, 0.000000
|
||||
37.183292, -120.791389, 3898.116943, -0.110597, -3.260861, 113.510010, 0.000000
|
||||
37.183247, -120.791275, 3897.675293, -0.458939, -3.399007, 113.635101, 0.000000
|
||||
37.183220, -120.791206, 3897.409668, -0.495934, -3.425584, 113.706985, 0.000000
|
||||
37.183182, -120.791107, 3896.976318, -0.338542, -3.312644, 113.832870, 0.000000
|
||||
37.183128, -120.790962, 3896.313965, 0.088305, -2.812056, 114.069130, 0.000000
|
||||
37.183083, -120.790848, 3895.734863, 0.355302, -2.143086, 114.327766, 0.000000
|
||||
37.183033, -120.790718, 3895.112061, 0.345563, -1.171917, 114.668144, 0.000000
|
||||
37.182987, -120.790604, 3894.519043, 0.034761, -0.025642, 115.037415, 0.000000
|
||||
37.182941, -120.790489, 3893.926270, -0.549108, 1.265883, 115.421654, 0.000000
|
||||
37.182888, -120.790344, 3893.151611, -1.627703, 3.039703, 115.896240, 0.000000
|
||||
37.182831, -120.790199, 3892.313477, -2.879907, 4.868656, 116.325722, 0.000000
|
||||
37.182785, -120.790077, 3891.557129, -3.883288, 6.350969, 116.633751, 0.000000
|
||||
37.182743, -120.789970, 3890.766602, -4.752331, 7.729563, 116.888329, 0.000000
|
||||
37.182705, -120.789871, 3889.997314, -5.439554, 8.871016, 117.077042, 0.000000
|
||||
37.182659, -120.789749, 3888.965820, -6.164141, 10.014505, 117.239494, 0.000000
|
||||
37.182610, -120.789627, 3887.832031, -6.734039, 10.811956, 117.319382, 0.000000
|
||||
37.182560, -120.789505, 3886.558594, -7.134449, 11.245357, 117.313339, 0.000000
|
||||
37.182514, -120.789383, 3885.197510, -7.320403, 11.326477, 117.228592, 0.000000
|
||||
37.182465, -120.789261, 3883.700439, -7.264509, 11.086659, 117.071564, 0.000000
|
||||
37.182415, -120.789131, 3882.124023, -7.020517, 10.579235, 116.843575, 0.000000
|
||||
37.182365, -120.789009, 3880.477295, -6.698184, 9.864036, 116.538239, 0.000000
|
||||
37.182316, -120.788887, 3878.771973, -6.407937, 8.986709, 116.154274, 0.000000
|
||||
37.182266, -120.788765, 3877.028076, -6.217397, 7.992366, 115.705994, 0.000000
|
||||
37.182217, -120.788643, 3875.249023, -6.173934, 6.988136, 115.220467, 0.000000
|
||||
37.182167, -120.788521, 3873.432617, -6.285208, 6.050294, 114.729034, 0.000000
|
||||
37.182117, -120.788399, 3871.583496, -6.453388, 5.213163, 114.269440, 0.000000
|
||||
37.182068, -120.788269, 3869.689209, -6.484870, 4.480176, 113.873062, 0.000000
|
||||
37.182014, -120.788147, 3867.766357, -6.310386, 3.856612, 113.555290, 0.000000
|
||||
37.181965, -120.788025, 3865.820801, -6.021461, 3.327790, 113.311180, 0.000000
|
||||
37.181915, -120.787903, 3863.870361, -5.728759, 2.874094, 113.135651, 0.000000
|
||||
37.181866, -120.787781, 3861.910156, -5.480271, 2.475115, 113.025513, 0.000000
|
||||
37.181816, -120.787651, 3859.973145, -5.302026, 2.122235, 112.979225, 0.000000
|
||||
37.181767, -120.787529, 3858.042969, -5.182843, 1.808723, 112.993736, 0.000000
|
||||
37.181717, -120.787407, 3856.119629, -5.038956, 1.552066, 113.070557, 0.000000
|
||||
37.181667, -120.787285, 3854.215088, -4.828547, 1.368155, 113.206085, 0.000000
|
||||
37.181614, -120.787148, 3852.185059, -4.515563, 1.254129, 113.410904, 0.000000
|
||||
37.181557, -120.787010, 3850.030762, -4.132499, 1.210060, 113.681358, 0.000000
|
||||
37.181507, -120.786888, 3848.263916, -3.831450, 1.225745, 113.935280, 0.000000
|
||||
37.181458, -120.786766, 3846.475342, -3.528734, 1.284648, 114.214294, 0.000000
|
||||
37.181408, -120.786644, 3844.712158, -3.243377, 1.382594, 114.502975, 0.000000
|
||||
37.181358, -120.786522, 3842.987549, -2.982575, 1.515415, 114.790489, 0.000000
|
||||
37.181309, -120.786392, 3841.302246, -2.688687, 1.679037, 115.070442, 0.000000
|
||||
37.181259, -120.786270, 3839.659424, -2.305070, 1.869125, 115.338135, 0.000000
|
||||
37.181210, -120.786148, 3838.070068, -1.827937, 2.080883, 115.588036, 0.000000
|
||||
37.181156, -120.786018, 3836.515137, -1.326015, 2.315055, 115.817902, 0.000000
|
||||
37.181107, -120.785889, 3835.020508, -0.858468, 2.566000, 116.019691, 0.000000
|
||||
37.181053, -120.785767, 3833.605713, -0.446646, 2.827466, 116.188957, 0.000000
|
||||
37.181004, -120.785637, 3832.263672, -0.082390, 3.097450, 116.326546, 0.000000
|
||||
37.180950, -120.785515, 3830.996094, 0.248427, 3.372406, 116.433670, 0.000000
|
||||
37.180901, -120.785385, 3829.802734, 0.561189, 3.648955, 116.513596, 0.000000
|
||||
37.180847, -120.785263, 3828.686279, 0.901348, 3.909596, 116.570610, 0.000000
|
||||
37.180798, -120.785133, 3827.642090, 1.422296, 4.101938, 116.610832, 0.000000
|
||||
37.180744, -120.785011, 3826.675537, 2.124010, 4.216800, 116.636208, 0.000000
|
||||
37.180691, -120.784889, 3825.800049, 2.895841, 4.268193, 116.644135, 0.000000
|
||||
37.180641, -120.784767, 3825.024658, 3.647615, 4.264566, 116.632553, 0.000000
|
||||
37.180588, -120.784637, 3824.355469, 4.389325, 4.198403, 116.604164, 0.000000
|
||||
37.180538, -120.784523, 3823.797119, 5.116096, 4.063403, 116.559959, 0.000000
|
||||
37.180489, -120.784401, 3823.351562, 5.802851, 3.858843, 116.500069, 0.000000
|
||||
37.180435, -120.784279, 3823.021240, 6.434232, 3.583184, 116.425621, 0.000000
|
||||
37.180386, -120.784164, 3822.803223, 7.040646, 3.237821, 116.340439, 0.000000
|
||||
37.180336, -120.784042, 3822.697021, 7.629384, 2.839028, 116.249237, 0.000000
|
||||
37.180286, -120.783928, 3822.700195, 8.181519, 2.404881, 116.155312, 0.000000
|
||||
37.180244, -120.783821, 3822.798828, 8.596326, 1.981372, 116.066658, 0.000000
|
||||
37.180183, -120.783684, 3823.074219, 9.020256, 1.372200, 115.947289, 0.000000
|
||||
37.180126, -120.783554, 3823.453369, 9.331639, 0.798377, 115.847244, 0.000000
|
||||
37.180073, -120.783424, 3823.932129, 9.642418, 0.224538, 115.759720, 0.000000
|
||||
37.180019, -120.783302, 3824.521729, 9.962214, -0.365530, 115.680557, 0.000000
|
||||
37.179970, -120.783188, 3825.146240, 10.216949, -0.901261, 115.617035, 0.000000
|
||||
37.179928, -120.783081, 3825.777100, 10.420901, -1.378152, 115.566948, 0.000000
|
||||
37.179871, -120.782951, 3826.665283, 10.683296, -1.973540, 115.510689, 0.000000
|
||||
37.179817, -120.782829, 3827.599854, 10.932059, -2.526971, 115.463028, 0.000000
|
||||
37.179764, -120.782700, 3828.676758, 11.182608, -3.091355, 115.418022, 0.000000
|
||||
37.179710, -120.782570, 3829.791748, 11.405788, -3.608584, 115.379250, 0.000000
|
||||
37.179657, -120.782448, 3830.954102, 11.541166, -4.084742, 115.349564, 0.000000
|
||||
37.179604, -120.782326, 3832.230469, 11.431418, -4.526593, 115.343117, 0.000000
|
||||
37.179554, -120.782204, 3833.525391, 11.053594, -4.891589, 115.367775, 0.000000
|
||||
37.179501, -120.782082, 3834.855957, 10.596283, -5.199400, 115.407677, 0.000000
|
||||
37.179451, -120.781960, 3836.201660, 10.188977, -5.458726, 115.448441, 0.000000
|
||||
37.179401, -120.781837, 3837.573486, 9.879080, -5.681745, 115.481895, 0.000000
|
||||
37.179348, -120.781715, 3838.972656, 9.667299, -5.869191, 115.505310, 0.000000
|
||||
37.179298, -120.781593, 3840.342529, 9.507944, -5.992330, 115.524872, 0.000000
|
||||
36
MATLAB/PlaybackExample/Playback.m
Normal file
36
MATLAB/PlaybackExample/Playback.m
Normal file
@@ -0,0 +1,36 @@
|
||||
%% X-Plane Connect MATLAB Playback Example Script
|
||||
% This script demonstrates how to playback recorded data from X-Plane.
|
||||
% (See Record.m)
|
||||
% Before running this script, ensure that the XPC plugin is installed and
|
||||
% X-Plane is running.
|
||||
%% Import XPC
|
||||
addpath('../')
|
||||
import XPlaneConnect.*
|
||||
|
||||
%% Setup
|
||||
% Create variables and open connection to X-Plane
|
||||
path = 'MyRecording.txt'; % File containing stored data
|
||||
interval = 0.1; % Time between snapshots in seconds
|
||||
duration = 10;
|
||||
Socket = openUDP(); % Open connection to X-Plane
|
||||
fd = fopen(path, 'r'); % Open file
|
||||
|
||||
disp('X-Plane Connect Playback Example Script');
|
||||
fprintf('Playing back ''%s'' in %fs increments.\n', path, interval);
|
||||
|
||||
%% Start Playback
|
||||
count = floor(duration / interval);
|
||||
pauseSim(1);
|
||||
for i = 1:count
|
||||
line = fgetl(fd);
|
||||
posi = sscanf(line, '%f, %f, %f, %f, %f, %f, %f\n');
|
||||
sendPOSI(posi);
|
||||
pause(interval);
|
||||
end
|
||||
|
||||
%% Close connection and file
|
||||
pauseSim(0);
|
||||
closeUDP(Socket);
|
||||
fclose(fd);
|
||||
|
||||
disp('Playback complete.');
|
||||
34
MATLAB/PlaybackExample/Record.m
Normal file
34
MATLAB/PlaybackExample/Record.m
Normal file
@@ -0,0 +1,34 @@
|
||||
%% X-Plane Connect MATLAB Recording Example Script
|
||||
% This script demonstrates how to record data from X-Plane that can later
|
||||
% be played back. (See Playback.m)
|
||||
% Before running this script, ensure that the XPC plugin is installed and
|
||||
% X-Plane is running.
|
||||
%% Import XPC
|
||||
addpath('../')
|
||||
import XPlaneConnect.*
|
||||
|
||||
%% Setup
|
||||
% Create variables and open connection to X-Plane
|
||||
path = 'MyRecording.txt'; % File to save the data in
|
||||
interval = 0.1; % Time between snapshots in seconds
|
||||
duration = 10; % Time to record for in seconds
|
||||
Socket = openUDP(); % Open connection to X-Plane
|
||||
fd = fopen(path, 'w'); % Open file
|
||||
|
||||
disp('X-Plane Connect Recording Example Script');
|
||||
fprintf('Recording to ''%s'' for %f seconds in %fs increments.\n', path, duration, interval);
|
||||
|
||||
%% Start Recording
|
||||
count = floor(duration / interval);
|
||||
for i = 1:count
|
||||
posi = getPOSI(0, Socket);
|
||||
fprintf(fd, '%f, %f, %f, %f, %f, %f, %f\n', ...
|
||||
posi(1), posi(2), posi(3), posi(4), posi(5), posi(6), posi(7));
|
||||
pause(interval);
|
||||
end
|
||||
|
||||
%% Close connection and file
|
||||
closeUDP(Socket);
|
||||
fclose(fd);
|
||||
|
||||
disp('Recording complete.');
|
||||
Reference in New Issue
Block a user