Added Java playback example
This commit is contained in:
32
MATLAB/PlaybackExample/Playback.m
Normal file
32
MATLAB/PlaybackExample/Playback.m
Normal file
@@ -0,0 +1,32 @@
|
||||
%% X-Plane Connect MATLAB Recording 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
|
||||
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 Recording
|
||||
count = floor(duration / interval);
|
||||
for i = 1:count
|
||||
posi = fscanf(fd, '%f, %f, %f, %f, %f, %f, %f\n');
|
||||
sendPOSI(posi);
|
||||
pause(interval);
|
||||
end
|
||||
|
||||
%% Close connection and file
|
||||
closeUDP(Socket);
|
||||
fclose(fd);
|
||||
|
||||
disp('Recording 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();
|
||||
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