Simulink toolkit to control haptic device works occasionally, otherwise crashes (fatalException)

32 views (last 30 days)
I'm trying to control a haptic device (Phantom Desktop, Geomagic Inc./SensAble) through Simulink. I am using PhanTorque, a Simulink Toolkit written for this purpose. It uses C/C++ S-functions and OpenHaptics libraries to set up the interface between the haptic device and Simulink. Compiling the toolkit does not give any errors (but see below). I am using MATLAB R2018a on Windows 10.
The problem: a basic Simulink model included in the package for testing purposes (Test_PhanTorque_3Dof__Library.mdl) works only occasionally.
Initially the model usually does work for a few runs. This is after having calibrated the device in an external program and having just starting Matlab/Simulink. After a number of runs it starts giving the following error.
Error in 'Test_PhanTorque_3Dof_Library/PhanTorque_3Dof_vels' while executing C MEX S-function 'PhanTorque_3Dof_vels', (mdlStart), at time 0.0.
Caused by:
FatalException
At the same time, the MathWorks Crash Reporter pops up, saying Matlab has encountered an internal problem and needs to close. Also see the crash report attached here. When I am patient enough and click 'Attempt to continue' and try running the model again, sometimes, after any number of identical crashes, the model all of a sudden runs without any errors.
When I run the Simulink Model Advisor in order to check the S-functions in the model, a crash might also occur (but then again, sometimes it does not). The crash report reports two Fails in PhanTorque_3Dof_vels:
  • S-function MEX-file check (ModelCompileError): identical to the error listed above.
  • Source Code Check (MEX Compile Check):
PhanTorque_3Dof_vels.c
C:\Users\heuvelm\Documents\MATLAB\Phan_Torque_3Dof
Library_64Bits\PhanTorque_3Dof_vels.c(37): fatal error
C1083: Datei (Include) kann nicht ge"ffnet werden:
"HD/hd.h": No such file or directory
("Datei (Include) kann nicht ge"ffnet werden" is German for "cannot open include file"). This error clearly points to a directory in the OpenHaptics libraries, so I am guessing something is going on during compilation? I really have little to no experience here.
This is what I have used to compile:
mex -lHD -L"C:\Users\heuvelm\Documents\MATLAB\OpenHaptics\Developer\3.4.0\lib\x64\Release" 'PhanTorque_3Dof_vels.c' -I'C:\Users\heuvelm\Documents\MATLAB\OpenHaptics\Developer\3.4.0\include\' -I'C:\Users\heuvelm\Documents\MATLAB\OpenHaptics\Developer\3.4.0\utilities\include\'
Building with 'MinGW64 Compiler (C)'.
MEX completed successfully.
When inserting other blocks from this library similar (but slightly different) MEX compile check errors are reported, e.g.
C:\Users\heuvelm\Documents\MATLAB\PhanTorque_3Dof_Library_64Bits\PhanTorque_3Dof.c:37:19: fatal error: HD/hd.h: No such file or directory
The error in the Matlab command window suggests to examine the source code for errors, but I wouldn't know where to start.
I would be grateful for any kind of troubleshooting you could offer.
  2 Comments
Wonsup Lee
Wonsup Lee on 23 Oct 2020
Edited: Wonsup Lee on 23 Oct 2020
In PhanTorque_6Dof.c, it is mentioned that the HD/hd.h file is components of OpenHaptics library
/*Open haptics libreries */
#include <HD/hd.h>
#include <HD/hdScheduler.h>
#include <HDU/hduError.h>
#include <HDU/hduVector.h>
You might get OpenHaptics from 3D Systems website (e.g., https://support.3dsystems.com/s/article/OpenHaptics-for-Windows-Developer-Edition-v35?language=en_US; note that this link is for OpenHaptics 3.5). After you install OpenHaptics, you will get HD/hd.h and more necessary files from C:\OpenHaptics\Developer\3.5.0\include\HD folder. Therefore, the problem can be solved by copying the HD folder in PhanTorque folder.
Also, library files (e.g., hd.lib, hdu.lib) under the OpenHaptics folder (e.g., C:\OpenHaptics\Developer\3.5.0\lib\x64\Release for hd.lib; C:\OpenHaptics\Developer\3.5.0\utilities\lib\x64\Release for hdu.lib) also need to be copied in PhanTorque folder (or create library folder under PhanTorque).
Then, need to modify mex function to include the HD folder
mex -I"HD/" -L"library/" -lhd -lhdu PhanTorque_6Dof_damp_vels.c
note) need to mention the correct name of the file in the line, for example, PhanTorque_6Dof_damp_vels.c
If the C code generate errors, that should be corrected in the C file.
Zhenyu
Zhenyu on 13 Oct 2023
I am running the similar program. I have included and linked header and lib files and there are no errors like "HD/hd.h: No such file or directory". Unfortunately the problem has not been solved. The model still works occasionally. When it doesn't work, it shows the following error.
Error in 'Test_PhanTorque_3Dof__Library/PhanTorque_3Dof' while executing C MEX S-function 'PhanTorque_3Dof', (mdlStart), at time 0.0.
Caused by:
  • FatalException
I would be grateful for any suggestion.

Sign in to comment.

Answers (1)

wang
wang on 9 Sep 2019
Hello, I have the same problem as you. Have you solved it now?

Community Treasure Hunt

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

Start Hunting!