This repository contains a complete implementation of a vision-based maze-solving system for the MyCobot Pro 600 robotic arm.
The robot autonomously identifies start and end points in a maze image, determines the optimal path using Breadth-First Search (BFS), converts image coordinates to real-world coordinates, and sends joint commands to the robot via TCP/IP.
The system integrates:
- Computer Vision – detects maze walls, start, and goal points.
- Path Planning – computes the shortest path using BFS.
- Kinematic Control – calculates joint angles via Inverse Kinematics (IK).
- Digital Twin Simulation – verifies trajectories in Simulink before execution.
- TCP Communication – sends movement commands to the MyCobot Pro 600.
| File | Description |
|---|---|
| Main.m | Primary MATLAB script that processes the maze image, finds the path, converts coordinates to world space, and computes joint angles. |
| cobotMazeAngles.m | Modular MATLAB function that encapsulates the entire maze-solving pipeline, including BFS and IK. |
| angle.m | Formats and displays computed joint angles over time for trajectory review. |
| robott.m | Imports and visualizes the robot model using tocheck.urdf. |
| Rigiftreedof.m | Builds a multi-DOF rigidBodyTree structure for simulation. |
| Forward.slx | Simulink model for forward kinematics visualization. |
| inverse.slx | Simulink model for inverse kinematics computation. |
| rigidtree.slx | Simulink digital twin of the robot. |
| tocheck.urdf | URDF defining the MyCobot Pro 600’s geometry and joint configuration. |
| cobot_maze_solver.py | Python interface that runs MATLAB scripts, retrieves joint angles, and sends them as TCP/IP commands to the physical robot. |
- MATLAB R2023a or later
- Image Processing Toolbox
- Robotics System Toolbox
- Simscape Multibody Toolbox
- Python 3.9+
opencv-pythonmatlab.enginesocket,csv
Install Python dependencies:
pip install opencv-pythonRun in MATLAB:
cobotMazeAngles('images/maze7final.jpeg')This will:
- Process the maze image.
- Detect red (start) and green (goal) circles.
- Use BFS to find the optimal path.
- Convert pixel coordinates to world coordinates.
- Generate joint angles via inverse kinematics.
- Save results in
joint_angles.csv.
After MATLAB processing, run in Python:
python cobot_maze_solver.pyThis will:
- Read
joint_angles.csv. - Connect to the MyCobot Pro 600 via TCP/IP.
- Send sequential movement commands for each waypoint.
-
Image Processing
- Threshold maze image and isolate maze area.
- Detect start (red) and goal (green) markers via HSV masking.
- Clean up walls and free space using morphological operations.
-
Path Planning
- Apply BFS to compute the shortest path between markers.
- Interpolate waypoints along the discovered path.
-
Coordinate Mapping
- Convert pixel coordinates → real-world (mm).
- Apply calibration offsets to match the MyCobot workspace.
-
Kinematic Computation
- Build a
rigidBodyTreemodel of the robot. - Use MATLAB’s
inverseKinematicssolver for joint computation. - Validate using forward kinematics (optional Simulink models).
- Build a
-
Execution
- Send joint angles via TCP commands to the MyCobot robot.
- The robot physically traces the maze from start to goal.
- ✅ Maze path detected (red → green).
- ✅ Shortest path visualized with waypoints.
- ✅ Real-world coordinate scatter plot.
- ✅
joint_angles.csvgenerated with six joint angles per waypoint. - ✅ Robot follows the maze autonomously via TCP control.
[pathFound, pathXY] = bfs_maze(BWclean, startPt, endPt);
jointAngles_all = inversee(Wp);BFS Pathfinding:
while ~isempty(queue)
...
if isequal(current, endRC)
found = true; break;
end
endIK Solver:
ik = inverseKinematics('RigidBodyTree', robot);
[configSol, ~] = ik('ee', targetPose, weights, initialGuess);SERVER_IP = "192.168.1.159"
SERVER_PORT = 5001
MESSAGE = "set_angles(-124.6, -54.2, 106.6, -148.1, -92.9, 47.9, 1000)"
send_tcp_packet(SERVER_IP, SERVER_PORT, MESSAGE)This repository is for educational and research purposes.