This kit builds a Simulink S-function named sfunc_haptics that connects to a Novint Falcon haptic device.
haptics.cpp / haptics.h: HDAL-style haptics wrapper (position out, force in)sfunc_haptics.cpp: Simulink S-function interface (Legacy Code Tool)- Simulink example models from the original course zip (PD controller, etc.)
- A Win64 build script:
build_sfunc_haptics_win64.m
The original course materials used Novint's HDAL SDK directly. On modern Windows 11 + 64-bit MATLAB, the easiest reliable approach is:
- Build/install libnifalcon (open-source Falcon driver) and the HDAL compatibility layer libnifalcon_hdal
- Compile the existing HDAL-style wrapper and S-function into mexw64
- Run the provided Simulink models (fixed-step discrete)
Reference:
- libnifalcon repo (mentions bundled firmware requirement): https://github.com/libnifalcon/libnifalcon
- libnifalcon_hdal repo (HDAL compatibility layer): https://github.com/libnifalcon/libnifalcon_hdal
- MATLAB supported compilers list: https://www.mathworks.com/support/requirements/supported-compilers.html
If your lab already has a genuine 64-bit HDAL SDK with x64
hdl.lib, you can link against that instead. Otherwise, use the compatibility layer.
Install these once per machine:
- MATLAB R2022b or newer (64-bit)
- Visual Studio 2022 (or Build Tools) with Desktop development with C++
- CMake (and make sure it’s on PATH)
- Git
In MATLAB:
mex -setup C++Choose the Visual Studio 2022 compiler MATLAB finds.
Open “x64 Native Tools Command Prompt for VS 2022” (or a Developer PowerShell).
Choose a working folder, e.g. C:\dev\falcon, then run:
mkdir C:\dev\falcon
cd C:\dev\falcon
git clone https://github.com/libnifalcon/libnifalcon.git
git clone https://github.com/libnifalcon/libnifalcon_hdal.gitmkdir build-libnifalcon
cd build-libnifalcon
cmake ..\libnifalcon -A x64 -DCMAKE_INSTALL_PREFIX=C:\dev\falcon\install
cmake --build . --config Release
cmake --install . --config Releasecd C:\dev\falcon
mkdir build-hdal
cd build-hdal
cmake ..\libnifalcon_hdal -A x64 -DCMAKE_INSTALL_PREFIX=C:\dev\falcon\install -DCMAKE_PREFIX_PATH=C:\dev\falcon\install
cmake --build . --config Release
cmake --install . --config ReleaseAfter install, you should have:
C:\dev\falcon\install\include\...C:\dev\falcon\install\lib\...(look forhdl.liborlibhdl.lib)
libnifalcon requires firmware files shipped in its source distribution (see firmware/). If utilities cannot find/load firmware, copy the firmware folder somewhere predictable and ensure your setup follows libnifalcon’s guidance.
In this kit, create a folder named EXTERNAL next to the MATLAB script:
EXTERNAL\include→ copy (or point to)C:\dev\falcon\install\includeEXTERNAL\lib→ copy (or point to)C:\dev\falcon\install\lib
Simplest for students:
# from the kit folder
mkdir EXTERNAL
mkdir EXTERNAL\include
mkdir EXTERNAL\lib
xcopy /E /I C:\dev\falcon\install\include EXTERNAL\include
xcopy /E /I C:\dev\falcon\install\lib EXTERNAL\lib(Alternatively edit the two paths inside build_sfunc_haptics_win64.m.)
From MATLAB, cd into the kit folder and run:
run build_sfunc_haptics_win64.mExpected output file:
sfunc_haptics.mexw64
If compilation fails with cannot open file 'hdl.lib':
- check
EXTERNAL\libfor the actual library name - update
def.HostLibFiles/def.TargetLibFilesin the MATLAB script to match (e.g.,libhdl.lib)
Open one of the provided models, e.g.:
hapticsSimBlk_pd.mdl(PD control demo)
Recommended Simulink settings (haptics stability):
- Solver: Fixed-step
- Type: Discrete (no continuous states)
- Fixed-step size:
0.001(1 ms)
- Unplug/replug the Falcon
- Try a different USB port (avoid unpowered hubs)
- Confirm Windows sees the device in Device Manager
- Ensure any required USB driver stack is installed (varies by Falcon hardware revisions)
- Re-run:
mex -setup C++
- Ensure Visual Studio 2022 C++ workload is installed
- You may be missing runtime DLLs from your build/install. Ensure the
binoutput from your install (if any DLLs) is on PATH, or place required DLLs next to the mex.
The wrapper applies workspace scaling and a transform matrix in haptics.cpp. For teaching labs, it can be useful to:
- log raw position
- verify sign conventions per axis
- apply simple gain scaling in Simulink first
Send students:
- This single ZIP kit
- The build instructions above
- Optionally, a prebuilt
EXTERNALfolder for your lab image to avoid per-student library installs