A robot soccer simulation 2D environment for python.
Project description
Robot soccer Python
robot_soccer_python is a robot soccer simulation 2D environment for python. I create this project to study AI applied to robot. With this project, you will need only programming the robots' brain. Lets take a look bellow how to install and use this open-source project!
Installation
To install this project is very simple, you only need to write the command bellow in your prompt terminal:
pip install robot_soccer_python
And that's it! Very simple, isn't it?
Usage
To use, I need to explain the classes and methods that you will need.
Pose
This class is used to write a position on the environment. To import you have to write:
from robot_soccer_python.agents Pose
And you have to pass the position x, y and rotation in the plane xy for this class, like Pose(x,y,rotation)
, remember, rotation is zero when the robot is turn to the positive sense of axis x and π in the negative sense.
Player
This class is used to get and set all the information about the robots. To import this class and initialize a player you have to do:
from robot_soccer_python.agents import Player
player = Player(Pose(3, 3, 0), 2, 2, 0.2)
The first argument is the initial position of the player, the second is maximum linear speed that this player will achieve, the third is the maximum angular speed and the last parameter is the radius of the robot (because the robots are circles and you can change the size).
simulation2D
This class is the most important class that you will need. In this class you will configure the parameters of the simulation, like the list of players and you will get the information about the sensors of the robots. To configure the simulation, you have to do:
from robot_soccer_python.simulation2D import simulation2D
simulation = simulation2D([
Player(Pose(3, 3, 0), 2, 2, 0.2),
Player(Pose(6, 3, 0), 2, 2, 0.2)],
shockable=True,
full_vision=False)
The first argument is the list of players, the second is if you want that the robots can shock with each other (Like the Pauli exclusion principle "two bodies cannot occupy the same space") or if you don't want this physic principle. The last argument is if you want that the robots will see all in the environment, or if they will see only the the field and players in their field vision. To get the information about the sensors of all the players, you have to do:
simulation.get_sensors()
init_simulation
To pass the frames of the simulation you only need to call this class. Like demonstrad bellow:
from robot_soccer_python.simulation2D import init_simulation
init_simulation(simulation)
Example
A example of a simple simulation is:
from robot_soccer_python.simulation2D import simulation2D, init_simulation
from robot_soccer_python.agents import Player, Pose
import time
simulation = simulation2D(
[Player(Pose(3, 3, 0), 2, 2, 0.2),
Player(Pose(6, 3, 0), 2, 2, 0.2)],
shockable=True,
full_vision=False)
now = time.time()
now2 = time.time()
command1 = (0, 0)
command2 = (0, 0)
while True:
if time.time() - now > 2:
command1 = (1 + command1[0], 1 + command1[1])
command2 = (1 + command2[0], - 1 + command2[1])
now = time.time()
if time.time() - now2 < 3:
simulation.set_commands([command1, command2])
else:
simulation.set_commands([command2, command1])
if time.time() - now2 > 5:
now2 = time.time()
init_simulation(simulation)
player_sensors = simulation.get_sensors()
Just copy and past after the installation and see what happen!
Sensors
There are 40 points in the soccer field in the contour and the robots can calculate the distance between they and those points, that is the sensors. They can calculate the distance beetween they and other players too, if they are in their field od vision, of course.
I draw the line of vision of the robot to explain how they can see. Below I draw black lines for vision of points on the field and write line for vision of other robot. If the robot cannot see, the data will be infinite.
On the image bellow the red robot cannot see the yellow robot, so there aren't a write line and when you run simulation.get_sensors()
the data for the other player's distance will be infinite.
But on the image bellow the red robot can see the yellow robot and there are write line.
Goal
Like the real soccer, if the ball achieve the crossbar, the scoreboard will update and the robots and the ball will replace to the init position.
Did you have any problem?
If you get any problem, please contact me: jonysalgadofilho@gmail.com
If you like to contribute, please do it! I will like so much, I did this project to help me to study AI and I think that can help you, as well.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file robot_soccer_python-1.0.7-py2.py3-none-any.whl
.
File metadata
- Download URL: robot_soccer_python-1.0.7-py2.py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | acecd55df2bf62d632c85dafa13bac913c3d4c83b23fca269e4fb6d4f23ed150 |
|
MD5 | 98eae846a55c28701a441aa5b3f2076f |
|
BLAKE2b-256 | 906a43158bea43eafdb60b10bfe9f565855d9c47552c6f6fd4559c4d05fa2808 |