An automated bearing inspection rig: a stepper-motor stage rotates a ball bearing in front of a Basler industrial vision camera, the operator GUI drives the capture cycle, and a labelled pattern-recognition layer processes the resulting images.
Originally built over 2023 and 2024 as a six-month industrial engineering internship deliverable. Published here in white-label form: the branding, captured data, and operational logs have been removed, and the system architecture and code are intact.
- The operator launches the Tkinter GUI, names a new bearing inspection run, and configures the capture parameters.
- The motor controller (
CamMotor3.py) communicates with a TMC stepper driver over a serial link, configures the driver into StealthChop mode for quiet, low-vibration operation, and rotates the bearing stage through a configurable sequence of angular positions. - At each position the GUI triggers the Basler camera via the
pypylonlibrary and stores the resulting frame in a per-run directory underBearings/. - After capture,
labelledPAN.pyruns the labelled pattern-analysis pipeline over the captured frames and writes results back to the GUI. - Every action (GUI events, motor commands, camera triggers, errors) is timestamped and written to
logs.txtso the operator can reconstruct a run.
The end result is an unattended capture cycle for a bearing that previously required manual operator intervention at each rotation step.
+----------------------+
| GUI.py (Tkinter) |
| - run configuration |
| - capture pipeline |
| - threaded workers |
| - log display |
+----------+-----------+
|
| imports
v
+----------+-----------+ +-----------------------+
| CamMotor3.py | | labelledPAN.py |
| - serial protocol | | - frame post-process |
| - TMC stepper driver | | - labelled pattern |
| (StealthChop mode) | | analysis |
| - Basler camera | +-----------+-----------+
| capture (pypylon) | |
+----------+-----------+ |
| |
v v
Serial / USB to stage Per-run image directory
+ Basler camera over USB (./Bearings/<run>/)
All file paths (logs, asset directory, per-run bearing storage) are computed relative to the script location, so the project can be relocated wherever the operator needs it.
bearing-analyzer/
├── CamMotor3.py # Motor + camera control (~180 LOC)
├── GUI.py # Tkinter operator interface (~800 LOC)
├── labelledPAN.py # Labelled pattern analysis pipeline (~400 LOC)
├── Assets/
│ ├── Program_BG.jpg # GUI background (generic bearing render)
│ ├── Run_icon.png # Button icon
│ └── Logo.png # (optional) drop your own 250x129 logo here
├── requirements.txt
├── LICENSE
└── README.md
A Bearings/ directory is created at first run for captured-frame storage. logs.txt is generated by the GUI.
The code was developed against:
- Basler USB3 industrial camera with the official
pypylonSDK - Trinamic TMC-series stepper driver speaking the standard TMCL serial protocol (the protocol bytes are written explicitly in
CamMotor3.py, no driver library) - A custom mechanical stage with 3D-printed fixtures to mount the bearing under inspection
If you swap any of these, expect CamMotor3.py to be the file that changes most.
pip install -r requirements.txt
python GUI.pyYou will need:
- A Basler camera connected and visible to the Pylon Viewer (
pypylonbuilds on the Pylon SDK). - A serial port reachable by
pyserialwith a TMC stepper driver on the other end. The default serial parameters live near the top ofCamMotor3.py. - (Optional) Drop a
Logo.pngintoAssets/if you want the GUI's top-right corner to show one; otherwise it falls back to a blank canvas.
- The original company logo in
Assets/. Replaced with an optionalLogo.pngfallback. - The
Bearings/directory of captured frames from real operation. Empty. logs.txtwith operational timestamps. Will regenerate on first run.__pycache__/Python bytecode artifacts.- The
Bearing Analyzer (2).zipbackup snapshot.
The 800-line Tkinter GUI, the 180-line motor / camera controller, and the 400-line analysis pipeline are unchanged from the original (apart from the single line that loaded the company logo).
MIT. See LICENSE.
Hashem Touqan · LinkedIn · github.com/HTouqan