A MEX function that returns joystick axes and buttons. It should be reasonably portable since it's based on SDL which runs on Mac, Linux, Win.
>> [j,b] = joystick
0 0 -0.0039 0.0039
0 0 0 0 0 0 0 0 0 0 0 0
Could be wrapped into an S-function.
Simulink comes with similar functionality if you have the 3D Animation Toolbox.
Tested on R2012b MacOS 10.8.2 (ML) with SDL 1.2.15.
I was trying to compile this on OSX El Capitan, Matlab R2015b, Xcode 7.2.1 and SDL2, but I had some errors. Matlab was using "Xcode with Clang" for compilation.
I fixed the issue as follows:
1) I changed the following lines
2) I changed the compile command to
mex -v joystick/joystick.c LINKLIBS='\$LINKLIBS -framework SDL2'
How do you use it with the 'mex' function in MATLAB command line?
It does not compile on 64 architecture, Mac
Thank you for your promptness of your response.
I'm using Matlab 7.6 - R2008a and Windows 32-bit. I did download the SDL libraries (https://www.libsdl.org/download-1.2.php).
The error messages are:
>> mex joystick.c
Error C:\Users\myPC\Desktop\Joystick\joystick.c: C:\Users\myPC\Desktop\Joystick\SDL_endian.h: 171 compiler error in _kids--Bad rule number 0
C:\PROGRA~1\MATLAB\R2008A\BIN\MEX.PL: Error: Compile of 'joystick.c' failed.
??? Error using ==> mex at 207
Unable to complete successfully.
I think my problem is the MEX compiler. I tried to use Lcc-win32 compiler (C:\PROGRA~1\MATLAB\R2008a\sys\lcc\bin).
Anyway, I already have got access to the joystick inputs. I'll use the vrjoystick functions (Virtual Reality Toolbox).
Bruno, could you share some details of the error messages.
I was unable to compile this file.
Tried on Linux
1) need to replace // with /*
2) variable event not defined
Fixed bug described by Christie, also includes release of dynamically allocated memory.
The // comment problem can be fixed by specifying the C99 compiler, but is probably platform/compiler specific.
Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.