Chess Robot Raspberry Pi Lynxmotion AL5D Arm

4,450

15

73

Introduction: Chess Robot Raspberry Pi Lynxmotion AL5D Arm

Build this chess robot and see it beat everybody!

It's pretty easy to build if you can follow the instructions on how to build the arm, and if you have at least an elementary knowledge of computer programming and Linux.

The human, playing white, makes a move. This is detected by the visual recognition system. The robot then ponders and then makes its move. And so on ...

Perhaps the most novel thing in this robot is the code for move recognition. This vision code is also usable for chess robots built in many other ways (such as my chess robot with LEGO build).

Because the human's move is recognised by a vision system, no special chess board hardware (such as reed switches, or whatever) is needed.

My code is available for personal use.

Step 1: Requirements

All the code is written in Python, which will run on, amongst other things, a Raspberry Pi.

The Raspberry Pi is a small, inexpensive (around $40) single-board computer developed by the Raspberry Pi Foundation. The original model became far more popular than anticipated, selling for uses such as robotics

My robot uses a Raspberry Pi, and the robot arm is built from a kit: Lynxmotion AL5D. The kit comes with a servo controller board. (The link I've just given is to RobotShop's US site; click on one of the flags at the top right of their site pages for your country, e.g. UK).

You will also need a table, a camera, lighting, a keyboard, screen and pointing device (e.g. mouse). And of course, chess pieces and a board. I describe all these things in more detail in the subsequent steps.

Step 2: The Hardware Build

As I previously indicated, the heart of the vision code will work with a variety of builds.

This build uses a robotic arm kit from Lynxmotion, the AL5D. Included with the kit is an SSC-32U servo controller board, which is used to control the motors in the arm.

I chose the AL5D because the arm has to be able to make repeated accurate movements and not drift off. The grabber has to be able to get between pieces and the arm has to be able to reach to the far side of the board. I still needed to make some modifications as detailed below.

The Raspberry Pi I use is a Raspberry Pi 3 Model B+. This talks to the SSC-32U board via a USB connection.

EDIT: The Raspberry Pi 4 is now available.
You will need:

  • A 15W USB-C power supply – we recommend the official Raspberry Pi USB-C Power Supply
  • A microSD card loaded with NOOBS, the software that installs the operating system (buy a pre-loaded SD card along with your Raspberry Pi, or download NOOBS to load a card yourself)
  • A keyboard and mouse (see later)
  • A cable to connect to a display via a Raspberry Pi 4's micro HDMI port

I needed further reach on the robot arm, so I made some minor modifications to it, using additional Lynxmotion parts which can be bought from RobotShop:

1. Replaced the 4.5 inch tube by a 6 inch one - Lynxmotion part AT-04, product code RB-Lyn-115.

2. Tried using an additional set of springs, but went back to one pair when I implemented item 3 below

3. Extended the height using a 1 inch spacer - Lynxmotion part HUB-16, product code RB-Lyn-336.

4. Extended the gripper reach using spare gripper pads attached by some spare LEGO pieces I had and elastic bands(!) This works very well, as it introduces flexibility when lifting pieces.

These modifications can be seen in the image above on the right.

There is a camera mounted above the chess board. This is used to determine the human's move.

Step 3: The Software Which Moves the Robot

All the code is written in Python 2. Inverse kinematics code is needed in order to move the various motors correctly such that chess pieces can be moved. I use library code from Lynxmotion which supports moving the motors in two dimensions and have added to that with my own code for 3 dimensiions, gripper angle and gripper jaw movement.

So, we then have code which will move pieces, take pieces, castle, support en passant, and so on.

The chess engine is Stockfish - which can beat any human! "Stockfish is one of the strongest chess engines in the world. It is also much stronger than the best human chess grandmasters."

The code to drive the chess engine, validate that a move is valid, and so forth is ChessBoard.py

I use some code from http://chess.fortherapy.co.uk to interface with that. My code (above) then interfaces with that!

Step 4: The Software Which Recognises the Human's Move

I have described this in detail in the Instructable for my Chess Robot Lego build - so I don't need to repeat it here!

My "black" pieces were originally brown, but I painted them matt black (with "blackboard paint"), which makes the algorithm work better under more variable lighting conditions.

Step 5: Camera, Lights, Keyboard, Table, Display

These are the same as in my Chess Robot Lego build, so I don't need to repeat them here.

Except that this time I used a different and significantly better speaker, a Lenrui Bluetooth speaker, which I connect to the RPi by USB.

Available from amazon.com, amazon.co.uk and other outlets.

Also I am now using a different camera - an HP Webcam HD 2300, as I couldn't get the previous camera to behave reliably.

The algorithms work best if the chessboard has a colour that is a long way from the colour of the pieces! In my robot, the pieces are off-white and brown, and the chess board is hand-made in card, and is a light green with little difference between the "black" and "white" squares.

The algorithms need a particular orientation of camera to board. Please comment below if you are having an issue. The arm has limited reach, and so the square size should be 3.5 cm.

Step 6: Obtaining the Software

1. Stockfish

If you run Raspbian on your RPi you can use the Stockfish 7 engine - it's free. Just run:

sudo apt-get install stockfish

2. ChessBoard.py Get this from here.

3. Code based on http://chess.fortherapy.co.uk/home/a-wooden-chess... Comes with my code.

4. Python 2D Inverse Kinematics library - https://github.com/Lynxmotion/Arms/tree/master/Code%20examples/Python%20(RPi)

5. My code which invokes all the code above and which gets the robot to make the moves, and my vision code. Get this from me by first subscribing to my YouTube channel, then clicking on the "Favorite" button near the top of this Instructable and then posting a comment to this Instructable, and I will respond.

Be the First to Share

    Recommendations

    • Summer Fun: Student Design Challenge

      Summer Fun: Student Design Challenge
    • Fandom Contest

      Fandom Contest
    • Metal Contest

      Metal Contest

    73 Comments

    0
    fane_grs
    fane_grs

    5 days ago

    Hello,
    I am also interested in buliding this project. Could you share your code and some tips on stefan.catana2@gmail.com with me please? Thank you!

    0
    instruct42
    instruct42

    Reply 4 days ago

    Will do

    0
    FRED2021
    FRED2021

    3 months ago

    HI,
    GOOD WORK.
    I HAVE THE SAME QUESTION THAT THE LAST POST FROM MUTIC_PREDRAT;
    i SEARCH THE CODE TO ESTABLISH THE COMMUNICATION BEETWEEN RASPBERRY PI 4 AND SSC32U. Can share your code for this ?
    thank a lot
    Fred

    0
    instruct42
    instruct42

    Reply 2 months ago

    I'll PM you.

    0
    mutic.predrag
    mutic.predrag

    3 months ago on Step 6

    Great work! I am trying to make my Hexapod robot running SSC-32U to be connected and controlled by Raspberry Pi 4. You have connected them together (RPi 3 but that should be the same). Can you please share your code or explain what needs to be done to establish the connection between the two. My email is mutic_predrag@yahoo.com Thanks a lot!

    0
    instruct42
    instruct42

    Reply 3 months ago

    I will send you a link to the code, etc.

    0
    JSGallo
    JSGallo

    11 months ago

    Very nice. I am trying to do something similar but more recently updated
    (for example the chess logic code from scratch is epic but it can be
    replaced with the python chess lib). I am very interested in the code.
    Could you please send me it to gallojsantiago@gmail.com ? Thank you

    0
    instruct42
    instruct42

    Reply 11 months ago

    Will do.

    0
    JSGallo
    JSGallo

    11 months ago

    Very nice. I am trying to do something similar but more recently updated (for example the chess logic code from scratch is epic but it can be replaced with the python chess lib). I am very interested in the code. Could you please send me it to gallojsantiago@gmail.com ? Thank you

    0
    mangaxd3
    mangaxd3

    11 months ago

    Hi, great project, Can i please request the code you used. Send it to mangaxd3@gmail.com. I followed your instructions.

    0
    instruct42
    instruct42

    Reply 11 months ago

    Will do.

    0
    donghyun
    donghyun

    1 year ago

    That's a great project. I asked you to send me the code last time, but it didn't come, so please do it again. Send me the code, please. kn901020123@gmail.com

    0
    instruct42
    instruct42

    Reply 1 year ago

    I'll send it now.

    0
    Ralf-PeterM
    Ralf-PeterM

    1 year ago

    Amazing! Really a fascinating project!
    Could you please share your code with me, too? Thank you so much in advance.
    My email address is RPMicko@Gmail.com.

    0
    instruct42
    instruct42

    Reply 1 year ago

    Will do.

    0
    Jjhjart
    Jjhjart

    1 year ago

    Awesome! Could you please send me the code at files and every thing else at jjhjart@gmail.com. Thank you!

    0
    instruct42
    instruct42

    Reply 1 year ago

    Will do.

    0
    Jjhjart
    Jjhjart

    Reply 1 year ago

    How does the webcam see the color?

    0
    instruct42
    instruct42

    Reply 1 year ago

    I described this in detail in my Instructable for my Chess Robot Lego build, step 4.