S15: Wizard's Chess System

From Embedded Systems Learning Academy
Revision as of 00:03, 27 May 2015 by Spa user4 (talk | contribs) (Design & Implementation)

Jump to: navigation, search

Grading Criteria

  • How well is Software & Hardware Design described?
  • How well can this report be used to reproduce this project?
  • Code Quality
  • Overall Report Quality:
    • Software Block Diagrams
    • Hardware Block Diagrams
      Schematic Quality
    • Quality of technical challenges and solutions adopted.

Wizard's Chess System

Abstract

The purpose of this project is to create an automated chessboard, displaying moves made by users playing chess. The web application server will be hosted on a Beaglebone Black. Users log in and play a chess game hosted using Node.js. As moves are made on the web app,the pieces will be physically moved on the chessboard.

Objectives & Introduction

Show list of your objectives. This section includes the high level details of your project. You can write about the various sensors or peripherals you used to get your project completed.

Team Members & Responsibilities

  • Yaron Alexandrovich
    • Case Design, XY Plotter driver on SJOne Board, FreeRTOS Environment
  • Emil Kurian
    • Case Design, XY Plotter driver on SJOne Board, FreeRTOS Environment
  • Gerard Ramos
    • Web Server, Case Design, Electromagnet, Chess Pieces
  • Fred Sun
    • Web Server, Case Design, Electromagnet, Chess Pieces

Schedule

Week Start Date End Date Task Status
1 3/27/2015 4/10/2015 Finish building XY Plotter Completed
2 4/12/2015 4/26/2015 Build casing and chessboard In Progress
3 4/12/2015 4/19/2015 Build/Control Electromagnet In Progress
4 4/12/2015 4/15/2015 Find/Buy appropriate magnets Completed
5 4/12/2015 4/19/2015 Write drivers for XY-Plotter Completed
6 4/12/2015 4/19/2015 Design web application GUI (Front-end) Completed
7 4/12/2015 4/26/2015 Host Web Server on Campus Completed
8 4/19/2015 4/26/2015 3D print chess pieces + attach magnets to pieces In Progress
9 4/19/2015 5/3/2015 Develop Web Server Back-end Completed
10 4/26/2015 5/3/2015 Write functions for plotter to move chess pieces In Progress
11 5/3/2015 5/10/2015 Setup communication protocol between SJOne and Web Server In Progress
12 5/3/2015 5/17/2015 FreeRTOS Environment In Progress
13 5/15/2015 5/23/2015 Debug, Debug, Debug In Progress

Parts List & Cost

# Item Cost Quantity Total Cost
1 XY Plotter $300 1 $300.00
2 Wood $10 3 $30.00
3 Polalu Stepper Drivers Please 2 Please
4 Perfboard .50 2 $1.00
5 BeagleBone Black 60 1 $60.00

Design & Implementation

Hardware Design

The chess game is hosted on a Beaglebone Black (BBB). The BBB is a open-source hardware single-board computer that runs an embedded Linux. The server back-end is powered by Node.JS, and ran as a local host such that any computer device can connect to it and play the game. As plays are made on the chess game, the changes in piece position are processed, and a string is transmitted over UART to the SJOne board. The SJOne interprets the string, and translates these to physical moves. By commanding the stepper motors and electromagnet, it moves chess pieces to reflect the changes made in game.

Hardware Interface

Hardware Interface Diagram. All components have common ground.

XY Plotter Hardware

XY Plotter with Board
Top View of XY Plotter
Close Up 1
Close up 2

Computer Aided Design Chess Pieces

Chess Pieces for the Board

Electromagnet

Electromagnet
Relay to Control when the electromagnet turns on and off
Custom Made Driver Motors for our board

Stepper Motor Driver

Front
Back

Software Design

Server-Side Software

Our software was a two pronged approach: a website built from nodeJS and hosted on the BBB as well as a stepper motor control system implemented on the SJOne.

Embedded Software

Stepper Motor Driver Stepper motors work by having four electromagnets that magnetically grip a bar. By flipping these magnets on and off in a circular pattern, the bar rotates. To control the magnets, we used Pololu amd20b drivers. These respond to a direction, and step signal. On each rising edge of the direction signal, the motor steps a designated step size. We chose 1/8 step.

To control the electromagnets at 1/8th step, a sine wave is passed through the electromagnets at a very specific rate. Feeding this sine wave too fast or too slow will fail to grip and step the stepper motor properly, so a perfectly calibrated feed rate is required.

Our driver consisted of a series of helper functions, as well as three main functions: set_position(x position, y position) set_target(x target, y target) dda_move(feedrate)

x position and y position are NOT tick locations. These represent physical locations in the X and Y grid. The helper functions convert these into number of ticks. The feedrate is the speed at which the sine wave is pulsed through the stepper motor to achieve 1/8th step twitches.

set_position stores a positional value that the plotter is currently at. set_target stores a value that the stepper motor wants to achieve. Then the number of steps for x and y to achieve this position are calculated. dda_move is the move function. This creates an x step and y step counter, then steps the x and y stepper motors until the counters are maxed out. Then the x position and y position are updated.

Using the set_target, set_position, and dda_move, move routines to move the pieces were coded.

Move Routines

moveToOrigin(): This moves the stepper motors to the origin.

moveToBoard(): This moves the stepper motors to the first square on the 8x8 chess board.

moveInGrid(x, y): This moves the stepper motors to the designated x and y position of the 8x8 chess board.

moveToPassingLaneX(): This moves a chess piece off the center of the square, so that it can navigate around other pieces.

moveToPassingLaneY(): Same, but for y-axis.

moveOffPassingLaneX(): Returns piece to center of grid from x-axis passing lane.

moveOffPassingLaneY(): Returns from y-axis passing lane.

moveToGraveyardB(): Once a piece is gripped, it moves that piece into the x passing lane, than carries it to its graveyard.

moveToGraveyardW(): Same, but for the white team's graveyard.

When a move is made on the hosted chess game, the move is generated as a string and passed into the SJOne board via UART. The string will be something like [M][A][2][C][5]. The first letter is the type of move it makes. Either moving a piece, or killing a piece. Then, positions two and three are the initial X and Y coordinates of the piece to move. Positions 4 and 5 are the final X and Y coordinates of the piece to move.

Once a command comes in, for example a move command, it executes a series of move routines. First, move to board buts the plotter in position [1][1]. Then, moveInGrid(initial X, inital Y) grips the piece to be moved. Then moveToPassingLaneX and moveToPassingLaneY positions the piece to move around other chess pieces. Then, moveInGrid(final X, same Y) is called to move to the proper X location. Then, moveInGrid(same X, final Y) is called to move to the final Y position. Then moveOffPassingLaneX and moveOffPassingLaneY centers the piece in its final resting location. Finally, moveToOrign is called, moving the plotter to its resting position.

Implementation

This section includes implementation, but again, not the details, just the high level. For example, you can list the steps it takes to communicate over a sensor, or the steps needed to write a page of memory onto SPI Flash. You can include sub-sections for each of your component implementation.

The chess game was implemented using Node.JS, hosted on a Beaglebone Black. To access the game, any internet device would connect to the local Wifi hosting the BBB, and enter the IP address into the address bar: 192.168.1.136:3030.

The Chess game compiles itself into a 64 character long string, describing the entire board. When a move is made, the change in positions are parsed out of the string, and a command is transmitted over UART to to the SJOne board. The SJOne uses UART2 to receive the signal. When a character comes in, an interrupt is thrown on the SJOne. As characters come in, a string is appended with the received character, until \n is received. Upon \n, the string is thrown into a que.

To service a string, the first character is examined. Depending on that letter, the matching set of move routines are called. The piece locations to be moved are parsed out of the string, and passed into the move routines, which include timed instructions to the stepper motors.

Therefore, the moves made in the chess game are physically expressed on the board.

Chess Board

The chess board was created from an XY Plotter. The electromagnet was attached to the plotter, and would move under the chess board in order to pick up and move pieces. The Chess board itself was made from wood, and laser cut to our specification based on the usable size of the XY Plotter. The plotter had a movable area of 11" X 15". So we made the chess board 10 X 10, with 1/2" margins on the X plane. 2 inch graveyards were at Y = 0 and Y = Max.

Stepper Motors

In order to use the stepper motors, 2 processes needed to occur. The first was setting the stepper motor driver. Our Drivers were the MD20B stepper motor drivers from Pololu, based on the DRV8825 IC from TI. In order to use these drivers, we had to manually set the step size and attach the power source we would be using. The logic was taken from the SJone, and the external power came from a 12V, 2A power supply.

Electromagnet

After, we worked on the electromagnet. The magnet was handmade with the turns being wound by the team and power coming from an external 12-24V, 5A power source.

Data Conversion

Our game was hosed on the BBB, but our plotter was controlled by the SJone. In order to figure out where to move the pieces, a UART driver had to be created in order to pass data from the BBB to the SJone. The UART driver was interrupt based and would take in 5 characters at a time. These characters would then be deciphered and used to figure out the new chess piece locations.

Based on the location data for the pieces, the SJone would then engage the stepper motors and move them to the desired locations. This feat was accomplished by creating a software driver for the XY Plotter on the SJone board itself. The software driver was then used to create various move functions to be carried out based on the data coming in from the BBB.

Chess Pieces

Our Chess Pieces were 3d Printed and then modified for our use. The Modification was to add in a small magnet inside the chess piece and then weight the piece with a nut and washer on the bottom. These modifications allowed for the pieces to be grabbed by our electromagnet while staying stable and not getting attached to one another.

Technical Challenges

Issue #1: Stepper Motor Drivers

As current flows into a stepper motor, it stores this energy in magnetic fields. The reverse is true. That is, when current is no longer supplied to the motor, the magnetic field collapses creating current, known as back EMF. The stepper motor drivers contain circuitry to protect itself from this back EMF. However, adjusting the current setting or unplugging the stepper motor driver while engaged WILL damage the driver.

Issue #2: Electromagnet

One of the other issues we encountered was with safety regarding the electromagnet, mainly due to heat, one of the things we wanted to calculate was how much current to run through the electromagnet in order to start moving pieces. As we were doing our test, the way that the electromagnet moved under the board scraped little pieces of wood on it. After a couple of minutes of testing we noticed smoke coming from the bottom of the board, at first we thought it was the electromagnet heating up the board way too much but actually the issue was the the little pieces of wood was going on the electromagnet, and due to the high amount of heat this caused the wooden dust to burn. After noticing this fire hazard we decided to not use the electromagnet anymore because it wasn't worth the risk if anything catching on fire.

Issue #3: Stepper Motor Calibration

The XY Plotter was purchased from MakeBlock. The kit included a portion of code to control the stepper motor. The code is originally written for the Arduino so it needed to ported over to the SJOne Board. However, once the code was ported over, there were several #defines and const variables on the Arduino side that did not match on the SJOne Board. We needed to calibrate the stepper so that it performs exactly how it does on the Arduino side.

Issue #4: Stepper Motor Timing

Stepper motors have to be perfectly timed. They store current flowing through them in a magnetic field, then a rising edge pulse switches the field from one electromagnet to the next. This timing cycle needs to be perfect. When FreeRTOS context switches the stepper motors are no longer receiving a current, and lose their magnetic fields. Then, the context switch back to the stepper driver re-engergizes them. This causes unpredictable, uncontrolled behavior, and the stepper motors stutter and struggle to move.

Conclusion

We set out to create a Chess Board that could move the pieces by itself based on a game being played online. Instead, we created a potential fire hazard. After realizing that we created a potential fire hazard, we changed around a few things and instead created what was originally intended, a Wizard's Chess System. The Wizard's Chess possesses the ability to engage multiple players and move the pieces across the board via magnets underneath, suggesting to an errant watcher that the board indeed is magical.

As mentioned before, there were a few hiccups like the potential fire hazard. Testing and debugging the chess board was its own task because of the drivers we created from scratch. The motor drivers weren't as robust as we would have liked, wasting time and resources just to replace the driver over simple issues. Not to mention the testing that had to be done each phase such as how much power was going into each component or making sure that all the hardware was aligned in order to ensure that the precision we needed was there to play the game.

Overall, it would seem that a lot of effort went into creating a "over-the-top" version of a simple game. However, the chessboard we created draws from the various lessons learned though this class the and years we have been in engineering. A UART driver was implemented between two microcontrollers and ensured that the transmissions were read and properly processed. A driver was created for the XY Plotter from scratch, with all locations being mapped and programmed accordingly. An electromagnet was created, and though ultimately scrapped, it was successful in its intended purpose. FreeRTOS was used to prioritize the tasks of our board in order to ensure that all necessary functions were carried out properly and efficiently. By working on this project, the gap between knowledge attained in class and the actual implementation of these lessons was bridged.

Project Video

Upload a video of your project and post the link here.

Project Source Code

References

Acknowledgement

Special thanks to Hugo Quiroz. He provided mechanical knowledge, access to laboratory and equipment, and dedication to our project. Thanks for the measures, cuts, materials, and laser cutter to etch our chess board.

Special thanks to Professor Peter Reischl. He went out of his way to educate us on constructing the electromagnet. Thanks for going out of your way to provide the knowledge and verification to construct our electromagnet.

References Used

List any references used in project.

Appendix

You can list the references you used.