In our goal to create an AI powered air hockey opponent, we have developed a vision system, state machine, and robot interface so that the robot can play in real time against a human opponent.
First, you will need to install all necessary dependencies.
Run pip3 install pipenv
. pipenv
is used for Python package management.
Once downloaded, run pipenv install
. This will create a virtual environment for our application and will install the dependencies from the Pipfile.lock
file. If this is not present, it will default to the Pipfile
file.
We use YOLO2 and Darknet for the vision system. You will need to install CUDA 9.0
and cuDNN 7.0
. I would follow this tutorial to set this up on your machine.
You can either install redis via Docker or apt-get
. It is up to your preference.
There are a few steps you have to do to sync up the camera footage with the robot.
The html canvas and robot sets the origin point at the top left corner. However, the top left corner of the table in the footage is not the origin. Thus, you will need to compute the offset necessary to translate the frames up and left so that the top left corner of the table in the footage is the origin point.
It does not matter if Redis has already been started or not.
Make sure you are in your virtual environment. Run pipenv shell
to initiate you environment if you are not already in it.
- Grab a image from the source where your bot will be playing. This will be used to determine its location and dimensions.
- Run
python calibrate_offset.py --file <Your Image>
. This will grab the necessary information and publish it to redis to be used for later. - In
retrieve_state.py
, set your defaults. The table dimensions either user-defined. Other defaults are dependent on your table and specifications. Please play with these. - Run
retrieve_state.py
. This will we retrieve the state of the entire application. It will also compute where the robot should move to. All puck/bot physics or AI should be defined in themeet_the_puck
function. - In the
./simulator
, edit theindex.html
canvas componentswidth
andheight
attributes. Set these to the table dimensions. - In the same directory, run
npm start
to start simulator. Openhttp://localhost:3000
to see where the puck and bot is on the table. - Run
python yolo/table.py
to start recording the state of the game from the YOLO2/Darknet neural net.
Positronic Ai - Visit us at our website!