Add support for the KPC101 K-Cube Piezo Strain Gauge controller - #157
Open
MahsaHabibi wants to merge 9 commits into
Open
MahsaHabibi wants to merge 9 commits into
MahsaHabibi wants to merge 9 commits into
Conversation
The KPC101 integrates the piezo controller and strain gauge reader in a single KCube with one serial number, replacing device pairs like KPZ101+KSG101. MIC predates this device, so no KPC_ mex wrappers existed. - Add 8 Kinesis_KPC_* mex sources in mex_source/MIC/ wrapping the Thorlabs.MotionControl.KCube.PiezoStrainGauge C API, following the existing Kinesis_KCube_* wrapper pattern - Add buildKPCMex.m to compile them into mex64/ - Add mic.linearstage.KCubePiezoStrainGauge class: closed-loop positioning in microns via built-in strain gauge feedback, with device-reported max travel and automatic zeroing on construction Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Built with MATLAB R2025b and Microsoft Visual C++ 2022 against Kinesis Thorlabs.MotionControl.KCube.PiezoStrainGauge.lib. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The Kinesis_KPC_* mex files load Thorlabs.MotionControl.KCube.PiezoStrainGauge.dll at runtime; MIC keeps the Thorlabs runtime DLLs in mex64/ since Kinesis is not on the system PATH. DeviceManager.dll is updated from 1.14.10 to 1.14.59 to match the PiezoStrainGauge.dll version (both from the current Kinesis install). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The device DLLs and DeviceManager.dll must come from the same Kinesis release: mixing the new PiezoStrainGauge.dll (1.14.59) with the old DeviceManager (1.14.10) failed to load, and updating only DeviceManager made the old device DLLs fail with a missing-procedure load error. All DLLs are now copied from the same Kinesis install. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
On hardware, KPC_GetMaximumTravel returned 0 when called right after opening the device. Move the travel readout to after the strain gauge zeroing routine and retry up to 5 times, since the underlying request is asynchronous. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
KPC101 firmware returns 0 from KPC_GetMaximumTravel even after zeroing and retries, so the device cannot be relied on to report its travel. MaxPosition is now an optional constructor argument (default 20 um) that must match the Maximum Travel configured in Kinesis; the device query only overrides it (with a warning) if it returns a conflicting nonzero value. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The GenerateDocumentation workflow could never pass on pull requests: PR runs check out a detached HEAD, so its git push step always exits 128. Guard the commit-and-push step to run only on push events; on PRs the workflow now just validates that genDoc runs. Also commit the genDoc-generated Readme.md for the new KCubePiezoStrainGauge class, matching the other class folders. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Covers TPZ001+TSG001 (X), KPZ101+KSG101 (Y) and KPC101 (Z): position sweeps with strain gauge readback, repeatability, small step response, combined 3D moves and state export. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds MIC support for the Thorlabs KPC101, which integrates the piezo driver and strain gauge reader into a single K-Cube with a single serial number. MIC predates this device: the existing mex wrappers only cover the split-device architecture (KPZ101/TPZ001 driver + KSG101/TSG001 gauge,
PCC_/SG_C APIs), so classes likemic.linearstage.KCubePiezoandmic.stage3D.NanoMaxPiezoscannot drive it. This PR adds wrappers for theKPC_C API (Thorlabs.MotionControl.KCube.PiezoStrainGauge) and a new linear stage class, following the existing MIC patterns throughout.New files
Mex wrappers (
mex_source/MIC/Kinesis_KPC_*/mexFunction.cpp+ compiledmex64/*.mexw64)Kinesis_KPC_OpenKinesis_KPC_CloseKinesis_KPC_SetPositionKinesis_KPC_GetPositionKinesis_KPC_SetPositionControlModeKinesis_KPC_SetZeroKinesis_KPC_GetStatusBitsKinesis_KPC_GetMaximumTravelBuild script (
mex_source/MIC/buildKPCMex.m)Compiles all eight wrappers against the Kinesis import library into
mex64/. Requires a configured C++ compiler (mex -setup C++) and Kinesis atC:\Program Files\Thorlabs\Kinesis.Class (
src/+mic/+linearstage/@KCubePiezoStrainGauge/KCubePiezoStrainGauge.m)mic.linearstage.KCubePiezoStrainGaugeextendsmic.linearstage.abstract. On construction it opens the device, sets closed loop, runs the zeroing routine (~30 s, waits on status bits), and centers the stage. Positions are in microns; the class converts to/from the API's percentage-of-travel WORD internally. Because the device reports true position through its built-in strain gauge, no Slope/Offset calibration is needed (unlikeKCubePiezo).MaxPositionis an optional third argument (default 20 um) and must match the Maximum Travel configured in Kinesis — KPC101 firmware was observed to return 0 fromKPC_GetMaximumTraveleven after zeroing, so the device query is best-effort only.Runtime DLLs (
mex64/)Adds
Thorlabs.MotionControl.KCube.PiezoStrainGauge.dlland updates all existing Thorlabs DLLs inmex64/from 1.14.10/1.14.11 to 1.14.59. The device DLLs andDeviceManager.dllare mutually version-locked: mixing releases fails at load time with missing-module/missing-procedure errors, so they must all come from the same Kinesis release.Testing
Verified on hardware (KPC101 S/N 113251934, NanoMax 300 Z axis, 20 um travel, MATLAB R2025b, MSVC 2022):
Known limitation (shared with the other Kinesis mex classes): re-opening the device in the same MATLAB session can crash MATLAB; construct the object once per session.
Notes for reviewers
🤖 Generated with Claude Code