Wednesday, 10 August 2011

Documentation

Here is the list of documents and files made for the project, available on Google Docs in "Croquet Project Management" collection :
  • Code comments ( in the code ) (DONE)
  • Studentship report, actually made for my school (DONE)
  • FinalPresentation, slides for Friday's prensetation (DONE)
  • Configure&Use API, document made to explain how to setup camera and robot connection, and how to use the API (DONE)
  • Familiarize  with code, document made to explain with more details the role of each class, the "logic" of software programming, and some important points to know which could solve some futur bugs (DONE)
  • A Video Presentation to show the Lego robot on the board with the camera, moving manually and the AI. (DONE)

About school presentation, as it must only last 10 minutes ( around 9 if video is taken into account ), the slides will contain much less information, so i don't plan to upload them.

Tuesday, 2 August 2011

Platform / Reality Calibration

As I said before, the calibration isn't perfect :  if you move the robot manually too much time, the position difference with the platform may become bigger and bigger. However, enough calibration was made especially for the AI, so that it cans cross hoops in reality like on the platform.

  • Board
The board on Swing interface has the the same ratio width/height (1.333 ) than in reality, and, luckily, this is the same on camera snapshots :
Snaphots : 640px * 480px
Real board : 235cm * 174cm
Platform : 940u * 696u   ( u = swing units, here 1cm = 4u )
  • Elements
Elements were measured in order to be closer to reality.
  • Commands
The parameters you type must be entered with real units, this is the software which converts them into swing units for the platform.
So, used units are : cm, seconds, degrees.

Monday, 1 August 2011

API Control Panel

The Graphic Interface of the API uses the basic platform GUI, and also includes the Croquet Application pannel. On the bottom, some elements have been added :


First, a tabbed pane enables you to switch from platform view to the last snapshot saved. It can be useful to make sure image processing worked well.

Some buttons have been added to control the API :

Place Hoops & Peg :
Take a picture and position hoops/peg founded. You can press it at any time, but make sure the robot and balls are properly removed from the board, or it won't work.
Place Robot & Balls :
Available once you position hoops. Place initial position of robot and balls

AI Button Play :
Available only if the current player is not manual. Make the AI play. ( It could be done automatically like on the platform, but for a demonstration software I think it's better to be able to control everything yourself).


For the moment, hoops crossing detection, roquet, succession of turns,... is entirely based on what happens on the platform. For exemple, you may cross a hoop on the platform, whereas the real robot missed it. So, the software will suppose you've reached a hoop and earn an extra strike, even if it's wrong.
The corrective panel is here to correct mistakes made by the software.

Skip a Turn :
Skip current player's turn. Notice that each time you start a new turn, robot and balls positions are automatically recalculated with the camera.
Replace Robot & Balls :
If the difference between reality and platform is too big, you may want to replace robot and ball
( Warning : the button "Place Robot and Balls" do the same thing, but it automatically skips the current turn ).
Next Hoop Corrections :
Two fields to correct hoop crossing errors. Press "enter" after writting the value. The Peg is identified as hoop number 7.

Image Processing - Part 2/2

Here is the last part of  Image Processing feature.
It deals with  :
  • Robot location
  • Hammer location and calculation of robot's direction angle
  • Balls identification ( with a white and a black ball )
--------------------
  • Robot location




Each time you need to, you can find new positions of robot and balls without dealing with hoops.








  So, the first thing to do is to binarize your snapshot, and substract from it the binarized picture of hoops and peg. You have to remove sides of the board with this technique as well, because you can't use the "side eraser" mask here : indeed, balls/robots may be next to a corner, and you may remove them doing this.

At this point, you can clean the image by filling holes, and using Open on the image to clean it.
Then, detecting the robot, biggest element, is easy using enough Erositons and then Reconstructions by dilatation. 
The important point here is that hammer must be removed as well, because this will be used after.
Like before, finding extremas gives you the robot location.

  • Hammer location and calculation of robot's direction angle


Now you can remove the robot from the initial image.
You'll get an image with balls and the hammer.
As the hammer is thinner, you can get it by :
  1. Removing it from the image with erosion.
  2. Substracting the balls image from the initial image to get the hammer alone.
A dilatation may be needed here to get the hammer as a single element.






Now you've got the location of the robot, O, and a point on the hammer, B. With arctan function, you can get the value of a angle.

Depending on the result of image processing, B is not necesserally the middle of the hammer, so you can't measure AB distance. However, OA lenght can be measured ( 7.8 cm on my robot ).

So, as you know OB and OA, you can calculate b angle :   b = arcsin(OA/OB)
where OA and OB can have negative values.

The direction angle you're looking for is direction angle = a - b

  • Balls identification ( with a white and a black ball )

Now, take again the image with the two balls, use it as a mask on the camera snapshot saved, you'll get the image with the two balls only.

Here, use binarization, and an open to get rid of the white ball.
Here you've got the black ball location.
Substract it from the image with the two balls to get the white ball location.

--------------------------------------------
Image Processing Results ( Average values ) :
  • Hoops & Peg Detection :  787ms
  • Robot & Ball Detection : 963ms
So, if you plan to make some image processing in real time into the future, you may have to improve it first.