Data acquisition from USB Joystick - MAC OS

2 Ansichten (letzte 30 Tage)
Marco
Marco am 5 Aug. 2014
Kommentiert: Marco am 6 Aug. 2014
Hi.
For the project I am working on, I am trying to read in the 3-axis xyz values, as well as throttle and buttons, form my joystick. My problem is that I do not know how to persuade MatLab to do that.
I've seen that some out there published some self-made tools, comprising a mex file, to get that done. That might well work on WIndows but I have a Mac os. And that does not work on macs.
So I have a USB 4 axis joystick. I know that my comp can successfully interface with the external hardware (tried it when running google earth's flight sim, piloting trough ystick- pretty awesome!)
How can I explain matlab to read instantaneous values from the joystick, connected at my USB slot?
Than you so much. Marco
  2 Kommentare
Christopher Berry
Christopher Berry am 5 Aug. 2014
Why do you say that using mex files wont work on a Mac?
Marco
Marco am 6 Aug. 2014
My knowledge of mex files is nearly zero, so there migh be something wrong in my original statement. However, I see that when trying to compile the *.c file, some windows related stuff is called in.
What follows is the *.c file:
// // mat_joy.c // MATLAB Interface for Joysticks // Author: Stanislaw Adaszewski, 2012 //
#include mex.h #define WIN32_LEAN_AND_MEAN #define WINVER 0x0500 #include windows.h #include mmsystem.h
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { int joyId; JOYINFO joyInfo; mwSize sizePos[] = {3,1}; mwSize sizeBut[] = {16,1}; double *pos; double *but; int i;
if (nlhs != 2 || nrhs != 1 || mxIsEmpty(prhs[0]) || mxGetNumberOfElements(prhs[0]) != 1 || (joyId = (int) mxGetPr(prhs[0])[0]) < 0 || joyId > 15) {
mexErrMsgTxt("Usage: [position, buttons] = mat_job(joystick_id), where:\n\njoystick_id - joystick identifier (0-15),\nposition - list of joystick position in X, Y and Z axis,\nbuttons - list of 16 joystick button states (missing buttons are always zeros)");
}
joyGetPos(joyId, &joyInfo);
plhs[0] = mxCreateNumericArray(2, sizePos, mxDOUBLE_CLASS, mxREAL);
plhs[1] = mxCreateNumericArray(2, sizeBut, mxDOUBLE_CLASS, mxREAL);
pos = mxGetPr(plhs[0]);
but = mxGetPr(plhs[1]);
pos[0] = ((double) joyInfo.wXpos - 32767) / 32767;
pos[1] = ((double) joyInfo.wYpos - 32767) / 32767;
pos[2] = ((double) joyInfo.wZpos - 32767) / 32767;
for(i = 0; i < 16; i++) {
but[i] = (joyInfo.wButtons >> i) & 1;
}
}

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu C Shared Library Integration finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by