Code covered by the BSD License  

Be the first to rate this file! 11 Downloads (last 30 days) File Size: 2.28 KB File ID: #41041

Joystick MEX file

by

 

01 Apr 2013 (Updated )

Portable joystick MEX file using SDL

| Watch this File

File Information
Description

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

j =

         0 0 -0.0039 0.0039

b =

     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.

Required Products MATLAB
MATLAB release MATLAB 8.0 (R2012b)
Other requirements Needs SDL (Simple DirectMedia Layer) library 1.2.15
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (6)
27 Jun 2014 Mohamed Abdelkader

How do you use it with the 'mex' function in MATLAB command line?
Thanks.

21 May 2014 Mohamed Abdelkader

It does not compile on 64 architecture, Mac

31 Mar 2014 Bruno Dias

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).

Thanks.

31 Mar 2014 Peter Corke

Bruno, could you share some details of the error messages.

30 Mar 2014 Bruno Dias

I was unable to compile this file.

01 Apr 2013 christie harper

Tried on Linux
1) need to replace // with /*
2) variable event not defined

Updates
03 Apr 2013

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.

Contact us