How to store any sensor's last 1 second's values ​​in workspace as a vector (Real Time mode)?

2 ビュー (過去 30 日間)
Hey
e.g.
joy = vrjoystick(1);
x = axis(joy, 1); % This just gives me current value of x-axis of the joystick
But I need a vector which gives me values of 'x' in latest 1 second.
Why I need this? Because one of my matlabscript.m demands values of 'x' in latest 1 second. Not just the current value of x-axis of the joystick.
% So i think there should be something always running in background of Matlab, which can give me recent values of 'x'%.
Thanks
  6 件のコメント
Walter Roberson
Walter Roberson 2018 年 7 月 2 日
axis() is a method of the vrjoystick class

サインインしてコメントする。

採用された回答

Adam Danz
Adam Danz 2018 年 7 月 2 日
編集済み: Adam Danz 2018 年 7 月 2 日
What's the sampling rate? In your plot, I assume the y axis is angular velocity while the x axis is an index of samples such that x=60 is the 60th sample. If you're sampling at 200Hz that's a sample per 5ms so x=60 is 300ms; if you're sampling at 60Hz, x=60 is 1000ms.
I assume the variable 's' is a vector whose length continually grows. Say your sampling rate is 200Hz, all you need is the last 200 samples of 's' to isolate the last 1-second of data. Within your while loop, that would be ...
sampleRate = 200 %hz
while ...
lastSecond = s(end-sampleRate+1 : end);
end
Variable 'lastSecond' will always contain the most recent (hense last) second of data. However you'll likely run into memory problems if you allow s to grow to enormous lengths.
If you're interested in collecting only the last second of data continuously and tossing any data prior to 1 second,
sampleRate = 200 %hz
s = zeros(1, sampleRate);
while ...
d = 25*axis(joy, 1);
s(1) = []; %get rid of oldest value
s(sampleRate) = d; %add newest value
end
Of course none of this is tested because I don't have a cool steering wheel interface.
  3 件のコメント
JAI PRAKASH
JAI PRAKASH 2018 年 7 月 2 日
@ Adam Danz Thanks for your effort & Time.
But my interest is doing all this in a parallel i.e. in background. Please read last two lines of my initial question.
please refer this ongoing question.. How can I run 2 tasks in parallel?
Adam Danz
Adam Danz 2018 年 7 月 3 日
If you create a timer object, which was mentioned in this thread and the thread in your link, you'll still need code that continually collects the most recent 1-second of joystick data and the code offered here should help you with that.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by