Skip to content

ethan-soon/NovintFalcon

Repository files navigation

Novint Falcon → Simulink (Windows 11 + MATLAB R2022b+ / win64) Student Kit

This kit builds a Simulink S-function named sfunc_haptics that connects to a Novint Falcon haptic device.

What you get

  • 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

Big picture (important)

The original course materials used Novint's HDAL SDK directly. On modern Windows 11 + 64-bit MATLAB, the easiest reliable approach is:

  1. Build/install libnifalcon (open-source Falcon driver) and the HDAL compatibility layer libnifalcon_hdal
  2. Compile the existing HDAL-style wrapper and S-function into mexw64
  3. Run the provided Simulink models (fixed-step discrete)

Reference:

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.


Prerequisites (Windows 11)

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

MATLAB compiler setup

In MATLAB:

mex -setup C++

Choose the Visual Studio 2022 compiler MATLAB finds.


Step 1 — Build & install libnifalcon + libnifalcon_hdal (HDAL compat)

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.git

Build libnifalcon

mkdir build-libnifalcon
cd build-libnifalcon

cmake ..\libnifalcon -A x64 -DCMAKE_INSTALL_PREFIX=C:\dev\falcon\install
cmake --build . --config Release
cmake --install . --config Release

Build libnifalcon_hdal

cd 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 Release

After install, you should have:

  • C:\dev\falcon\install\include\...
  • C:\dev\falcon\install\lib\... (look for hdl.lib or libhdl.lib)

Firmware note (common gotcha)

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.


Step 2 — Point this kit at your installed include/lib folders

In this kit, create a folder named EXTERNAL next to the MATLAB script:

  • EXTERNAL\include → copy (or point to) C:\dev\falcon\install\include
  • EXTERNAL\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.)


Step 3 — Build the Simulink S-function (mexw64)

From MATLAB, cd into the kit folder and run:

run build_sfunc_haptics_win64.m

Expected output file:

  • sfunc_haptics.mexw64

If compilation fails with cannot open file 'hdl.lib':

  • check EXTERNAL\lib for the actual library name
  • update def.HostLibFiles / def.TargetLibFiles in the MATLAB script to match (e.g., libhdl.lib)

Step 4 — Run the Simulink examples

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)

Troubleshooting

Device not detected

  • 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)

mex cannot find a compiler

  • Re-run:
    mex -setup C++
  • Ensure Visual Studio 2022 C++ workload is installed

mex builds but Simulink errors loading mex

  • You may be missing runtime DLLs from your build/install. Ensure the bin output from your install (if any DLLs) is on PATH, or place required DLLs next to the mex.

Force directions / scaling feel “wrong”

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

Instructor notes (what to forward)

Send students:

  • This single ZIP kit
  • The build instructions above
  • Optionally, a prebuilt EXTERNAL folder for your lab image to avoid per-student library installs

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors