กลับไปหน้ารวมไฟล์
rubiks-cube-solver-robot-6233e2-en.md

The drivers to develop my project were:

  • Rubik´s cube is a "best seller" category toy, more than 350 millions of units
  • Time to solve by humans has been decreasing from 22 seconds in 1982 to 3.47 second in 2018
  • Brilliant mathematicians as Kociemba, Rokiki and Fridrich has been fascinated with the toy - at adult age!!!
  • There are people solving cubes blindfolded - 48 cubes in less than one hour
  • Opencv and Python are subject I wanted to know, so I choose this challenge
  • I need a pandemic project to maintain soul balance and my mind working in new knowledge as a mechanism to use the spare time

Conceptualization:

I took the Matt2uy design and optimize the image recognition and algorithm to solve by implementing the Herbert kociemba algorithm.

Process of development

It was an instinctive and observation process of the mechanics -assay and error - 4 models I built until found the more accurate and with more repeatibility featuring.

The idea was to built knowledge based on existent knowledge, so Instructables, youtube, github were very important knowledge's sources.

Results

Implementing some changes I got to save about 20-24 minutes solving the cube - Average time is 6 to 8 minutes to solve.

If you are looking for speed solving, please see my other project, this is more about strategies to solve a problem, learning and patient.

This video summarize, as integrated view, what I did:

Rubik´s cube solver Robot - 6-8 mins to solve

Process:

Cube images are captured by a python program module, then color extraction for each sticker is proceesed by other program module and finally the cube is solved by Kociemba algorithm, the solution is sent to Arduino trough a serial port. Once the solution is received the arduino code start to processing the movements, after 6-8 minutes the process finish and the robot show all the faces of the cube solved.

Algorithmic Kinematics: The Python and Arduino Pipeline

A human solving a Rubik's Cube relies on physical pattern recognition. To make a machine do exactly this involves astronomical mathematical complexity uniting high-level optical engineering, the Kociemba algorithmic solving matrix, and terrifyingly synchronized mechanics! The Rubik's Cube Solver Robot acts as a unified master-slave architecture! A PC or Raspberry Pi captures exactly 54 color-square states via an intensive WebCam array, mathematically generates an optimized 20-move solution string (e.g., U2 R' F B'), and aggressively fires that entire Serial payload into an Arduino Uno slave! The Uno violently decodes the string and whips an intricate matrix of 4 to 6 high-torque Stepper/Servo motors completely solving the cube physically in literal seconds!

The Python OpenCV Visual Analysis Pipeline

Before any motor spins, the robot must perfectly memorize the scrambled state.

  1. The robot arms meticulously rotate the cube, presenting all 6 faces to a fixed USB Camera.
  2. OpenCV (Python) aggressively scans the image, generating 9 distinct Regions of Interest (ROI) per face.
  3. The incredibly volatile RGB values are translated natively into HSV (Hue, Saturation, Value) to precisely evaluate "Orange" even under terrible bedroom lighting conditions!
  4. It compiles a massive string of colors: "UUUURRRRRFFFDDD..." and shoots it completely into a heavy-weight external Kociemba Python library to physically calculate the mathematical solve path instantaneously!

Orchestrating The Stepper Motor Array (Arduino Code)

Parsing the solution string "R2 L' F" requires the Arduino to map exact mechanical maneuvers utilizing the <AccelStepper.h> framework!

  • R2 means the Right face must violently spin 180 Degrees exactly.
  • L' means the Left face must aggressively spin 90 Degrees Counter-Clockwise!
void executeMove(String currentMove) {
  if (currentMove == "R") {
    // 90 Degree turn clockwise on Stepper Right! (Assume 200 steps/rev)
    stepperR.moveTo(stepperR.currentPosition() + 50); 
    while (stepperR.distanceToGo() != 0) {
      stepperR.run(); // Fast non-blocking acceleration sweep!
    }
  } 
  else if (currentMove == "R'") {
    // 90 Degree turn counter-clockwise!
    stepperR.moveTo(stepperR.currentPosition() - 50); 
    while (stepperR.distanceToGo() != 0) { stepperR.run(); }
  }
}

Physical Solving Infrastructure Architecture

  • Arduino Mega 2560 (An Uno simply does not pack the massive RAM and Digital IO pins required to concurrently handle 4 to 6 massive A4988 Stepper Motor Driver chips synchronously!).
  • 4x NEMA 17 Stepper Motors or high-torque Metal Gear Servos (MG996R). (Steppers are highly preferable for instantaneous 90° snaps without horrific jittering errors that cause the Rubik's cube mechanism to jam entirely and shatter!).
  • Custom 3D-Printed Kinematic Frame (The motors must literally grip the center pieces of the cube with millimeter perfection).
  • A Desktop PC or Raspberry Pi 4 (Executing the terrifying weight of the Python OpenCV and Thistlethwaite/Kociemba Algorithm processing).
  • A 12V High-Amperage Power Supply (To aggressively prevent Stepper driver brownouts when 4 axes lock their holding-torque instantaneously).

Next challenge

Based on this project I moved forward and got from 6 minutes to 30 seconds, 18 seconds time to solve. In other video I explain how can we reach 18 seconds. Please watch, below, my comparison video:

30 seconds vs.6-8 minutes

What for?

This robot is designed to teach:

1. Patient, resilience, frustration management

2. Repeatability and Accuracy, applied to robots

3. Rubik's cube notation, solving algorithms

4. Maths: matrixes theory, statistical, group theory,

5. Programming: Arduino-Python

6. Image processing with openCV

ข้อมูล Frontmatter ดั้งเดิม

apps:
  - "1x OpenCV"
author: "hbolanos2001"
category: "Gadgets, Games & Toys"
components:
  - "1x Arduino 101"
  - "1x 60W PCIe 12V 5A Power Supply"
  - "2x SG90 Micro-servo motor"
  - "1x Machine Screw, M4"
  - "1x Multitool, Screwdriver"
  - "1x Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires"
  - "1x Jumper wires (generic)"
description: "Kinematic puzzle algorithms! Construct an astronomically complex Six-axis 3D-Printed servo architecture, parsing massive Python computer-vision matrices natively into Kociemba algorithms to violently orchestrate a sub-10-second mechanical Rubik's Cube resolution."
difficulty: "Intermediate"
documentationLinks: []
downloadableFiles: []
encryptedPayload: "U2FsdGVkX19SaRhuVCmlxqtCw4Q/AxArdWHg2/VHOp2et22Am7E4Hit21Xsnu6o8V8oKmd1LFu1VotJ4RKvhlQ=="
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/rubiks-cube-solver-robot-6233e2_cover.jpg"
lang: "en"
likes: 5
passwordHash: "5553fc5d9fed610146567d56bab1e80bb6b80ccab1b7cdccbbaa6edbc04effad"
price: 299
seoDescription: "Build a Rubik's Cube Solver Robot using Arduino, Python, and OpenCV. Learn robotics and computer vision in this guide."
tags:
  - "robot"
  - "rubik's cube"
  - "kociemba"
title: "Rubik's Cube Solver Robot"
tools: []
videoLinks:
  - "https://www.youtube.com/embed/ZxHKOq-HWi8"
  - "https://www.youtube.com/embed/-vIQ_6rZf4w"
views: 33118