PTB3 & Linux
Working with the Psychtoolbox (Psychophysics Toolbox) for MATLAB, you will frequently deal with code that supposedly only runs on OSX systems. The main reason for this is that older PTB versions lack OpenGL support (and a lot of other functions) on OS9, Windows and Linux. Obvious side effect: if you are a neurobiologist who just wants to design his stimuli you will not care about these problems and just buy a Mac, and as soon as you start coding you will care even less about other operating systems.
Recently, I received four MATLAB programs and I really need these stimuli to run. However, I do not have a Mac. In fact, the next one I could use is located in Tübingen, so this is not an option. So let’s just try this on my Linux box here.
First we need Octave. I decided against MATLAB since I don’t like the way it integrates into your OS. Furthermore, I am not eligible for the free student licenses any longer. The PTB3 needs an x86 environment (Octave/MATLAB) and a SubVersion (SVN) client.
sudo apt-get install octave subversion openssh-server
// change to desired directory
wget http:// [look this up youself :)] /DownloadPsychtoolbox.m
octave
octave:1> DownloadPsychotoolbox(‘/path/to/your/directory’)
Installing the SSH server is optional; we will use it later to shut down PTB Screens if our MATLAB code crashes. The last command installs PTB3. Type
in order to close Octave. In future, start octave with
PTB will then be able to set process priorities for exact timing.
Incompatibilities & Workarounds
Now, you should have a look at the source code you want to run. In the following, I will list the most common problems you might face and the respective workarounds:
Paths
Stimuli written in MATLAB tend to have hard coded paths, adapt them to your needs.
if IsOSX
Some programmers will use this to prevent undefined states of their programs. You can remove this or replace IsOSX with true.
PsychHID(…)
You will probably see code using this function. This is a real problem because PsychHID is not implemented on Windows, OS9 and Linux. In most cases people will use this to capture keyboard input. In this case it is safe to rewrite
to
where your keyboard ID is most likely 0. Other PsychHID calls will probably try to find connected keyboards, you can comment out this code and adapt subsequent references. The remaining PsychHID functionality is too dependant on your code, but it should be possible to adapt it.
All CAPS
I am not entirely sure, but MATLAB on OSX seems to be case insensitive. The code I have received uses both Screen(…) and SCREEN(…). The latter will not work with Octave, just change all occurrences to Screen(…)
commandwindow
Since we’re using Octave, we do not have this function, and we don’t need it.
Reasons
So why are those programs OSX-dependant in the first place? The answer is OpenGL. Looking at the comments in the code that I have, I found the statement “So far, the OS X Psychtoolbox is the only OpenGL-base Psychtoolbox“. So either the script is old or the author is not aware of recent PTB developments. Anyways, he assumed that the script will stop at the AssertOpenGL statement if not being executed on OSX.
Closing dead “Screen”s
Sometimes your code will crash leaving PTB Screens open. Windows users usually do CTRL+ALT+DEL and stop the MATLAB process. Linux users will find their current X-session blocked or hidden behind the PTB Screen. If you have another computer, mobile phone or [insert device that runs UNIX derivates or PuTTY here] simply establish an SSH connection and kill the Octave process.
ps x | grep octave
kill [octave PID]
If you have started Octave with sudo, you will need to use sudo to display and kill the process (sudo ps … and sudo kill …).
You can also switch to the console by pressing CTRL+ALT+F1. Use your username and password to log-in and kill the Octave process as described above. Log-out by typing “exit” and return to your X-session: CTRL+ALT+F7.
What about x64?
Long story short: grab a copy of the current Ubuntu x86 release, free up some HDD space and install it.
If your thoughts now include “(s)chroot“, “debootstrap” and something like “apt-get install ubuntu-minimal” you should stop right here. PTB3 will need a running X-server. However, forwarding X over ssh or TCP will not work for PTB3 which is rather low level. Starting another X-server in your chrooted environment? Good luck, you have an x64 kernel running and you try to start a x86 X-server*. You can obviously continue and install a 32bit kernel and boot it… oh wait, this is a second Linux on your computer -> download Ubuntu and use the normal install routine (some people have to learn the hard way :))
* this might not be the real reason and it simply does not work on my system.