Chess Robot Raspberry Pi Lynxmotion AL5D Arm

2,817

6

41

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.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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.

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)
  • Cables 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.

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

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 posting a comment, and I will respond.

Be the First to Share

    Recommendations

    • Backyard Contest

      Backyard Contest
    • Silly Hats Speed Challenge

      Silly Hats Speed Challenge
    • Finish It Already Speed Challenge

      Finish It Already Speed Challenge

    41 Discussions

    0
    roger9an0
    roger9an0

    12 days ago

    The common troubleshooting will be to check if your physical USB connection is on a communication port used by the software. Also, you should try to check if the baud rate settings of the software match that of the AL5D robot arm. And finally, it might just be a simple solution to upgrade the FlowArm PLTW software. Finally, you might need to just understand some basics about sensor technology to get some issues fixed, so learn more here: https://tacunasystems.com/knowledge-base/

    0
    hdayae1004
    hdayae1004

    21 days ago

    hi. your project is amazing. can you send me a code files? my email is hdayae705@naver.com . it'll be thankful if you send me a code.

    0
    instruct42
    instruct42

    Reply 18 days ago

    Will do.

    1
    instruct42
    instruct42

    Reply 24 days ago

    Will do.

    0
    MarcoF26
    MarcoF26

    Reply 24 days ago

    thanks!

    0
    hrp2617
    hrp2617

    5 weeks ago

    Excellent project ,Could you share all codes and files with me,Thank you hrp4414@gmail.com

    0
    instruct42
    instruct42

    Reply 5 weeks ago

    Will do.

    0
    hrp2617
    hrp2617

    Reply 5 weeks ago

    Thank you.

    0
    승찬이1
    승찬이1

    5 weeks ago

    awesome again. I already commented your another project with EV3, but I ask you again just in case. can you send me a code? my email is leesc030720@naver.com it will be so thankful if you send me a code.

    0
    instruct42
    instruct42

    Reply 5 weeks ago

    Will do

    0
    Nuryc
    Nuryc

    2 months ago

    Amazing project!!!
    Could you please send me the code, here's my email nurychavarror@hotmail.com
    Thanks in advance :)

    0
    instruct42
    instruct42

    Reply 2 months ago

    Will do.

    0
    instruct42
    instruct42

    Reply 3 months ago

    Will do.

    0
    saleh6449
    saleh6449

    Question 5 months ago

    nice work if you pleace can send for me the code was written 3 dimensiions on python on my email :saleh6449@hotmail.com

    0
    instruct42
    instruct42

    Answer 5 months ago

    Will do.

    0
    carlitos.m8018
    carlitos.m8018

    6 months ago

    Great job and a very interesting project. I am on a project same this for my school, it would be very helpful if you can share the code carlitos.m8018@gmail.com

    0
    instruct42
    instruct42

    Reply 6 months ago

    Will do