Open bluetulip89 opened 6 years ago
but during the build the file is created in the respective paths (inside include folder) but still getting the error.
Can you paste your example_create_sfunctions.m
file? Also paste the text this file prints on the command prompt when you run it.
here is the sequence once it is run
example_create_sfunctions
* Running create_sfun_encode for E:\mavlink_s\include\mavlink\v1.0\common\mavlink_msg_heartbeat.h: Creating Simulink bus from message... done Bus is saved in buses/bus_mavlink_heartbeat_t.mat Creating the s-function header file... done Header file is saved in include/sfun_mavlink_msg_heartbeat.h ** Creating the output file sfun_encode_msg_heartbeat.cpp ... done Compiling the s-function... Building with 'MinGW64 Compiler (C++)'. MEX completed successfully. S-function source and compiled files are in the folder 'sfunctions'
* Running create_sfun_encode for E:\mavlink_s\include\mavlink\v1.0\common\mavlink_msg_attitude.h: Creating Simulink bus from message... done Bus is saved in buses/bus_mavlink_attitude_t.mat Creating the s-function header file... done Header file is saved in include/sfun_mavlink_msg_attitude.h ** Creating the output file sfun_encode_msg_attitude.cpp ... done Compiling the s-function... Building with 'MinGW64 Compiler (C++)'. MEX completed successfully. S-function source and compiled files are in the folder 'sfunctions'
* Running create_sfun_encode for E:\mavlink_s\include\mavlink\v1.0\common\mavlink_msg_raw_imu.h: Creating Simulink bus from message... done Bus is saved in buses/bus_mavlink_raw_imu_t.mat Creating the s-function header file... done Header file is saved in include/sfun_mavlink_msg_raw_imu.h ** Creating the output file sfun_encode_msg_raw_imu.cpp ... done Compiling the s-function... Building with 'MinGW64 Compiler (C++)'. MEX completed successfully. S-function source and compiled files are in the folder 'sfunctions'
* Running create_sfun_decode: Creating Simulink bus from message... done Bus is saved in buses/bus_mavlink_heartbeat_t.mat Creating the s-function header file... done Header file is saved in include/sfun_mavlink_msg_heartbeat.h Creating Simulink bus from message... done Bus is saved in buses/bus_mavlink_attitude_t.mat Creating the s-function header file... done Header file is saved in include/sfun_mavlink_msg_attitude.h Creating Simulink bus from message... done Bus is saved in buses/bus_mavlink_raw_imu_t.mat Creating the s-function header file... done Header file is saved in include/sfun_mavlink_msg_raw_imu.h ** Creating s-function header file... done Creating the output file sfun_decode_mavlink.cpp ... done Compiling the s-function... Building with 'MinGW64 Compiler (C++)'. Error using mex In file included from E:\mavlink_s\sfun_decode_mavlink.cpp:18:0: E:\mavlink_s\include/sfun_decode_mavlink.h:7:48: fatal error: include/sfun_mavlink_msg_heartbeat.h: No such file or directory
^
compilation terminated.
Error in create_sfun_decode (line 212) eval(['mex ' output_filename '.cpp']);
Error in example_create_sfunctions (line 35) create_sfun_decode(filenames);
Even if we add manually the path along with file and sub-folders / if we give addpath(genpath(cd)) or
p = genpath(cd) addpath(p)
its throwing same error
Just make sure there is no file called sfun_decode_mavlink.cpp
before you run the Matlab script, and then please paste the sfun_decode_mavlink.cpp
file being created by the script. This is the file that is not compiling, so we have to see. Also, let me know if this file is created in your root folder (and not examples folder).
Same error comes even when sfun_decode_mavlink.cpp is deleted before run.
sfun_decode_mavlink.cpp content generated during build
/ DO NOT EDIT. This file was automatically created by the Matlab function 'create_sfun_decode' on 21-Nov-2017 18:18:01 as part of Simulink MAVLink library. /
// System and Component IDs for MAVLink communication
/* Function: mdlInitializeSizes ================================================
block's characteristics (number of inputs, outputs, states, etc.). / static void mdlInitializeSizes(SimStruct S) {
DECL_AND_INIT_DIMSINFO(inputDimsInfo); DECL_AND_INIT_DIMSINFO(outputDimsInfo);
ssSetNumSFcnParams(S, 0); if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { return; / Parameter mismatch will be reported by Simulink / }
if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortDirectFeedThrough(S, 0, 1); ssSetInputPortRequiredContiguous(S, 0, 1); ssSetInputPortDataType(S, 0, SS_UINT8); ssSetInputPortVectorDimension(S, 0, MAVLINK_MAX_PACKET_LEN);
if (!ssSetNumOutputPorts(S, 3)) return;
if (ssGetSimMode(S) != SS_SIMMODE_SIZES_CALL_ONLY) { DTypeId dataTypeIdReg0; ssRegisterTypeFromNamedObject(S, BUS_NAME_HEARTBEAT, &dataTypeIdReg0); if (dataTypeIdReg0 == INVALID_DTYPE_ID) return; ssSetOutputPortDataType(S, 0, dataTypeIdReg0);
DTypeId dataTypeIdReg1;
ssRegisterTypeFromNamedObject(S, BUS_NAME_ATTITUDE, &dataTypeIdReg1);
if (dataTypeIdReg1 == INVALID_DTYPE_ID) return;
ssSetOutputPortDataType(S, 1, dataTypeIdReg1);
DTypeId dataTypeIdReg2;
ssRegisterTypeFromNamedObject(S, BUS_NAME_RAW_IMU, &dataTypeIdReg2);
if (dataTypeIdReg2 == INVALID_DTYPE_ID) return;
ssSetOutputPortDataType(S, 2, dataTypeIdReg2);
}
ssSetBusOutputObjectName(S, 0, (void ) BUS_NAME_HEARTBEAT); ssSetBusOutputObjectName(S, 1, (void ) BUS_NAME_ATTITUDE); ssSetBusOutputObjectName(S, 2, (void *) BUS_NAME_RAW_IMU);
ssSetOutputPortWidth(S, 0, 1); ssSetOutputPortWidth(S, 1, 1); ssSetOutputPortWidth(S, 2, 1);
ssSetBusOutputAsStruct(S, 0, 1); ssSetBusOutputAsStruct(S, 1, 1); ssSetBusOutputAsStruct(S, 2, 1);
ssSetOutputPortBusMode(S, 0, SL_BUS_MODE); ssSetOutputPortBusMode(S, 1, SL_BUS_MODE); ssSetOutputPortBusMode(S, 2, SL_BUS_MODE);
ssSetNumSampleTimes(S, 1);
/ specify the sim state compliance to be same as a built-in block / ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE);
ssSetOptions(S, 0); / general options (SS_OPTION_xx) /
} / end mdlInitializeSizes /
/* Function: mdlInitializeSampleTimes ==========================================
} / end mdlInitializeSampleTimes /
/* Function: mdlStart ==========================================================
to do it. */
static void mdlStart(SimStruct S) { int_T busInfo = (int_T ) malloc(2NFIELDS_OUTPUT_BUS*sizeof(int_T)); if(busInfo == NULL) { ssSetErrorStatus(S, "Memory allocation failure"); return; }
encode_businfo_heartbeat(S, busInfo, OFFSET_HEARTBEAT); encode_businfo_attitude(S, busInfo, OFFSET_ATTITUDE); encode_businfo_raw_imu(S, busInfo, OFFSET_RAW_IMU);
ssSetUserData(S, busInfo); } / end mdlStart /
/* Function: mdlOutputs ========================================================
block. / static void mdlOutputs(SimStruct S, int_T tid) {
int_T len_uvec = ssGetInputPortWidth(S, 0); const uint8_T uvec = (uint8_T) ssGetInputPortSignal(S, 0);
mavlink_message_t msg; mavlink_status_t status;
for (int uidx = 0; uidx < len_uvec; uidx++) { if(mavlink_parse_char(MAVLINK_COMM_0, uvec[uidx], &msg, &status)) { decode_mavlink_msg(S, &msg); } }
}
/* Function: mdlTerminate ======================================================
/=============================
This is a curious error, which I am not getting, nor have any of the other users (I know of at least 3 other people who have used this function). If you look at the error, it is saying that the file "include/sfun_mavlink_msg_heartbeat.h"
does not exist, even though that file was correctly used during the compilation of sfun_encode_msg_heartbeat
. Even the other include file, include/sfun_decode_mavlink.h
is included correctly.
I don't know if this is a compiler specific message, which is resolving the relative paths differently from MS Visual C++ compiler (but highly unlikely). As a different approach, I can suggest you this:
After the file sfun_decode_mavlink.cpp
is created, go to the file include/sfun_decode_mavlink.h
, and manually copy-paste the content from sfun_mavlink_msg_heartbeat.h
, sfun_mavlink_msg_attitude.h
, and sfun_mavlink_msg_raw_imu.h
where it includes these files (so that instead of including the files, you are just pasting their contents). Then compile the s-function.
Hi, I installed the minGW compiler and found that I was also getting this same issue. As I suspected, it is because of how the compiler deals with relative paths. Check this: http://www.mingw.org/wiki/includepathhowto
Specifically, the following sentence:
path must be a relative path, and it must be relative to the directory in which the file containing the pertinent #include directive is itself located.
I have fixed the issue. You can update your repo, it should work now.
Closing this issue.
Have updated the repo and now i am getting the following error. Any Idea to get rid of the following error.
example_create_sfunctions
* Running create_sfun_encode for C:\Simulation\simulink_mavlink\include\mavlink\v1.0\common\mavlink_msg_heartbeat.h: Creating Simulink bus from message... Error using fgets Invalid file identifier. Use fopen to generate a valid file identifier.
Error in fgetl (line 33) [tline,lt] = fgets(fid);
Error in create_bus_from_mavlink_header (line 16) lin = fgetl(fid);
Error in create_sfun_header (line 27) [simulink_bus, simulink_bus_name] = create_bus_from_mavlink_header(filename);
Error in create_sfun_encode (line 29) mavlink_msg_name = create_sfun_header(filename);
Error in example_create_sfunctions (line 26) create_sfun_encode(filenames{i});
I think you have to update the file names to your computer path. "C:\Simulation\simulink_mavlink" is my path, which I used in the example. Change it to your relevant path.
Oh ok will change and let you know.
In file included from E:\mavlink_s\sfun_decode_mavlink.cpp:18:0: E:\mavlink_s\include/sfun_decode_mavlink.h:7:48: fatal error: include/sfun_mavlink_msg_heartbeat.h: No such file or directory
include "include/sfun_mavlink_msg_heartbeat.h"
compilation terminated.