C. elegans behavioral tracking rig
This rig was built for the C. elegans arm of the KCR silencing study, where I needed to record and quantify worm locomotion during optogenetic stimulation. No C. elegans behavioral lab existed locally, and dedicated worm-tracking systems would have been cost-prohibitive, so I built the whole setup from a stereoscope and a camera, designing and 3D-printing the parts that did not exist. This was done in collaboration with the Duke-NUS 3D Printing & Prototyping (3DPP) Lab; credit to Dennis Ong, who brought the fabrication and 3D-printing expertise that made the ideas real.
The base chamber

Figure 1. Base chamber. (A) The chamber components were CNC-milled from acrylic. (B) Each component is cut as a separate piece and held together with embedded magnets, so a single broken part can be swapped out without remaking the whole chamber. (C) The parts assembled together. (D) The finished chamber under infrared illumination, imaged in the dark.
The base chamber holds the worm arena, the agar, and the optics in a fixed, repeatable geometry. Cutting each piece separately and joining them magnetically made the build modular: worn or damaged parts could be replaced individually rather than re-machining the whole assembly.
Sizing the worm arenas
Individual worms were placed in 3.5 × 3.5 mm arenas cut into a 51 mm-diameter transparent acrylic disk, seated on NGM agar in a 60 mm Petri dish. The confined geometry kept worms in frame, physically isolated individuals to prevent crossing or mating (both of which confound tracking), and let me stage several animals at once while imaging them one at a time.

Figure 2. Worm arenas. The recording arenas where individual worms sit. Several worms can be staged in separate grids at once for imaging, though optogenetic experiments were usually run one worm at a time. (A) An early prototype fitting the chamber cut-out to a 96-well plate; this failed because the wells were too deep to reliably deposit a worm. (B) Different grid sizes and layouts were tested. (C) The size chosen as best suited to C. elegans. (D) The final arena schematic.
Fixing the camera to the stereoscope

Figure 3. Camera adapter. The custom C-mount adapter that fixes the camera to the stereomicroscope, designed with the 3DPP Lab (credit: Dennis Ong) and 3D-printed. (Left) the part modeled in Onshape; (right) the printed adapter fitted to the stereoscope.
Images were acquired at 29 FPS with a FLIR Grasshopper3 near-infrared camera on an Optika stereomicroscope at 1.5× magnification. We needed to fix the camera to the microscope securely, so I designed a custom C-mount adapter and had it 3D-printed. The rigid mount eliminated camera displacement during recording.
The assembled rig
The whole setup sat inside a temperature-controlled incubator. Constant 850 nm infrared LEDs lit the arena for recording without activating the opsins. Optogenetic stimulation used green (530 nm) and blue (460 nm) LEDs on heatsinks. Each 30 fps recording ran 10 s of darkness → 10 s of green stimulation → 40 s of darkness, the final window capturing the kinetics of locomotor recovery.

Figure 4. The assembled rig. Camera, C-mount adapter, stereomicroscope, worm arena, and the infrared and optogenetic illumination, brought together.
Tracking with DeepLabCut
Because the low-contrast stereoscope video defeated the classical trackers I tested, I trained a custom DeepLabCut model on our own footage. Videos were down-sampled to 512 × 512 px (a worm spans roughly 17 × 80 px); 10 key points were hand-labeled head-to-tail across 280 frames from 14 videos, and a ResNet-50 network was trained for over 500,000 iterations. A custom Python package (Celegans_tracking) then converts the key-point coordinates into baseline-normalized worm speed, with effect sizes reported via the DABEST estimation framework.
Video 1. Before and after tracking. The same worm shown raw (left) and with the DeepLabCut pose overlay (right). Recordings were made at 30 fps using the Spinnaker SDK application.
See the science this rig was built for → the KCR silencing study.