2016年8月28日日曜日

Oculus and VR player setting notes

ヘッドマウントディスプレイを買ったはいいけれど,なにかコンテンツがない場合には宝の持ち腐れですよね。私も,実験に使おうと勝手は見たものの,全く使わずに放置でした。とりあえずヘッドマウントディスプレイ(Oculus DK2)を使用して動画を見る方法は確立したので,メモします。他のヘッドマウントでも簡単に見られると思います。

360度動画(画像),およびヘッドマウントに対応しているMovie playerは色々あるようですが,一番使い勝手が良かったのは,VR Playerです。

同様の機能を持つものに,GoPro VR Playerがあります。これは,昔Koler Eyesっていう名前でしたが,いつのまにか変わっていました。ちなみにこっちは,私の環境ではすぐに設定できなかったのでポイっとしました。

[ How to use VR Player ]
インストールしたら,ドラッグ&ドロップで動画を再生できます。
Install a VR player into your computer and drag&drop a movie file onto it.

設定項目は,上のツールバーにあります。細かいものは,「Tools→Settings」へ。
基本的な 「Media」「Device」のみをいじります。

RICHO Thetaなどで撮影した360度動画をHMDで見たい場合 
If you want to watch 360° movie using a head mounted display.

Media 
-- Format: Mono
-- Projection: Sphere
-- Effects: None

Device 
-- Layout: Side by side
-- Distortion: Barrel (None)
-- Tracker: Oculus Rift DK2 (Choose own device's name)

Mediaが入力側,Deviceが出力側の設定だと考えれば簡単です。
Media and Device are for input and output settings respectively.

もし動画が既に両眼用(左右に動画が二つ並んでいる)になっている場合には,
If your movie file is dual one,

Media 
-- Format: Side by side
としてください。

HMDを使わずにPCでみたい場合には,
If using PC display,

Media 
-- Format: Mono
-- Projection: Sphere
-- Effects: None

Device 
-- Layout: Mono
-- Distortion: None
-- Tracker: Mouse (None)

とするといいでしょう。
マウスは一回クリックすると,操作モードになり,もう一度クリックすると戻ります。


【Amazon リンク】



   Oculus Rift 製品版       Galaxy Gear VR(スマホ入れるタイプ。安い)

とりあえず安く体験してみたい方は1000円でハコスコが売っているので,買ったらいいと思います。

動画を撮影する方も,RICHO Thetaを皮切りに,どんどん出ています(iPhoneに付けるのも売ってますね)ので,自分でコンテンツ作るのも非常に楽になってきています。





RICHOTHETAです。新しいモデルは綺麗だし,使いやすくなっていいですね。

2016年6月23日木曜日

MATLAB and LeapMotion



A very convenient motion tracker for hand, LeapMotion.
手のトラッキングに便利なリーププモーションを紹介。


Now, you can buy it only 6200 yen by Amazon. If you get 3D position data from LeapMotion using MATLAB, download Matleap.
ホント安いですね。Kinectもですが…量産とは恐ろしい。 MATLABで位置情報を取得したい時には,以下からmatleapをダウンロードします。

Download https://github.com/jeffsp/matleap

You can easily understand the initial settings by reading Read me file, and have to install Leapmotion SDK first. Matleap contains sample m file to get position data.
Read me読めば,最初のセッティングについてとりあえずわかります。簡単です。 LeapMotionに関しては,SDKをダウンロードして下さいね。 サンプルコードも付いてくるので,あんまり困ることはないです。


LeapMotion ifself always get position data as long as it capture a hand. MATLAB fetches the data from matleap_frame function.
LeapMotion自体はマウスのように,手がある限りずっとデータを取得しています。そこから,MATLABがmatleap_frame関数でデータをとってきます。

matleap_frame.m : read position data from LeapMotion


f = matleap_frame;
% an example of data contents
% f =
%             id: 354491
%      timestamp: 2.1655e+10
%     pointables: [1x5 struct]
%          hands: [1x1 struct]

Position data of fingertips are  f.pointables.position.
指先の一データはf.pointables.positionです。以下のような感じで取り出します。

point_num = length(f.pointables);
if (~isempty(point_num))&&(point_num>0)
    for i=1:point_num
        nowpos(i,:) = f.pointables(i).position;
    end
end

As default, matleap cannot get data other than fingertips, but it seems that you can get other data by changing codes by yourself.
デフォルトでは指先の位置データしか取得できませんが,コード書き換えればその他も可能なようです。
https://community.leapmotion.com/t/matleap-only-has-pointable-information/470/4

2016年1月5日火曜日

Ubuntu 15.4 + Psychtoolbox 3 on DELL Inspiron

Failed!

First, I installed Ubuntu 14LTS version onto a DELL Laptop, but WiFi controller couldn't work (driver  for Intel AC3165 is not provided). Then I installed Ubuntu 15.4, which can recognize well the network controller. 

MATLAB installation was very easy and did not meet any troubles. To install Psychtoolbox, I used NeuroDebian. After some configuration settings, I tried to install matlab-psychtoolbox-3, but the terminal said matlab-psychtoolbox-3-nonfree is required. Then I put it, it needs libglew1.9. I checked about libglew1.9, it cannot be installed on Ubuntu 15.4!

Therefore, if you want to install Psychtoolbox3 on Ubuntu, you need Ubuntu 14 LTS with a compatible WiFi controller. Or, you need to put a driver somehow. A USB WiFi network controller may be a solution..

2015年11月12日木曜日

Installing MATLAB Psychtoolbox on Windows 10

PC spec
Dell Inspiron 13 7000 (2-in-1)
Windows 10 Home 64bit
Core i3-6100U

It was the first time to use a Windows 10 PC for me. So I can't tell what causes this slow processing.... Anyway, I successfully installed Psychtoolbox onto Windows 10 PC with MATLAB 2014b after some struggles.

First I downloaded and installed MATLAB 2015a and Psychtoolbox, but MATLAB crashed when I called Screen function. Then I installed 2014b instead of 2015a, and MATLAB told me to install Gstreamer, which is a familiar comment for me. After installing Gstreamer, the screen function worked. I don't know the reason of the crash first I met.

** P.S.
Psychtoolbox 3 with MATLAB 2015a woked on Windows 10 PC.

2015年11月9日月曜日

MATLAB Connection using UDP (TCP/IP)

時間ないので,暫定版メモ。
今度修正します。
Pscyhtoolboxのpnetという関数を使用します。

UDP Port 5000に接続,タイムアウトを0.5秒,パケット送信がなくなると終了。

@MATLAB

sock = pnet('udpsocket',5000);
pnet(sock,'setreadtimeout',0.5)
dataP = 1;

try
    while dataP~=0
        dataI = pnet(sock,'read');
        disp(dataI);
        dataP = pnet(sock,'readpacket');
    end
catch
    disp('Closed_ERROR')
end

pnet(sock,'close')


おわり。

これで,UDPポートを使ってデータを取得するソフトから,MATLABにリアルタイムにデータを取り込むことができます。

2015年10月5日月曜日

Wait signals and proceed

双方向で通信してる時にはこういうのって必要になることありますよね。
シリアル通信における待ちプログラムについて,MATLABとArduinoの両方で書いてみます。
Sometimes you needs to wait until certain signals come in serial communication. Here I'll describe it in Arduino and MATLAB codes.

一番簡単なのは,こうです。
The simplest one would be

@Arduino

Serial.begin(115200);
while (Serial.available() == 0) {
      delay(1);
}

// CODE //

@MATLAB

s = serial('COM1');
set(s,'BaudRate',115200);
fopen(s);
while (s.BytesAvailable==0)
      WaitSecs(0.001);
end

%% CODE %%

fclose(s);

2つのコードはほぼ同じであることが分かると思います。あとは,特定の文字が入力された時のみ次のステップに進むとかもありますね,書き方はたくさんありますが,例えばこうしてみます。
You can see the two codes are essentially the same. In another case, you have to proceed a program only after a particular character is input. You can write like this for example.

@Arduino

byte WaitingFlag = 1;
while (WaitingFlag == 1) {
    while (Serial.available() == 0) {
      delay(1);
    }
    int str = Serial.read();
    if (str == 'R') {
      WaitingFlag = 0;
    }
}

@MATLAB

WaitingFlag = 1;
while (WaitingFlag)
   while (s.BytesAvailable==0)
        WaitSecs(0.001);
   end
   if strmatch(fgets(s),'R')
        WaitingFlag = 0;
   end
end

どちらも,WaitingFlagが1の間はwhile文を繰り返します。ただし,その中にもう一つwhile文がありますので,何か信号が入ってくるまではここから出れません。出たと思ったら,if文によってそれが目的の文字かどうかが照合され,マッチしていたらWaitingFlagを変更して,while文を抜ける,というロジックになってます。
In both programs, the while sentence is repeated as long as Waitingflag = 1. However, before that, an additional while sentence loops until some signals come to the port. After signals come and processing exits from the while loop, the if sentence judges whether the character is expected one or not. If it is not, you cannot exit from the loop. lol







2015年9月20日日曜日

Arduino: Pointer

ポインタというものがC言語(Arduino)では出てくる。これに関して分かりやすく説明しているページが見つけられなくてとってもこまった。
I couldn't find good explanations for a pointer function in C language on the Web and wasted my time.

今回行いたいのは,作成した関数から複数の戻り値(数値の配列)を得ること。MATLABだと超簡単なんだけど,C言語では基本的にはできないらしい。そこで使用するものが,ポインタというもの,らしい。
This time, I want to get an array of values as the return value of a function. In MATLAB it is very easy to write but C does not allow such a program. Instead, "pointer" enables us to achieve  almost the same thing.

結局,以下のように書いたら上手くいきました。MATLABでいうと,
In MATLAB, to get an array of values as the return value, you write

function main
pointer = testFunc;
disp(pointer)

function pointer = testFunc
for i = 1:6
   pointer(i)=i;
end

これで得られる配列を得るためには,Cだとこんな感じになる。
but in C, you write something like that.

void setup() {
  Serial.begin(115200);
}

void loop() {
  int pointer[] = {0, 0, 0, 0, 0, 0}; //(1)
  // the size of pointer is 6

  // Fucntion
  testFunc(pointer); //(2)

  // print on a serial monitor
  for (byte i = 0; i < 5; i++) {
    Serial.print(pointer[i]);
    Serial.print(',');
  }
  Serial.write(10); // new line character
  delay(1000);
}

void testFunc(int *a) { //(3)
  // put pointer as an argument
  for(byte i = 0; i<5; i++) {//(4)
    *a = i;
    ++a;  
    // the pointer proceeds from 0 to 5.
    // this maybe the same that a[0]=i ... a[5]=i.
  }
  
  // no "return", but the pointer is updated.
}


あまり説明が見つからなかったこともあり,ポインタについての理解は足りませんが,実用的な使い方としての解説をしてみます。


(1) int pointer[] = {0, 0, 0, 0, 0, 0};

で,ポインターと呼ばれるものをつくります。これは,ポインターとか言わずに,とりあえず欲しい配列入れるための変数を宣言すると考えましょう。今回はテストとして0を入れてますが,pointer[6];として,サイズだけ決めてもいいのかもしれません。
this made a pointer, and it is better to regard as just a variable which will contain an array of values. This time I write {0,0,0,0,0,0} but it maybe OK to state int pointer[6].


(2) testFunc(pointer); 

戻り値は書いてませんが,ポインターが勝手に更新されてくれるのでOKです。
this doesn't include the return value, but it's OK because the pointer gets the return value.

(3) void testFunc(int *a) {

引数を「*a」としているのがポインターとして使うというしるしです。きっと。
The asterisk maybe the sign to use an argument as a pointer. 

(4)for(byte i = 0; i<5; i++) {
     *a = i;
      ++a; 
   }

for文の中で,何やらポインターの数を増やしつつ,ポインターに値を代入しています。これがどういう仕組みかはわかりませんが,MATLABでいうと,for i=1:6; a(i)=x; end と一緒ということでしょう。もちろん,厳密な意味は違うのでしょうが,表層的にはこれでいいかと。
In the for loop, the value of the pointer increases and at the same time i is substituted for the pointer valuable. This may mean that for i=1:6; a(i)=x; end in the MATLAB language at least superficially.

とりあえず,これさえ理解できれば,戻り値に配列を設定するのは実装できるかな,と思います。根本的な間違いがあれば教えて下さい。