Dark Matters
  • About Me
  • Publications
  • Educational Resources
  • Blog
  • Other Interests

Quick Chessboard Update

10/30/2013

2 Comments

 
I took a little hiatus on the robotic chessboard project I have been working on to better plan out some of my methods. I decided that the sensing of the position of the chess pieces will be done by Hall sensors. I will place a Hall sensor under each square of the board. The kind I bought are essentially switches which turn when one polarity is brought towards the sensor and turns off at the presence of the other magnetic pole. I put small magnets in the bottom of each chess piece. In the first video, you can see that the chess piece activates the hall sensor, which lights the LED. I then use the opposite pole of the magnet, which I glued to a stick, to reset the sensor. (Sorry for the vertical nature of the video. One of these days, I'll remember to consistently hold the phone sideways when recording.)
For the operation of the robotic chessboard, these latching Hall sensors pose a problem. As shown in the above video, the sensors would not turn off when the pieces are removed. Hall sensors that do not latch are nearly twice as expensive at the latching kind. This adds up when 64 are needed. I solve this problem by using a digital pin on the Arduino to control the power input to the Hall sensor instead of the 5V pin. This idea comes from the comments on Sparkfun. As you can see in the second video, the sensor now detects the presence of a magnet.
The next step is learning how to control 64 inputs on the arduino with a mux chip, which allows for control of 16 hall sensors using only 4 pins on the arduino. The next update will hopefully show a full chess board which detects where the pieces are or at least progress in that direction.
2 Comments

The OWI Robotic Arm

9/22/2013

0 Comments

 
Picture
The other day, I ordered an OWI Robotic Arm from Amazon. It is by far the least expensive robotic arm I have seen. I also purchased a standard double-weight tournament-style travel chess board from my local gaming store.  It's pretty much this. The OWI arm has a large range of motion and the motors provide enough torque to lift the heaviest even at full extension. I took a little video of my using the arm with the remote control to move a queen around. As you can see, I am still having trouble figuring out the controls. Also, you can hear my kids making some craft ghosts for Halloween in the background.

There is an Instructable that documents how to control an OWI Arm with an Arduino and a motor shield. I think this is far too complicated. I recently ordered some jumper wires and will attempt to control the arm with the Arduino by wiring it in as the controller and not by connecting the motors to some sort of motor shield or transistor network. I think this will give me the same controls as in the Instructable but will use the electronics board in the arm instead of the Arduino. Perhaps this will also use fewer pins on the Arduino. 
Picture
Picture
Picture
One of the drawbacks of using a OWI arm is that is uses DC motors and not servos or stepper motors. This means that I need to figure out some way to determine how far the arms have moved. I could calibrate the time it takes to move each motor to various distances, but this will not account for drift in the motors or variations in the power given to the motors from the ever-draining D batteries.  An ingenious solution to the distance measurement problem is found by using infrared sensors to measure to rotation of a gear in each gearbox. I have obtained sensors, but I still need to modify the gears and gear boxes so the sensors fit. I'm not sure if this will be less work than making a robotic arm with servos, but I think it will be less expensive in the long run. I have attached some photos of the gear box and the position of the opto coupler. I need to cut some of the plastic in the gearbox so the slit in the optical sensor is in the same plane as the gear. I will detail the process of installing and wiring the opto coupling system as I complete it. I want to demonstrate the Arduino control first after the jumper wires arrive this week. 
Picture
Picture
Picture
Picture
0 Comments

Towards a Robotic Chess Board: Stockfish and Python

9/6/2013

7 Comments

 
I have had it in my head for a while to build a robotic chess board, a chess board where I play against a computer that controls a robotic arm of some sort that moves real pieces on a real board. The "thinking" will be done on a Raspberry Pi computer, which I bought this week as a graduate gift to myself for having finished my PhD program. The arm will be controlled by an Arduino microcontroller. I have already learned how to get Arduino and Raspberry Pi to communicate with each other by reading Simon Monk's nice book Programming the Raspberry Pi:  Getting Started with Python. The Arduino and Raspberry Pi communicate nicely though the serial port using the PySerial package. I have tested this out and it works wonderfully. I must write the Arduino code on my Mac though because the Arduino software released for the Linux Debian operating system is a very old version.

For the chess engine, I have decided to use Stockfish, which uses the Universal Chess Interface. It is consistently rate one of the strongest chess engines. The creators of Stockfish have not provided any documentation for their engine, and the Universal Chess Interface was nontrivial to decipher. Therefore, it took me some time to figure out how to communicate with Stockfish through the terminal.

Tonight, I was able to write a proof-of-concept Python program which let me play chess with Stockfish through the Python shell. This is the first step in writing the software for a USB chessboard. I have included the Python code below. Of course, the Stockfish engine must be installed first. 
Python Code

#This code talks to the Stockfish Chess Engine. Entries are to be made in algebraic
#chess notation (eg. e2e4). Stockfish is set to think for a maximum of 1 sec. 

import sys

chess = r'/Applications/stockfish-4-mac/Mac/stockfish-4-64'.split()['linux' in sys.platform]

import subprocess as S
getprompt = 'isready'
done= 'readyok'

proc= S.Popen(chess, stdin=S.PIPE, stdout=S.PIPE, bufsize=1, universal_newlines=True)

print(proc.stdout.readline().strip())
proc.stdin.write('uci\n')

while True :
        text = proc.stdout.readline().strip()
        print(text)
        if text == "uciok":
            break
        
print('Choose skill level (0-20):')
skillLevel=input()
proc.stdin.write('setoption name Skill Level value '+skillLevel+'\n')
proc.stdin.write('ucinewgame\n')

moveList='position startpos moves '
checkmate=False
while checkmate==False:
    print('Enter move:')
    move=input()
    moveList=moveList+move+' '
    proc.stdin.write(moveList+'\n')
    proc.stdin.write('go movetime 1000\n')
    print('Computer moves:')
    while True :
        text = proc.stdout.readline().strip()
        if text[0:8] == 'bestmove':
            cpuMove=text[9:13]
            print(cpuMove)
            moveList=moveList+cpuMove+' '
            break

7 Comments

    Archives

    July 2015
    February 2014
    November 2013
    October 2013
    September 2013
    July 2013
    June 2013
    May 2013
    April 2013
    March 2013
    February 2013
    January 2013

    Categories

    All
    Arduino
    Chess
    Lightsaber
    Math
    Probability
    Projects
    Python
    Raspberry Pi
    Robotics
    Statistics

    The Great Arduino Project

    RSS Feed

Powered by Create your own unique website with customizable templates.