Automata – THE HYPERTEXT http://www.thehypertext.com Thu, 10 Dec 2015 06:10:15 +0000 en-US hourly 1 https://wordpress.org/?v=5.0.4 The Mechanical Turk’s Ghost, Part V http://www.thehypertext.com/2015/01/05/the-mechanical-turks-ghost-part-v/ Mon, 05 Jan 2015 02:13:40 +0000 http://www.thehypertext.com/?p=415 For my final project in Automata with Nick Yulman, I completed work on my musical chess experience, entitled the Mechanical Turk's Ghost.

Read More...

]]>
For my final project in Automata with Nick Yulman, I completed work on my musical chess experience, the Mechanical Turk’s Ghost. Along with adding a case, I changed the music to an original score and added solenoids beneath the board that fire when the Stockfish chess engine detects one player is within range of checkmate.

Here are some additional sketches and photos of the finished product:

photo 5

photo 2

IMG_0628

 

The drawer left ample space for a variable voltage power supply (for the solenoids), a pair of speakers (to amplify the music), and my MacBook Pro (to run Stockfish).

IMG_0726

IMG_0724

 

Here’s a look beneath the board:

IMG_0733

IMG_0736

IMG_0739

]]>
The Mechanical Turk’s Ghost, Part IV http://www.thehypertext.com/2014/11/18/the-mechanical-turks-ghost-part-iv/ Tue, 18 Nov 2014 07:56:38 +0000 http://www.thehypertext.com/?p=314 For my Automata midterm, I completed software and hardware versions of my music feedback system for chess.

Read More...]]> For my Automata midterm, I completed software and hardware versions of my music feedback system for chess. All the code is available on Github, for both the hardware and software versions.

After experimenting with various methods for mixing two songs, I arrived at the conclusion that the most dramatic effect, in terms of game feedback, would be achieved by mixing stems (individual instrument recordings) of each song. To do this, I used Garage Band to synthesize stems from midi files of Beethoven’s 9th Symphony (for white) and Rachmaninoff’s Piano Concerto No. 3 (for black), and triggered the inclusion or removal of stems at various score thresholds.

Here is the pattern I implemented:

photo

 

On Tom Igoe‘s suggestion, I added volume knobs and a reset button for the music loops to allow more user control over the experience. I used two potentiometers and a button connected to an Arduino Uno, which sent signals to my computer via serial communication.

20120130 0674 2 Pots 1 Button_sm

Here is the software version of in action (I apologize for the distracting background noise):

After playtesting the software version in class and on the floor, I built a hardware version.

I discovered a circuit that would help me avoid wiring up 64 chessboard squares independently. Rather than connecting each hall effect sensor as a switch to a single input, I connected them together in rows and columns. By sending a pulse down each column, and then reading each row, it is possible to record the status (0 or 1) of every square on the board.

I started with a relatively simple grid of 16 hall effect sensors:

20120130 0670 16 Hall Effect Sensors_sm

After I got that working, I started putting together the full board.

I laser cut 64 triangles out of a piece of wood, glued the wood to vinyl chessboard, glued hall effect sensors into each triangle, and soldered everything together. Each hall effect sensor has three pins: one connected to a row of sensors, one connected to a column of sensors, and one connected to ground.

20141104 9140 mtg bottom_sm

20141104 9157 4 hall effect housings_sm

I then placed neodymium magnets under the felt pads on the bottom of each chess piece:

20120130 0678 magnet_sm

20141104 9155 piece magnet_sm

Finally, I hooked up the chessboard to an Arduino Mega and tested it out (sorry again for the excessive background noise):

Here are some more photographs of the project in its current state:

20141104 9112 mtg_sm

20141104 9114 mtg w jane_sm

For my Automata final project, I plan to refine the musical experience and add a case to the chessboard. More details to come in future installments.

]]>
The Mechanical Turk’s Ghost, Part III http://www.thehypertext.com/2014/10/19/the-mechanical-turks-ghost-part-iii/ Sun, 19 Oct 2014 22:01:50 +0000 http://www.thehypertext.com/?p=228 We have begun work on our midterm assignments for Automata, and we were asked to present our concepts for this week's class. I have decided to pursue my chess idea, the Mechanical Turk's Ghost, and will discuss its implementation in this post.

Read More...

]]>
CONCEPT

My midterm project will be a chess set that generates music and ejects pieces from the board based on Stockfish chess engine analytics. My eventual plan is to implement a physical (hardware) version of the chess set, using magnets in the pieces, Hall Effect sensors in the board, and solenoids beneath the board. However, I may rely on a software version (a chess GUI rather than a physical board) as my initial prototype. Such a version would still be connected to a physical board with solenoids beneath it to demonstrate that aspect of the project.

COMPOSITION

The chess board will be connected to the Stockfish chess engine — the world’s most powerful chess engine, which also happens to be open source. The engine will provide real-time analytics for games-in-progress, providing a score (above 0 if white is winning, below 0 if black is winning), along with the “best move” from any given board position. Mapping these variables to music will provide auditory feedback for players, turning an otherwise normal game of chess into “advanced chess” (chess where both players have access to engine analytics), but without the traditional chess engine interface. The solenoids beneath the board will provide an element of surprise and a unique way to signal that the game has ended, due to one player coming within range of a checkmate.

CONTEXT

Creating an auditory interface for the game of chess could have interesting consequences, both for chess itself and the possibility of applying such an interface to other games. I am not sure how auditory feedback will effect the game, but I hope it will make players more acutely aware of their relative strategic positions at all times. Ideally, it would provide an avenue for improvement by helping people think more like the computer chess engines.

BILL OF MATERIALS

Chess board & housings for Hall Effect sensors
64 Hall Effect sensors
32 (or more) magnets
4 solenoids
1 Arduino Mega
1 Raspberry Pi
16 multiplexor ICs
64 LEDs (if “best move” feature implemented)

TECHNICAL DRAWINGS & IMAGES

Initial Drawing (with conductive pads instead of hall effect sensors):
image_23

 

Rendering of Hall Effect Sensor Enclosure (for laser cutter):

halleffectencl

Hall Effect Sensor Enclosure Prototype:

photo

Chess GUI (software version):

che55

SIGNAL CHAIN

Magnets >> Hall Effect Sensors >> Multiplexors >> Arduino >> Raspberry Pi (>> Music) >> Arduino >> Multiplexors >> Solenoids/LEDs

]]>
Trillion Year Clock http://www.thehypertext.com/2014/10/06/trillion-year-clock/ Mon, 06 Oct 2014 06:38:07 +0000 http://www.thehypertext.com/?p=199 For this week's Automata homework, I experimented with extreme gear ratios. I plan to use what I learned to create a clock that will make one full rotation every trillion years.

Read More...]]>

For this week’s Automata homework, I experimented with extreme gear ratios. I plan to use what I learned to create a clock that will make one full rotation every trillion years. In the video above, I demonstrate my prototype device, which exhibits a combined gear ratio of 1:622080000000. The drill I am using to turn the first gear is spinning at 450 rpm. From that initial speed, translated over the course of the gear chain, the final gear on the far right will take 2630 years to make one full rotation.

The inspiration for making a trillion year clock came from a number of sources: Spin Sink by Tim Hawkinson, Machine with Concrete by Arthur Ganson, and the Clock of the Long Now. Moreover, I am fascinated by the concepts of time and scale.

One trillion years is an absurdly long amount of time, considering that scientists have measured the approximate age of the universe to be a (relatively) scant 13.5 billion years—just 1.3% of the trillion year timespan. Rather than focusing on the difficult (if not impossible) problem of finding materials and a driving mechanism that would last such a long time, I am primarily interested in finding a compact combination of gears that will provide the requisite speed reduction.

I started my exploration by playing with Lego gears. I began with combinations of compound gears, hoping to discover the point at which rotation would no longer be visible. Each of the large gears has 40 teeth, and each of the small gears has 8 teeth, creating a gear ratio of 1:5 for each compound gear pair. After stacking four of these compound gears, and rotating the first gear by hand, it was no longer possible to see the final gear rotating. I continued adding gears until I ran out of space on the Lego board.

image_7

image_1

image_6

image_4

image_2

After creating this initial prototype device, I did some research and some math. I found gears for sale online that would allow me to create compound gears with a 1:10 ratio. Stacking 20 of these compound gears would provide a combined ratio of 1:10^20. With such a gear ratio, an initial rotation speed of one turn per second would translate to a final rotation speed of one turn every 3.17 trillion years.

Worm_Gear

I then began reading about worm gears. Worm gears are effectively single tooth gears, allowing for more dramatic gear ratios contained within smaller amounts of space. Using worm gears with a 1:100 ratio for each pair of gears, the 1:10^20 final ratio described above would require only 10 pairs of gears.

With my newfound perspective, I returned to the Lego sets with the intention of making the most extreme possible gear ratio with the parts available. After scouring the 6 Lego kits in the ITP equipment room for every large gear, small gear, worm gear, and worm gear box, I constructed the device pictured in the video above.

photo 1

photo 2

photo 3

photo 4

photo_0

The device consists of 7 pairs of compound gears, each with a 1:5 gear ratio, and 5 pairs of worm gears, each with a 1:24 gear ratio. The resulting combined gear ratio is calculated as: 1:(5^7*24^5) or 1:622080000000.

Working with Legos helped me visualize the spacial configuration possibilities for a trillion year clock. If I move forward with the project, I plan to fabricate the support structures and gear boxes, and possibly the gears themselves.

]]>
General Update http://www.thehypertext.com/2014/09/29/general-update/ http://www.thehypertext.com/2014/09/29/general-update/#comments Mon, 29 Sep 2014 06:24:41 +0000 http://www.thehypertext.com/?p=177 I've been so busy the past two weeks that I failed to update this blog. But documentation is important, and that's why I'm going to take a moment to fill you in on all my recent activities. This post will cover all the projects I've been working on.

Read More...

]]>
I’ve been so busy the past two weeks that I failed to update this blog. But documentation is important, and that’s why I’m going to take a moment to fill you in on all my recent activities. This post will cover all the projects I’ve been working on, primarily:

  • Applications Presentation on September 16
  • ITP Code Poetry Slam on November 14
  • The Mechanical Turk’s Ghost
  • Che55

On Tuesday, September 16, I helped deliver a presentation to our class in Applications. Yingjie Bei, Rebecca Lieberman, and Supreet Mahanti were in my group, and we utilized my Poetizer software to create an interactive storytelling exercise for the entire audience. Sarah Rothberg was kind enough to record the presentation, and Rebecca posted it on Vimeo:

 

 

I’ve also been organizing an ITP Code Poetry Slam, which will take place at 6:30pm on November 14. Submissions are now open, and I’m hoping the event will serve as a conduit for productive dialogue between the fields of poetry and computer science. Announcements regarding judges, special guests, and other details to come.

Various explorations related to the Mechanical Turk’s Ghost [working title] have consumed the rest of my time. While I wait for all the electronic components I need to arrive, I have been focusing on the software aspects of the project, along with some general aspects of the hardware.

The first revision to the preliminary design I sketched out in my prior post resulted from a friend‘s suggestion. Rather than using conductive pads on the board, I now plan to use Hall effect sensors mounted beneath the board that will react to tiny neodymium magnets embedded in each chess piece. If everything works properly, this design should be far less visible, and thus less intrusive to the overall experience. I ordered 100 sensors and 500 magnets, and I look forward to experimenting with them when they arrive.

In the meantime, the parts I listed in my prior post arrived, and I was especially excited to begin working with the Raspberry Pi. I formatted an 8GB SD card and put NOOBS on it, then booted up the Raspberry Pi and installed Raspbian, a free operating system based on Debian Linux that is optimized for the Pi’s hardware.

r_pi

The Stockfish chess engine will be a major component of this project, and I was concerned that its binaries would not compile on the Raspberry Pi. The makefile documentation listed a number of options for system architecture, none of which exactly matched the ARM v6 chip on the Raspberry Pi.

Screen Shot 2014-09-28 at 10.46.18 PMFirst, I tried the “ARMv7” option. The compiler ran for about 10 minutes before experiencing errors and failing. I then tried several other options, none of which worked. I was about to give up completely and resign myself to running the chess engine on my laptop, when I noticed the “profile-build” option. I had never heard of profile-guided optimization (PGO), but I tried using the command “make profile-build” rather than “make build” along with the option for unspecified 32-bit architecture. This combination allowed Stockfish to compile without any issues. Here is the command that I used (from the /Stockfish/src folder):

$ make profile-build ARCH=general-32

With Stockfish successfully compiled on the Raspberry Pi, I copied the binary executable to the system path (so that I could script the engine using the Python subprocess library), then tried running the Python script I wrote to control Stockfish. It worked without any issues:

ghost

My next set of explorations revolved around the music component of the project. As I specified in my prior post, I want the device to generate music. I took some time to consider what type of music would be most appropriate, and settled on classical music as a starting point. Classical music is ideal because so many great works are in the public domain, and because so many serious chess players enjoy listening to it during play. (As anecdotal evidence, the Chess Forum in Greenwich Village, a venue where chess players congregate to play at all hours of the day and night, plays nothing but classical music all the time. I have been speaking to one of the owners of the Chess Forum about demonstrating my prototype device there once it is constructed.)

Generating a classical music mashup using data from the game in progress was the first idea I pursued. For this approach, I imagined that two classical music themes (one for black, one for white) could be combined in a way that reflected the relative strength of each side at any given point in the game. (A more complex approach might involve algorithmic music generation, but I am not ready to pursue that option just yet.) Before pursuing any prototyping or experimentation, I knew that the two themes would need to be suitably different (so as to distinguish one from the other) but also somewhat complementary in order to create a pleasant listening experience. A friend of mine who studies music suggested pairing one song (or symphony or concerto) in a major key with another song in the relative minor key.

Using YouTube Mixer, I was able to prototype the overall experience by fading back and forth between two songs. I started by pairing Beethoven’s Symphony No. 9 and Rachmaninoff’s Piano Concerto No. 3, and I was very satisfied with the results (play both these videos at once to hear the mashup):

I then worked on creating a music mashup script to pair with my chess engine script. My requirements seemed very simple: I would need a script that could play two sound files at once and control their respective volume levels independently, based on the fluctuations in the score calculated by the chess engine. The script would also need to be able to run on the Raspberry Pi.

These requirements ended up being more difficult to fulfill than I anticipated. I explored many Python audio libraries, including pyo, PyFluidSynth, mingus, and pygame’s mixer module. I also looked into using SoX, a command line audio utility, through the python subprocess library. Unfortunately, all of these options were either too complex or too simple to perform the required tasks.

Finally, on Gabe Weintraub’s suggestion, I looked into using Processing for my audio requirements and discovered a library called Minim that could do everything I needed. I then wrote the following Processing sketch:

import ddf.minim.*;

Minim minim1;
Minim minim2;
AudioPlayer player1;
AudioPlayer player2;

float gain1 = 0.0;
float gain2 = 0.0;
float tgtGain1 = 0.0;
float tgtGain2 = 0.0;
float level1 = 0.0;
float level2 = 0.0;
float lvlAdjust = 0.0;

BufferedReader reader;
String line;
float score = 0;

void setup() {
  minim1 = new Minim(this);
  minim2 = new Minim(this);
  player1 = minim1.loadFile("valkyries.mp3");
  player2 = minim2.loadFile("Rc3_1.mp3");
  player1.play();
  player1.setGain(-80.0);
  player2.play();
  player2.setGain(6.0);
}

void draw() {
  reader = createReader("score.txt");
  try {
    line = reader.readLine();
  } catch (IOException e) {
    e.printStackTrace();
    line = null;
  }
  print(line); 
  score = float(line);
  
  level1 = (player1.left.level() + player1.right.level()) / 2;
  level2 = (player2.left.level() + player2.right.level()) / 2;  

  lvlAdjust = map(level1 - level2, -0.2, 0.2, -1, 1);
  tgtGain1 = map(score, -1000, 1000, -30, 6);
  tgtGain2 = map(score, 1000, -1000, -30, 6);
  tgtGain1 = tgtGain1 * (lvlAdjust + 1);
  tgtGain2 = tgtGain2 / (lvlAdjust + 1);
  
  gain1 = player1.getGain();
  gain2 = player2.getGain();
  
  print(' ');
  print(gain1);
  print(' ');
  print(gain2);
  print(' ');
  print(level1);
  print(' ');
  println(level2);
  
  if (level2 > level1) {
    tgtGain2 -= 0.1;
  } else if (level1 < level2) {
    tgtGain1 -= 0.1;
  }
  
  player1.setGain(tgtGain1);
  player2.setGain(tgtGain2);
}

The script above reads score values from a file created by the Python script that controls the chess engine. The score values are then mapped to gain levels for each of the two tracks that are playing. I input a chess game move by move into the terminal, and the combination of scripts worked as intended by fading between the two songs based on the relative positions of white and black in the chess game.

Unfortunately, a broader issue with my overall approach became highly apparent: the dynamic qualities of each song overshadowed most of the volume changes that occurred as a result of the game. In other words, each song got louder and quieter at various points by itself, and that was more noticeable than the volume adjustments the script was making. I attempted to compensate for these natural volume changes by normalizing the volume of each song based on its relative level compared to the other song (see lines 42-45, 48-49, and 63-67 in the code above). This did not work as effectively as I hoped, and resulted in some very unpleasant sound distortions.

After conferring with my Automata instructor, Nick Yulman,  I have decided to take an alternate approach. Rather than playing two complete tracks and fading between them, I plan to record stems (individual instrument recordings) using the relevant midi files, and then create loop tracks that will be triggered at various score thresholds. I am still in the process of exploring this approach and will provide a comprehensive update sometime in the near future.

In the meantime, I have been learning about using combinations of digital and analog inputs and outputs with the Arduino, and using various input sensors to control motors, servos, solenoids, and RGB LEDs:

photo 3

In Introduction to Computational Media, we are learning about object oriented programming, and Dan Shiffman asked us to create a Processing sketch using classes and objects this week. As I prepare to create a physical chessboard, I thought it would be appropriate to make a software version to perform tests. Che55 (which I named with 5’s as an homage to Processing’s original name, “Proce55ing“) was the result.

che55

Che55 is a fully functional chess GUI, written in Processing. Only legal moves can be made, and special moves such as en passant, castling, and pawns reaching the end of the board have been accounted for. I plan to link Che55 with Stockfish in order to create chess visualizations and provide game analysis, and to prototype various elements of the Mechanical Turk’s Ghost, including the musical component. I left plenty of space around the board for additional GUI elements, which I’m currently working on implementing. All of the code is available on Github.

Unfortunately, I cannot claim credit for the chess piece designs. Rather, I was inspired by an installation I saw at the New York MoMA two weeks ago called Thinking Machine 4 by Martin Wattenberg and Marek Walczak (also written in Processing).

That’s all for now. Stay tuned for new posts about each of these projects. I will try to keep this blog more regularly updated so there (hopefully) will be no need for future multi-project megaposts like this one. Thanks for reading.

]]>
http://www.thehypertext.com/2014/09/29/general-update/feed/ 2
The Mechanical Turk’s Ghost http://www.thehypertext.com/2014/09/13/mechanical-turks-ghost/ Sat, 13 Sep 2014 08:02:24 +0000 http://www.thehypertext.com/?p=133 I began the first exercise of Automata with an exploration of two subjects that interest me: the game of chess and horror fiction. These subjects brought me to a simple question: how to make the game of chess terrifying?

Read More...]]> image_23

I began the first exercise of Automata with an exploration of two subjects that interest me: the game of chess and horror fiction. These subjects brought me to a simple question: how to make the game of chess terrifying?

Here are the elements that I decided on, which could be implemented separately or all at once, presented in ascending order of difficulty (or my perception thereof):

  • Pieces fly off the board when the game becomes “angry” at the players — this could be due to a variety of factors, including players taking too much time to make a move, overall game duration, or chess engine analytics.
  • The game generates music and noises that become more terrifying when you start to lose (using a music template engine).
  • The game generates visual elements on a screen.
  • LEDs show that the move you should’ve made (using the Stockfish open source chess engine).
  • The game generates a story (using natural language processing & generation) that you can read afterwards.

My first study involved using a square on the board as a switch in a circuit. I decided to focus on the most common opening move for white: pawn to e4.

I began by gluing a conductive washer to the base of a white pawn, inserting wires into a vinyl chess board, and fashioning makeshift conductive pads with pools of solder.

image_20

I then connected each square to an LED.

image_9

image_13

A few observations I made after conducting this initial study:

  • Tracking the game will not require electronic IDs for individual pieces, so long as the game always begins in the standard starting position.
  • 64 inputs will (probably) be required (unless there’s a simple, elegant solution that I’m not seeing at the moment).
  • I need to order a lot of parts.

I started by ordering some parts. At present, I have ordered:

  • 4 12V DC Solenoids with Spring-Return Clappers
  • 100 Super Bright Blue LEDs
  • 140 1/4″ Crimp Terminals (to use as conductive pads)
  • 16 MCP23S17-E/SP Input/Output Expander Chips
  • 40 CD4021BE Parallel-to-Serial Shift Register Chips
  • 1 Giant Breadboard
  • 1 Raspberry Pi Model B+ (see software investigation below).

Sam Levign wisely pointed out that I could use a video camera + OpenCV to accomplish the piece tracking, but in the spirit of investigating automata, I am pursuing the mechanical route for now. In theory, the hardware listed above should give me far more than enough General Purpose I/O pins.

In my second study, I investigated the software component of the device. Stockfish, the world’s most powerful chess engine, is open source. and provides an ideal solution to the problems of gathering and interpreting game analysis data. I also concluded that the Raspberry Pi would likely provide the best scripting platform for Stockfish.

The terminal interface for Stockfish:

Screen Shot 2014-09-13 at 3.16.33 AM

I was relieved to find that the interface does not rely on chess notation. Instead, it uses a much more straightforward [originSquare][destinationSquare] notation. The relevant commands to manipulate the interface are:

position startpos moves e2e4 d7d5 ...
go movetime 5000

The first line sets the board position. The second line specifies how long the computer should spend analyzing the position. (In this case, 5000 = 5 seconds.)

In the console, the program prints its output in real time. It is fun to watch, especially if you type “go infinite”, in which case the computer will analyze indefinitely until you enter “stop”. This is what the output looks like:

Screen Shot 2014-09-13 at 3.44.28 AM

Using Python’s subprocess library, I was able to manipulate the engine and its output using Python scripts:

import subprocess
from time import sleep

engine = subprocess.Popen(
	'stockfish',
	stdin=subprocess.PIPE,
	stdout=subprocess.PIPE,
	)

def put(command):
	engine.stdin.write(command+'\n')

def move(coords):
	game.append(coords)
	game_string = ' '.join(game)
	put("position startpos moves " + game_string)

def analyze(m):
	last_line = ""
	move(m)
	put("go infinite")
	nextmove = raw_input('> ')
	if bool(nextmove) == True:
		put("stop")
		while True:
			text = engine.stdout.readline().strip()
			split_text = text.split(' ')
			if len(split_text) > 6 and split_text[5] == 'score':
				score = split_text[7]
			if split_text[0] == 'bestmove':
				return {'rightmove': split_text[1],
						'ponder': split_text[3],
						'info': last_line,
						'score': int(score),
						'movemade': nextmove}
				break
			last_line = text


game = []
first_move = raw_input('> ')
while True:
	analysis = analyze(first_move)
	print analysis
	first_move = analysis['movemade']

The script above analyzes each move the players make and stops analyzing once the next move has been made, at which point it prints out the best move the player could have made along with a “score” for the game so far. The best move will be mapped onto the board’s LEDs and the score will generate auditory/visual feedback. When the score dips below (or above) a certain threshold, one or more of the solenoids beneath the board will activate.

I am very excited to be working on this project. I plan to experiment with various aspects of the overall design until I arrive at the best solutions for each part of it.

Edit: This fictional story I wrote a while back may serve as fodder for the narrative aspect of the project, but I don’t want to give too much away w/r/t specifics at the moment.

Edit2: And these photographs may serve as visual fodder.

]]>