Hey all,

One of my first entries on my robotlab smiley

This is regarding my chess board project and  since a few days I have been talking with GroG and Alessandruino on the shout box regarding this project, so Grog suggested that I post more details about this one so it can be a more permanent thing :P

Heres what im doing in this project:

I am trying to make an automated chessboard. (ie: the moves played by computer will magically move on the board) laugh

Well not exactly magically, I'll be using 2 stepper motors and an electromagnet for making the movement.

A similar project has been already done using MRL and thats what brought me here. Almost all of the hardware is ready for this project, and ill be using an Arduino board to interface the hardware with the computer.

So for most of the software part ill be using MRL and little Arduino programming.

I'll be running MRL on the PC with the following services:

- Chess service (this will be the main game running, al the brain work :D)

- Serial Service (Will send moves to and from the Arduino board and the chess game)

- Log (Will make a note of all the moves during the game)

Since im not much familiar with python coding, ive been using GUI tab to make all the connections. (Ive posted screenshts below showing them).

Things where I need help using MRL are:

- Serial Communication (thanks to Grog and Alessandruino for releasing the serial service and writing a python script for the communication)yes

- Sending the incoming chess moves into chess service (As of now the moves are coming as ascii values, need a function in serial service to print whatever data is incoming so that i can directly connect this to inputMove(string) function of the chess service) (solved with the update of serial service)

(ascii value of char "a")

 

- Sending the moves made by the chess game (Best Move) into the Serial service so it will forward it to the Arduino, I think this can be done by connecting the makeMove of chess with the write(string) function of Serial. Havet tried it yet because the makeMove function publishes both user move and the computer played move (shown belo in this screenshot of log) 

Few Pics of the project hardware:

The Motors, Driver IC, Power Supply and the drive chain

the base is made of acrylic and stands are 3D printed

The reed Array which will detect the movement and send that to the PC

*Will update with images as the project progresses. laugh

Project Update [chess . Automated v1.0] - http://myrobotlab.org/content/chess-automated-10-project-update

 

 

 

beetlejuice

11 years 3 months ago

Very good project !

I'll follow your progress with interest smiley

GroG

11 years 3 months ago

Looks like a great project, and thanks for all your careful detail - it certainly helps (so do the pictures) .

Ok, lets get started....

Step 1 - I suggest moving to a Python script. Although the gui is intuitive, a script provides more control, and as you get more accomplished it is easier to load, versus setting up everything through the gui every time.

I've created the following short script.

It creates the necessary services and creates some message routes

# create the servies
chessgame = Runtime.createAndStart("chessgame","ChessGame")
serial = Runtime.createAndStart("serial","Serial")
log = Runtime.createAndStart("log","Log")
 
#serial.connect("COM4")
 
# register to recieve data from the arduino / serial service (arduino ----->  python)
serial.addListener("read", python.name, "input")
# add the logger to recieve the same 'read" data from the arduino (arduino ----->  log)
serial.addListener("read", log.name, "log")
# register to send data from the chess game to the log (chessgame ----> log)
chessgame.addListener("makeMove", log.name, "log") 
 
def input():
    dataFromArduino = msg_serial_read.data[0]
    # print the data which came from the arduino
    print dataFromArduino 
    
    
This should display both the computer and human moves on the log.  
 
 
I'm a little confused as to how your game will work.  Will it just mirror what is happening on the chessgame gui ?  Or is move input done somehow on the board.  e.g. does the Arduino pick up a pysically movement of a chess peice on the board - or does it only move the pieces around.

I added message routes from the Arduino / Serial service to the log, but don't know if this is needed or desired.
 
A description of game play would be useful. 
e.g.

A human starts by moving a piece on MRL's chessgame
This sends a command to the chessboard to move the piece
The computer counter-moves and this information is sent to the arduino..
etc..
 
Hope this gets you a little farther.
 

mehtaatur

11 years 3 months ago

I wanted to write the details about the game play in the post itself but was nervous about making the post too long. Well so here it is,
 
This gameboard is intended for helping the specially able (blind) people play game of chess against the computer or online against another player.
 
The chess board will be physically like any other board but it will have sensors and motors in it.
 
The chess coin will be 3D printed with magnet at the bottom (Array of reed switches will detect this movement)
 
Game play: 
 
White is Human and Black is Computer
 
  • Player will move White piece himself physically on the board, reed switch array will detect the initial and final positions of that and send it to arduino, arduino will concat this (eg: a2 is initial block and a4 is final block so "a2a4" string will be sent) to the Serial service running on the Computer
*I am expecting that the serial service will directly send this into the Chess service using function inputMove(String)
 
  • Now the computer will play its move, (Back side) and using function MakeMove(string) i'll link this to the write function of the serial service which will send this string into the Arduino board. Once here this string will be decoded (decoding is required because the chess service sends other characters like x, n, z  along with the moves) after getting the coordinates for the movement the arduino will instruct stepper motors to position A and move that coin to position B (done using electromagnet)
 
 
This cycle will repeat will Check Mate and this will give the blind person the feeling of playing chess againts a computer just as if playing on a physical board against a real opponent.
 
Future improvements expected if this projects works well and if I am able to save some funds for it.
 
  • Using the Speech service of MRL(For voice feedback of moves)
  • Being able to connect this board for online game play
  • Making the complete chess box more portable by using a Raspberry PI which runs on Linux (even MRL works on linux and connection to PC wont become optional)

 

 

mehtaatur

11 years 3 months ago

Hey GroG,
 
I tried using the script, it works. could you please help me with the following things:
 
here is the code which i am using:

 

# create the services
 
chessgame = Runtime.createAndStart("chessgame","ChessGame")
serial = Runtime.createAndStart("serial","Serial")
log = Runtime.createAndStart("log","Log")
 
#serial.connect("COM X")
 
serial.connect("COM5", 9600, 8, 1, 0)
 
 
 
serial.addListener("read", python.name, "input")   # this gets data from arduino and into python via the serial service
 
 
serial.addListener("read", log.name, "log")   # log shows the incoming serial data in ASCII
 
 
 
chessgame.addListener("makeMove", log.name, "log")    # moves made by computer and user show up in log
 
 # function for converting ASCII to char and save in variable "dataFromArduino"
 
def input():
    dataFromArduino = msg_serial_read.data[0]
    print dataFromArduino
 
 

 

- connecting the makeMove(string) function of the chess with the write(string) function of the serial [so the chess moves can be sent to arduino]
 
- connecting readString() of serial with inputMove(string) of chess [ so that the incoming move strings can be sent to chess board]
 
** I am guessing that since you have released the new serial service, python wont have to convert ascii any more.
 
When you find time, please help me in adding the two functions in the above script so that one complete cycle of gameplay is completed.
 
Thanks for the Help :)
 
 

mehtaatur

11 years 3 months ago

The chess notations will be a string with 4 characters always,

the above image shows the coordinte system which I will be using.

the incoming string will contain the initial and the final position of the movement.

Eg: if the knight moves from block b1 to c3 then incoming string will be "b1c3"

the arduino will detect the movement using reed switches and the following command will be used for sending the string to PC

Serial.println("b1c3");

 

GroG

11 years 3 months ago

Here's an example script to get string values from the Arduino

Arduino Sketch

void setup() {

  Serial.begin(57600);
}
 
 
void loop() {
 
  Serial.println("a2a3");
  delay(5000);  
}
 

Python Script

import time
 
#create a Serial service named serial
serial = Runtime.createAndStart("serial","Serial")
count = 0
 
if not serial.isConnected():
    #connect to a serial port COM3 57600 bitrate 8 data bits 1 stop bit 0 parity
    serial.connect("COM10")
    #have python listening to serial
serial.addListener("publishByte", python.name, "input") 
 
 
def input():
 global count
 newByte = int(serial.readByte())
 #we have reached the end of a new line
 if (newByte == 10) :
    chessMove = ""
    while (newByte != 13):
        newByte = serial.readByte()
        chessMove += chr(newByte)
 
    print chessMove
    
The Arduino println ends each serial write with a new line also known as "\n" or the byte value 13 10.  So the python script looks for the 13 & 10 and while appending the characters - when it finds a new line it prints it out

GroG

11 years 3 months ago

Build 1666 - (you can update to bleeding edge) has new easy methods for chess game.

with the following python script - you can send moves and recieve moves back from the computer

chessgame = Runtime.createAndStart("chessgame", "ChessGame")
log = Runtime.createAndStart("log", "Log")
chessgame.addListener("computerMoved", log.getName(), "log")
chessgame.move("a2a3")
Change the "a2a3" to the next move and just re-run the script.
 
You will see the computers move on the log panel - this is done with the message routing line :
chessgame.addListener("computerMoved", log.getName(), "log")
but it could just as easily be re-routed to python input or serial output
e.g. chessgame.addListener("computerMoved", python.getName(), "input")
 
 
 

AdolphSmith

10 years 4 months ago

Nice would be nice to see movie of this project in action

 

GroG

10 years 4 months ago

The LED's in the new board are great ! ..  Not only are they functional, but the look great too

Paddymcd

9 years 8 months ago

How did you attach each of the 64 reed switches to your Arduino? I have a Mux shield which gives me 64 pins. But just from looking at yours you seem to have it done differently. Could you explain how you wired up yours?

mehtaatur

9 years 8 months ago

In reply to by Paddymcd

Hello Paddymcd,

You do not need 64 IO pins to control the switches.

An 8x8 Matrix would do the job. You would require 16 pins for reading values from the switches. Following is the wiring diagram for reed switches used in chess automated 1.0

By wiring in this manner you will get 8 VCC pins and 8 Input pins, you can control in double for loop to detect the switches.

I got your email regarding the chess board. Could you make a post about what exactly you are trying to do, so I can help you better.

Ciao! :)