Vision-Guided SCARA Pick-and-Place Robot (4 DoF)
Firmware & electronics lead — 4-DOF SCARA with YOLOv11n vision (mAP 0.72), kinematics & PID in MATLAB/Simulink, 5/6 picks at ~14 s/cycle, custom Altium PCB
5 out of 6 pieces picked and placed correctly in the final demonstration, at approximately 14 seconds per cycle. The robot classifies pieces by shape and colour with a YOLOv11n model (mAP@0.5 = 0.72) running on my own computer, then picks and places them autonomously — coordinates flow from Python over MQTT to C++ firmware on an ESP32.
Design at a glance




Design decisions, from first principles
| Decision | Engineering reasoning | Result |
|---|---|---|
| All joint axes vertical | Decouples the problem: planar position from shoulder and elbow, height from the Z stage; inverse kinematics in closed form with the law of cosines | Forward kinematics mean error 4.0 mm, inverse 6.9 mm |
| L1 = 150 mm, L2 = 110 mm | Annular workspace from |L1−L2| to L1+L2 covers the 25 cm task radius | Reachable area 50–250 mm from the base |
| Steppers on J1/J2, absolute encoder on the wrist, limit-switch homing | Steppers give position without feedback, so accuracy depends on a correct home reference | Homing identified as the main error source |
| YOLOv11n on top of the HSV pipeline | HSV thresholds shift with lighting; a trained detector is more robust | mAP@0.5 = 0.72; 5 of 6 parts sorted, ~14 s/cycle |
Full technical write-up
Challenge
Identify, pick and place flat pieces that differ in shape, colour and orientation inside a 25 cm-radius workspace, and sort each one into its designated area without human intervention. The pieces come in five shapes (square, circle, triangle, cross, pentagon) and four colours. The arm has two revolute joints driven by NEMA 17 steppers (shoulder and elbow), a lead-screw vertical stage driven by a DC motor with encoder, a wrist closed around an AS5600 absolute encoder and a servo gripper, built in PETG with aluminium bars. Design and Development of Robots, Tec de Monterrey, team of four.
My contribution
- Computer vision: the classical OpenCV pipeline (edge detection, HSV segmentation, shape classification, grip angle) and its integration with the robot over MQTT
- Pixel-to-robot coordinates: the ArUco homography that converts image pixels into robot millimetres
- Machine learning: the YOLOv11n workflow: automatic pre-annotation, dataset split, training and evaluation
- PCB design: the single-layer control board in Altium Designer (ESP32, stepper and DC drivers, encoders, power distribution)
- Kinematics & control: my own forward and inverse kinematics in MATLAB (each member derived them individually) and PID joint control in Simulink; with the team, Simulink and Simscape Multibody models of the gantry robot
- With the team: breadboard prototype, motor and driver selection, and the homing sensors — the Z-axis limit switch and the AS5600 on the wrist, validated against known reference angles; the MQTT link between the vision host, the broker and the ESP32; co-author of the robot datasheet
Teammates built the C++ kinematics and firmware architecture on the ESP32, the MATLAB App Designer HMI, the final Simscape model of the SCARA and the mechanical structure.
Computer vision
A smartphone mounted 500 mm above the workspace, optical axis vertical, streams to the PC; a script captures one frame at 1280 × 720 px. Four ArUco markers at known corners of a 562 × 562 mm area define a homography from image pixels to robot millimetres.


The classical pipeline builds an edge map (Gaussian blur, Laplacian, Otsu), segments each colour in HSV (red needs two hue ranges because hue wraps around) and splits touching pieces with a watershed. Shapes are classified by solidity, convexity deficit and circularity: the cross is caught first because it is the only non-convex piece, and the others are decided by a vote of approxPolyDP at three tolerances. The grip angle comes from the minimum-area rectangle, adjusted to each shape’s symmetry so the wrist turns as little as possible, and every piece is published over MQTT as shape, colour, x, y, angle.


Because HSV thresholds are sensitive to lighting and to close colours, I trained a YOLOv11n detector on images of the real workspace (16 classes, 80/20 split, 50 epochs). The classical pipeline pre-annotated every image, so labelling took about 30 minutes instead of 3–4 hours. The model reached mAP@0.5 = 0.72; the weakest classes were the crosses, which had only 62–94 examples against 1,580 for the blue square — the class imbalance, not the model, is the main limit.



Kinematics & mechanism
All four joint axes are vertical, so the problem splits cleanly: the planar position depends only on the shoulder and elbow, the height only on the vertical stage, and the tool angle is the sum of the three rotations. Forward kinematics chain four Denavit–Hartenberg transforms; inverse kinematics use the law of cosines for the two-link arm (L1 = 150 mm, L2 = 110 mm), give an elbow-up and an elbow-down solution and keep the one closest to the current pose. A target is reachable only between 50 and 250 mm from the base.


Before the SCARA, the team modelled other manipulators to study motion and control. For a gantry with a 1-DOF arm we derived the equations of motion with Euler–Lagrange and built the model twice — from the equations in Simulink and in Simscape Multibody — with PID loops for the cart position and the arm angle. Both agreed on the overall behaviour, including the small jiggle at the end of each move caused by the coupling between cart and arm.




Electronics & PCB
The control board integrates the ESP32, two DRV8825 drivers for the steppers, a TB6612FNG for the DC motors, the encoder and sensor connectors and the power distribution. Single-layer was a manufacturing constraint, so placement and routing were planned to avoid crossings, and polygon pours carry power and ground to reduce the voltage drop between drivers and supply. The board was completed but not integrated: in the last weeks the team prioritised debugging mechanics, control and vision, and the demo ran from the breadboard electronics.



HMI & integration
The vision host, the ESP32 and the HMI never talk directly: they publish and subscribe through a Mosquitto broker, so each part can run on a different machine — during tests the robot was even operated from another city. In pick-and-place mode the ESP32 solves the inverse kinematics, approaches 30 mm above the piece, descends, grips, lifts and places it.

Tools & technologies
- Python, OpenCV, YOLOv11n, LabelImg: vision pipeline, homography, dataset tooling
- ESP32 (C++, ESP-IDF, PlatformIO, FreeRTOS): firmware; MQTT over Wi-Fi with a Mosquitto broker
- Altium Designer: single-layer control board
- MATLAB, Simulink, Simscape Multibody: kinematics, PID joint control, multibody simulation
Results & lessons
- Pick-and-place: 5 of 6 pieces placed correctly, about 14 s per cycle
- Accuracy: forward kinematics mean error 4.0 mm (calipers, 3 poses); inverse kinematics 6.9 mm mean, 8.6 mm max (5 targets); vision localisation about 15 mm
- Robust link: control restored about 2 s after a Wi-Fi drop
- Homing dominates accuracy: the steppers have no position feedback, so every session depended on a correct home reference; belt backlash and printed couplings were the main mechanical error sources
- Vision-to-gripper offset: most failed picks came from the offset between the estimated piece centre and the real gripper centre; better lens calibration is the next fix
- Small validation set: six attempts are an indication, not a measured success rate
- Next steps: more images for the under-represented classes, integrate the PCB and close the loop on the stepper joints
Stack: Python, OpenCV, NumPy, Ultralytics YOLOv11n, LabelImg · ESP32, C++ (ESP-IDF, PlatformIO), FreeRTOS · MQTT (Mosquitto), I²C · Altium Designer · MATLAB, Simulink, Simscape Multibody