Chess Robot Raspberry Pi Lynxmotion AL5D Arm

5,468

19

86

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.

Update: I now have a 3D-printed chess robot: https://youtu.be/WQTeGXyIulM

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

    • First Time Author Contest

      First Time Author Contest
    • Backyard Contest

      Backyard Contest
    • Meatless Challenge

      Meatless Challenge

    86 Comments

    0
    JunhoM
    JunhoM

    Question 7 weeks ago

    hello, i already built the robot now i need the code, could you share your code with me xd3141@hotmail.com

    0
    instruct42
    instruct42

    Answer 7 weeks ago

    Will do

    0
    JunhoM
    JunhoM

    Reply 7 weeks ago

    yes I will already made the robot in the 3d printer

    0
    instruct42
    instruct42

    Reply 7 weeks ago

    Which design did you use?

    0
    JunhoM
    JunhoM

    Reply 7 weeks ago

    using servo motors and arduino and pi does it work?

    Screenshot_20220619-014647[287].png
    0
    instruct42
    instruct42

    Reply 7 weeks ago

    You would have to change my code somewhat. Do you already have code on the Arduino to drive the motors, and what is the protocol used between the Rpi and Arduino?

    See also my 3D-printed chess robot: https://youtu.be/WQTeGXyIulM

    0
    JunhoM
    JunhoM

    Reply 6 weeks ago

    would you have an option for me to use in my robot that uses servos and arduino

    0
    instruct42
    instruct42

    Reply 6 weeks ago

    What servos do you have exactly, and how are you powering them?

    0
    JunhoM
    JunhoM

    Reply 6 weeks ago

    four mg995 servos and a 35 kg TD-8135MG, power supply

    0
    instruct42
    instruct42

    Reply 6 weeks ago

    At the moment, do you have any code at all on the Arduino for controlling servos?

    0
    JunhoM
    JunhoM

    Reply 6 weeks ago

    I don't, do you have any options?

    0
    instruct42
    instruct42

    Reply 6 weeks ago

    If you have some knowledge of java and python you could start with this code on the Arduino:
    https://create.arduino.cc/projecthub/Abysmal/robot...

    Then if you got that working it wouldn't be too difficult to modify it and use it with a slightly modified version of my RPi code.

    0
    JunhoM
    JunhoM

    Reply 6 weeks ago

    I don't know much about python, where should I modify

    0
    instruct42
    instruct42

    Reply 6 weeks ago

    OK, I think we can sort this out.. Let's carry on the discussion by email. I'll email you.

    0
    fane_grs
    fane_grs

    1 year 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 1 year ago

    Will do

    0
    FRED2021
    FRED2021

    1 year 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 1 year ago

    I'll PM you.

    0
    mutic.predrag
    mutic.predrag

    1 year 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 1 year ago

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