Skip to content

suyash-web/mycobot-maze-solver

Repository files navigation

MyCobot Pro 600 – Autonomous Maze Solver (MATLAB + Python)

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.


🧠 Overview

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 Structure

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.

⚙️ Requirements

MATLAB

  • MATLAB R2023a or later
  • Image Processing Toolbox
  • Robotics System Toolbox
  • Simscape Multibody Toolbox

Python

  • Python 3.9+
  • opencv-python
  • matlab.engine
  • socket, csv

Install Python dependencies:

pip install opencv-python

🚀 How to Run

1️⃣ MATLAB Path Extraction & Kinematics

Run 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.

2️⃣ Python TCP Control

After MATLAB processing, run in Python:

python cobot_maze_solver.py

This will:

  • Read joint_angles.csv.
  • Connect to the MyCobot Pro 600 via TCP/IP.
  • Send sequential movement commands for each waypoint.

🔢 Algorithm Workflow

  1. 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.
  2. Path Planning

    • Apply BFS to compute the shortest path between markers.
    • Interpolate waypoints along the discovered path.
  3. Coordinate Mapping

    • Convert pixel coordinates → real-world (mm).
    • Apply calibration offsets to match the MyCobot workspace.
  4. Kinematic Computation

    • Build a rigidBodyTree model of the robot.
    • Use MATLAB’s inverseKinematics solver for joint computation.
    • Validate using forward kinematics (optional Simulink models).
  5. Execution

    • Send joint angles via TCP commands to the MyCobot robot.
    • The robot physically traces the maze from start to goal.

🖼️ Example Output

  • ✅ Maze path detected (red → green).
  • ✅ Shortest path visualized with waypoints.
  • ✅ Real-world coordinate scatter plot.
  • joint_angles.csv generated with six joint angles per waypoint.
  • ✅ Robot follows the maze autonomously via TCP control.

🧠 Key MATLAB Functions

[pathFound, pathXY] = bfs_maze(BWclean, startPt, endPt);
jointAngles_all = inversee(Wp);

BFS Pathfinding:

while ~isempty(queue)
    ...
    if isequal(current, endRC)
        found = true; break;
    end
end

IK Solver:

ik = inverseKinematics('RigidBodyTree', robot);
[configSol, ~] = ik('ee', targetPose, weights, initialGuess);

🧩 Communication Example (Python)

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)

📜 License

This repository is for educational and research purposes.


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors