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.

Final project presentation: testing the gripper's grip, demonstrating joint control through the HMI and by sending commands directly to the MQTT broker, and explaining how the real-time vision system works.

Design at a glance

CAD model (4 DoF)
CAD model (4 DoF)
Reachable workspace 50–250 mm
Reachable workspace 50–250 mm
Control PCB, 3D view (Altium)
Control PCB, 3D view (Altium)
Shape/colour detection
Shape/colour detection

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.

Overhead camera setup
Overhead camera 500 mm above the workspace, with the ArUco markers at the corners.
ArUco markers detected for the homography
ArUco detection: the marker centroids (red) define the pixel-to-millimetre homography.

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.

Classified shapes on the workspace
Final detection: each piece labelled with its ID, shape and colour.
Grip angles overlaid on the workspace
Grip angles computed for each piece, using its symmetry to minimise wrist travel.

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.

Training image of the workspace
Training image captured on the real workspace, with pieces in varied positions, orientations and colours.
YOLOv11n loss and mAP curves
Training and validation losses and mAP over 50 epochs.
Normalised confusion matrix
Normalised confusion matrix: green pieces are recognised best, crosses worst.

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.

CAD model of the SCARA robot
CAD model of the robot.
Reachable workspace
Top view of the reachable workspace (250 mm radius).
Simscape Multibody model of the SCARA, built from the CAD geometry, with PID control of the two planar joints (final version by a teammate).

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.

Gantry robot simulation (team coursework).
Industrial arm simulation (team coursework).
Simulink block diagram of the gantry robot model
Simulink model of the gantry: the nonlinear state equations in a MATLAB Function block, two PID loops (x and θ) and scopes, with step references (left) and sinusoidal references (right).
Top-level Simscape model with the gantry and arm subsystems
Top level of the Simscape model: the gantry subsystem (rail, cart and arm) and the robot arm subsystem, each driven by a motion reference and logged to scopes.
Simscape Multibody connection diagram for the gantry robot
Simscape Multibody connection diagram: the gantry and arm subsystems, the motion references, and the same PID loops as the analytical model for comparison.
Simscape outputs: angle, angular velocity, torque and control signal
Simscape outputs: arm angle θ against its reference, angular velocity, output torque and PID control signal. The control signal overshoots at the start of each step and then settles.

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.

Control board schematic
Schematic: ESP32, stepper drivers, DC motor driver and connectors.
Single-layer PCB layout
Single-layer layout with power polygon pours.
3D view of the PCB
3D view of the board.

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.

HMI teach pendant
HMI teach pendant (built by a teammate).
Gripper picking up a blue square.
Shoulder joint rotating via MQTT command during early integration — arm links not yet attached.
Z-axis movement test during sensor integration — limit switch and encoder triggering validated at this stage.
Bench session with HMI SCARA interface visible: joint jog commands sent over MQTT from MATLAB to the ESP32.

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