Group Abstract Group Abstract

Message Boards Message Boards

[Hackathon] Tic-Tac-Toe with autonomous Delta Robot

Hello! Last weekend I was at a hackathon at Georgetown University where my team and I wrote a python program that allowed our home made delta robot to autonomously play tic tac toe with a human user. The Mathematica program I was working on was written to interface the arduino controlling the delta robot, and the python program which has the tic tac toe algorithm, by relaying information about the user input on the board through image processing.

enter image description here

The user input had to be from the computer however because I wasn't able to finish the image processing. The img was an image of the board taken by a logitech web cam attached to the main shaft of the robot. It didn't work reliably but did work generally.

Does anyone have a better way of doing this? Thanks!

P.S. here is the code: http://paste.ofcode.org/JCyYF2tJtpcmRta8YjMhmW

src = ColorConvert[img, "Grayscale"];
white = Closing[src, DiskMatrix[5]];
srcAdjusted = Image[ImageData[src]/ImageData[white]]
components = 
  ComponentMeasurements[
    ColorNegate@Binarize[srcAdjusted], {"ConvexArea", "Mask"}][[All, 
   2]];
largestComponent = Image[SortBy[components, First][[-1, 2]]]
mask = FillingTransform[Closing[largestComponent, 2]]
lY = ImageMultiply[
   MorphologicalBinarize[
    GaussianFilter[srcAdjusted, 3, {2, 0}], {0.02, 0.05}], mask];
lX = ImageMultiply[
  MorphologicalBinari   GaussianFilter[srcAdjusted, 3, {0, 2}], {0.02, 0.05}], mask]
verticalGridLineMasks = 
  SortBy[ComponentMeasurements[
      lX, {"CaliperLength", "Centroid", "Mask"}, # > 100 &][[All, 2]], #[[2, 1]] &][[All, 3]];
horizontalGridLineMasks = 
  SortBy[ComponentMeasurements[
      lY, {"CaliperLength", "Centroid", "Mask"}, # > 100 &][[All, 2]], #[[2, 2]] &][[All, 3]];
centerOfGravity[l_] := 
 ComponentMeasurements[Image[l], "Centroid"][[1, 2]]
gridCenters = 
  Table[centerOfGravity[
    ImageData[Dilation[Image[h], DiskMatrix[2]]]*
     ImageData[Dilation[Image[v], DiskMatrix[2]]]], {h, 
    horizontalGridLineMasks}, {v, verticalGridLineMasks}];
    Show[src, 
 Graphics[{Red, 
   MapIndexed[{Point[#1], Text[#2, #1, {1, 1}]} &, gridCenters, {2}]}]]


tr = Last@
  FindGeometricTransform[
   Extract[gridCenters, {{4, 1}, {4, 2}, {3, 1}}], {{0, 0}, {0, 1}, {1, 0}}]
ts = Last@
  FindGeometricTransform[
   Extract[gridCenters, {{3, 1}, {3, 2}, {2, 1}}], {{0, 0}, {0, 1}, {1, 0}}]
tt = Last@
  FindGeometricTransform[
   Extract[gridCenters, {{2, 1}, {2, 2}, {1, 1}}], {{0, 0}, {0, 1}, {1, 0}}]
tu = Last@
  FindGeometricTransform[
   Extract[gridCenters, {{4, 2}, {4, 3}, {3, 2}}], {{0, 0}, {0, 1}, {1, 0}}]
tv = Last@
  FindGeometricTransform[
   Extract[gridCenters, {{3, 2}, {3, 3}, {2, 2}}], {{0, 0}, {0, 1}, {1, 0}}]
tv2 = Last@
  FindGeometricTransform[
   Extract[gridCenters, {{2, 2}, {2, 3}, {1, 2}}], {{0, 0}, {0, 1}, {1, 0}}]
tw = Last@
  FindGeometricTransform[
   Extract[gridCenters, {{4, 3}, {4, 4}, {3, 3}}], {{0, 0}, {0, 1}, {1, 0}}]
tx = Last@
  FindGeometricTransform[
   Extract[gridCenters, {{3, 3}, {3, 4}, {2, 3}}], {{0, 0}, {0, 1}, {1, 0}}]
tz = Last@
  FindGeometricTransform[
   Extract[gridCenters, {{2, 3}, {2, 4}, {1, 3}}], {{0, 0}, {0, 1}, {1, 0}}]
pics = {ImageTransformation[src, tr, {200, 200}, DataRange -> Full, 
   PlotRange -> {{0, 1}, {0, 1}}], 
  ImageTransformation[src, ts, {200, 200}, DataRange -> Full, 
   PlotRange -> {{0, 1}, {0, 1}}], 
  ImageTransformation[src, tt, {200, 200}, DataRange -> Full, 
   PlotRange -> {{0, 1}, {0, 1}}], 
  ImageTransformation[src, tu, {200, 200}, DataRange -> Full, 
   PlotRange -> {{0, 1}, {0, 1}}], 
  ImageTransformation[src, tv, {200, 200}, DataRange -> Full, 
   PlotRange -> {{0, 1}, {0, 1}}], 
  ImageTransformation[src, tv2, {200, 200}, DataRange -> Full, 
   PlotRange -> {{0, 1}, {0, 1}}], 
  ImageTransformation[src, tw, {200, 200}, DataRange -> Full, 
   PlotRange -> {{0, 1}, {0, 1}}], 
  ImageTransformation[src, tx, {200, 200}, DataRange -> Full, 
   PlotRange -> {{0, 1}, {0, 1}}], 
  ImageTransformation[src, tz, {200, 200}, DataRange -> Full, 
   PlotRange -> {{0, 1}, {0, 1}}]}
   find[img_] := 
  (croppy = ImageCrop[img, {180, 180}];
   bin = ColorNegate@
     Binarize[ImageAdjust[GaussianFilter[croppy, 5]]];
   components = 
    ComponentMeasurements[
     bin, {"Centroid", "Area", "FilledCircularity", 
      "EquivalentDiskRadius"}, #2 > 100 &]; 
   Show[croppy, 
    Graphics[{Thick {If[#[[3]] > 0.5, Red, Blue], 
          Circle[#[[1]], #[[4]]]} & /@ components[[All, 2]]}]] );
POSTED BY: Jenny Mandl
2 Replies
Attachments:
POSTED BY: Garrett Ducharme

Hello, I edited the post. The python was the tic tac toe algorithm and the goal was to have mathematica interface between the python and the arduino controlling the delta robot which is a 3 axis arm typically used for pick and place operations in manufacturing (we made a fully functioning one with 3D printed parts and stepper motors)

POSTED BY: Jenny Mandl
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard