Miles Chess Robot

Overview

This is an application that integrates robotics and chess. It utilizes a uFactory Lite 6 robot arm and Certabo chessboard; a smart chessboard that uses RFID chips and LEDs to indicate what the chess engine has converged to as best move. The system uses Stockfish as chess engine to drive the robot's movement.

Note
The uFactory robot and Certabo board is not originally compatible. This means that the original gripper may result in malfunctioning movement, due to various sizes and shapes of chess pieces. To remedy this custom made props including pieces and a 3D printed gripper extension are provided.

Architecture

graph TD
    User[User] --> |Interacts with| UI[Frontend UI]
    UI --> |HTTP Requests| Server[Backend Server]
    Server --> |Queries| DB[(PostgreSQL Database)]
    Server --> |Controls| Robot[uFactory Lite 6 Robot]
    Server --> |Reads| Board[Certabo Chessboard]
    Server --> |Uses| Stockfish[Stockfish Chess Engine]
    
    subgraph Frontend
        UI
    end
    
    subgraph Backend
        Server
        Stockfish
    end
    
    subgraph Hardware
        Robot
        Board
    end
    
    subgraph Database
        DB
    end

    classDef frontend fill:#f9f,stroke:#333,stroke-width:2px;
    classDef backend fill:#bbf,stroke:#333,stroke-width:2px;
    classDef hardware fill:#bfb,stroke:#333,stroke-width:2px;
    classDef database fill:#fbb,stroke:#333,stroke-width:2px;
    
    class UI frontend;
    class Server,Stockfish backend;
    class Robot,Board hardware;
    class DB database;
Loading

This diagram illustrates the main components of the Miles Chess Robot system:

  1. User: Represents the person interacting with the system.
  2. Frontend UI: The user interface, built with React and Vite.
  3. Backend Server: The Python-based server handling game logic and communication between components.
  4. PostgreSQL Database: Stores game data and other relevant information.
  5. uFactory Lite 6 Robot: The robotic arm that physically moves chess pieces.
  6. Certabo Chessboard: The smart chessboard with RFID chips and LEDs.
  7. Stockfish Chess Engine: Used to calculate the best moves for the AI opponent.

The diagram shows how these components interact to create an integrated robotics and chess experience.

Limitation

As of now the board only allows for white to start at USB-side of the board. This means that the chosen color must be oriented towards the user by physically rotating the board. It's essential to ensure precise centering of the board for the robot to effectively handle the chess pieces.

Piece placement
While playing, aim to position the pieces squarely in the middle of each chessboard square, maintaining an equal distance to all sides in the square.

Note
While playing make sure the side panels of the board remain free from pieces. This area is is used by the robot to store captured pieces.

Prerequisites

  • Certabo chessboard.
  • uFactory Lite 6 (with power supply).
  • Emergency Stop button.
  • PC or Tablet for Chess robot user interface.
  • Ethernet cable (between robot and pc).
  • USB cable (between chess board and pc).

System installation

  1. Press down the emergency stop button and connect this to the socket labeled safety on the backplane of the robot arm.
  2. Attach the robot to a stable surface using the provided clamps.
  3. Disconnect the AC lead in the power supply and connect the 24V connector to the socket labeled ROBOT 24V on the backplane of the robot arm.
  4. Allign the board infront of the robot using the marks notated on the board, ensuring centering of the base of the robot and board.
  5. Connect the ethernet cable from robot and the USB from the board to the computer.
  6. Connect the power supply to a power source.
  7. Once plugged in and a beep sound is emitted, release the emergency stop button.

CAUTION
The uFactory robot arm is strong and is suited for more than chess play and use various sensors to detect collision.

However, as these collisions are occasionally identified with major delays, users have to be cautious when interacting with the robot.

This collision sensivity can be altered through arm.set_collision_sensitivity(). 1-5, where 5 is most sensitive.

Frontend

Require npm >= 9.5.1

cd frontend
npm install
npm install --legacy-peer-deps
cd ..

Backend

Require Python >= 3.9.13 and pip >= 23.2

Install pip:

python install pip

Create a Virtual Python Environment

cd backend

MAC:

pip install virtualenv

Create:

virtualenv venv

or

python -m virtualenv venv

Activate it:

source venv/bin/activate

Windows:

pip install virtualenv
python -m virtualenv --python venv
.\venv\Scripts\activate

Install requirements

Make sure the virtualenv is activated before installing the requirements.

pip install -r requirements.txt

Stockfish setup

Require Stockfish

Installation for MAC:

brew install stockfish

Installation for Windows 64-bit:

Install Stockfish for Windows 64-bit: https://stockfishchess.org/download/windows/

Assign Stockfish Path:

Create config.py in /backend.

Assign variable STOCKFISH_PATH to Stockfish installation location.

Default path for MAC:

STOCKFISH_PATH = "/usr/local/opt/stockfish/bin/stockfish"

or

STOCKFISH_PATH = "/opt/homebrew/opt/stockfish/bin/stockfish"

Default path for Windows:

Default path for Windows will be stockfish-windows-x86-64.exe location

Database setup

Require postgresql@14

Start postgres on MAC:

brew services start postgresql@14

Check status

brew services

If error, check process for default port for postgresql, and terminate if in use, or change default port. And then restart service.

brew services restart postgresql@14

Start postgres on Windows:

net start postgresql-x64-14

To setup database for MAC and Windows

Activate postgresql environment with user "postgres":

psql -U postgres

Run within psql environment:

CREATE ROLE username WITH LOGIN PASSWORD 'password'; ALTER ROLE username CREATEDB;

CREATE DATABASE databasename;

GRANT ALL PRIVILEGES ON DATABASE databasename TO username;

Create database.ini in /backend/database with the following content:

[postgresql]
host = localhost
database = databasename
user = username
password = password

Board setup

Download Certabo board drivers from: https://www.certabo.com/download/

Follow the instructions provided on the download page.

For Mac, download Certabo software - MAC OSx.

For Windows, download Certabo software – PC 4.1 – 64 bit.

Within the chess-robot project folder in /backend, run the script and follow the instructions in the terminal

python setup.py

System Setup and Start

To set up the system and start the application, run:

./setup_and_start.sh

This script will:

  1. Install the Certabo board drivers
  2. Install necessary dependencies
  3. Set up the database
  4. Set up the backend and frontend
  5. Start the application

To run the setup.py script as well, use:

./setup_and_start.sh --run-setup

Note: You may need to provide administrator privileges for driver installation.

Start application

Open two terminals, one for backend and one for frontend.

In backend terminal:

cd backend

Activate virtualenv

python server.py

In frontend terminal:

cd frontend
npm start

Other information

Deactivate virtualenv

MAC:

deactivate

Windows

venv\scripts\deactivate

Stop postgres server

MAC:

brew services stop postgresql@14

Windows:

net stop postgresql-x64-14