フィルターのクリア

Problem with c code (joystick)

21 ビュー (過去 30 日間)
aysha
aysha 2014 年 1 月 20 日
コメント済み: aysha 2014 年 1 月 23 日
Hi all,
I'm trying to write a c code for s-function in matlab that captures the joystick position but i have the following errors:
posjoystick.c(70) : error C2065: 'prhs' : undeclared identifier
posjoystick.c(70) : error C2109: subscript requires array or pointer type
posjoystick.c(70) : error C2198: 'mxGetScalar' : too few arguments for call
posjoystick.c(101) : error C2065: 'plhs' : undeclared identifier
posjoystick.c(101) : error C2109: subscript requires array or pointer type
posjoystick.c(102) : error C2065: 'plhs' : undeclared identifier
posjoystick.c(102) : error C2109: subscript requires array or pointer type
posjoystick.c(102) : error C2198: 'mxGetPr' : too few arguments for call
posjoystick.c(105) : error C2065: 'plhs' : undeclared identifier
posjoystick.c(105) : error C2109: subscript requires array or pointer type
posjoystick.c(106) : error C2065: 'plhs' : undeclared identifier
posjoystick.c(106) : error C2109: subscript requires array or pointer type
posjoystick.c(106) : error C2198: 'mxGetPr' : too few arguments for call
posjoystick.c(109) : error C2065: 'plhs' : undeclared identifier
posjoystick.c(109) : error C2109: subscript requires array or pointer type
posjoystick.c(110) : error C2065: 'plhs' : undeclared identifier
posjoystick.c(110) : error C2109: subscript requires array or pointer type
posjoystick.c(110) : error C2198: 'mxGetPr' : too few arguments for call
posjoystick.c(113) : error C2065: 'plhs' : undeclared identifier
posjoystick.c(113) : error C2109: subscript requires array or pointer type
posjoystick.c(114) : error C2065: 'plhs' : undeclared identifier
posjoystick.c(114) : error C2109: subscript requires array or pointer type
posjoystick.c(114) : error C2198: 'mxGetPr' : too few arguments for call
C:\Program Files\MATLAB\R2012a\simulink\include\simulink.c(2582) : error C2065: 'mdlCheckParameters' : undeclared identifier
C:\Program Files\MATLAB\R2012a\simulink\include\simulink.c(2582) : warning C4047: '=' : 'mdlCheckParametersFcn' differs in levels of indirection from 'int'
posjoystick.c(136) : fatal error C1070: mismatched #if/#endif pair in file 'c:\users\matlab-pc\desktop\hover\posjoystick.c'
C:\PROGRA~1\MATLAB\R2012A\BIN\MEX.PL: Error: Compile of 'posjoystick.c' failed.
Error using mex (line 206) Unable to complete successfully.
I'm using Matlab R2012a
Here is my code:
#define S_FUNCTION_LEVEL 2
#define S_FUNCTION_NAME posjoystick
#define TIME_SCALE_FACTOR(S) ssGetSFcnParam(S,0)
/* Need to include simstruc.h for the definition of the SimStruct and
* its associated macro definitions. */
#include <simstruc.h>
#if defined(_WIN64) /// google what the win32 define is and add it here
/* Include the windows SDK header for handling time functions. */
#include <windows.h>
#include <math.h>
#define NUM_CHANNELS (2)
/* Function of the high performance counter (in seconds). */
#define NUM_PARAMS (3)
#define INPUT_RANGE_PARAM (ssGetSFcnParam(S,0))
#define INITIAL_OUTPUT_PARAM (ssGetSFcnParam(S,1))
#define SAMPLE_TIME_PARAM (ssGetSFcnParam(S,2))
#define INPUT_RANGE ((real_T*) mxGetPr(INPUT_RANGE_PARAM))
#define INITIAL_OUTPUT ((real_T*) mxGetPr(INITIAL_OUTPUT_PARAM))
#define SAMPLE_TIME ((real_T) mxGetPr(SAMPLE_TIME_PARAM)[0])
#define MDL_CHECK_PARAMETERS /* Change to #undef to remove function */
#if defined(MDL_CHECK_PARAMETERS) && defined(MATLAB_MEX_FILE)
static void mdlInitializeSizes(SimStruct *S)
{
ssSetNumSFcnParams(S, 1); /* Number of expected parameters */
if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) return;
ssSetNumContStates(S, 0);
ssSetNumDiscStates(S, 1);
if (!ssSetNumInputPorts(S, 0)) return;
if (!ssSetNumOutputPorts(S, 1)) return;
ssSetOutputPortWidth(S, 0, 1);
ssSetNumSampleTimes(S, 1);
ssSetNumRWork(S, 1);
ssSetNumIWork(S, 0);
ssSetNumPWork(S, 0);
ssSetNumModes(S, 0);
ssSetNumNonsampledZCs(S, 0);
ssSetOptions(S, 0);
}
#define MDL_INITIALIZE_SAMPLE_TIMES
static void mdlInitializeSampleTimes(SimStruct *S)
{
ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME);
ssSetOffsetTime(S, 0, 0.0);
}
#define MDL_START
static void mdlStart(SimStruct *S)
{
ssSetRWorkValue(S,0,ssGetTStart(S));
}
static void mdlOutputs(SimStruct *S, int_T tid)
{
JOYINFO joy; // Struct into which joystick state is returned.
MMRESULT rc; // Return code of function.
unsigned int cmd;
double* out;
// Get our name for output:
const char* me = mexFunctionName();
/* First argument must be the joystick id: */
cmd = (unsigned int) mxGetScalar(prhs[0]);
/* Call joystick function: */
if ((rc = joyGetPos((UINT) cmd, &joy)) != JOYERR_NOERROR) {
// Failed!
mexPrintf("For failed joystick call with 'joystickId' = %i.\n", cmd);
switch((int) rc) {
case MMSYSERR_NODRIVER:
mexErrMsgTxt("The joystick driver is not present or active on this system! [MMSYSERR_NODRIVER]");
break;
case JOYERR_NOCANDO:
mexErrMsgTxt("Some system service for joystick support is not present or active on this system! [JOYERR_NOCANDO]");
break;
case MMSYSERR_INVALPARAM:
case JOYERR_PARMS:
mexErrMsgTxt("Invalid 'joystickId' passed! [MMSYSERR_INVALPARAM or JOYERR_PARMS]");
break;
case JOYERR_UNPLUGGED:
mexErrMsgTxt("The specified joystick is not connected to the system! [JOYERR_UNPLUGGED]");
break;
default:
mexPrintf("Return code of failed joystick call is %i.\n", rc);
mexErrMsgTxt("Unknown error! See return code above.");
}
}
// Return X pos:
plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL);
*(mxGetPr(plhs[0])) = (double) joy.wXpos;
// Return Y pos:
plhs[1] = mxCreateDoubleMatrix(1, 1, mxREAL);
*(mxGetPr(plhs[1])) = (double) joy.wYpos;
// Return Z pos:
plhs[2] = mxCreateDoubleMatrix(1, 1, mxREAL);
*(mxGetPr(plhs[2])) = (double) joy.wZpos;
// Return 4-element button state vector:
plhs[3] = mxCreateDoubleMatrix(1, 4, mxREAL);
out = mxGetPr(plhs[3]);
out[0] = (joy.wButtons & JOY_BUTTON1) ? 1 : 0;
out[1] = (joy.wButtons & JOY_BUTTON2) ? 1 : 0;
out[2] = (joy.wButtons & JOY_BUTTON3) ? 1 : 0;
out[3] = (joy.wButtons & JOY_BUTTON4) ? 1 : 0;
// Done.
return;
}
static void mdlTerminate(SimStruct *S)
{
UNUSED_ARG(S); /* unused input argument */
}
/* Required S-function trailer */
#ifdef MATLAB_MEX_FILE /* Is this file being compiled as a MEX-file? */
#include "simulink.c" /* MEX-file interface mechanism */
#else
#include "cg_sfun.h" /* Code generation registration function */
#endif

回答 (1 件)

Rajiv Ghosh-Roy
Rajiv Ghosh-Roy 2014 年 1 月 20 日
At first glance, the two lines
#define MDL_CHECK_PARAMETERS /* Change to #undef to remove function */
#if defined(MDL_CHECK_PARAMETERS) && defined(MATLAB_MEX_FILE)
Cause an issue. For the first one, you are telling Simulink coder that you have an mdlCheckParameters function, which you don't. In the second line, you are starting a #if with no matching #endif. Perhaps you should try deleting/commenting both those lines out to see if there is any difference.
  3 件のコメント
Rajiv Ghosh-Roy
Rajiv Ghosh-Roy 2014 年 1 月 21 日
This looks like an application specific error, as this is coming from the Windows API call. Are you sure you are getting the correct id?
aysha
aysha 2014 年 1 月 23 日
Hi How can i make sure that i get the correct id? am using EXTREME 3D PRO joystick.
Thanks a lot.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by