Package: robot-soccer-python
Robot soccer Pythonrobot_soccer_pythonis 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!InstallationTo install this project is very simple, you only need to write the command bellow in your prompt terminal:pipinstallrobot_soccer_pythonAnd that's it! Very simple, isn't it?UsageTo use, I need to explain the classes and methods that you will need.PoseThis class is used to write a position on the environment. To import you have to write:fromrobot_soccer_python.agentsPoseAnd you have to pass the position x, y and rotation in the plane xy for this class, likePose(x,y,rotation), remember, rotation is zero when the robot is turn to the positive sense of axis x and π in the negative sense.PlayerThis 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:fromrobot_soccer_python.agentsimportPlayerplayer=Player(Pose(3,3,0),2,2,0.2)Thefirst argumentis the initial position of the player, thesecondis maximum linear speed that this player will achieve, thethirdis the maximum angular speed and thelast parameteris the radius of the robot (because the robots are circles and you can change the size).simulation2DThis 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:fromrobot_soccer_python.simulation2Dimportsimulation2Dsimulation=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_simulationTo pass the frames of the simulation you only need to call this class. Like demonstrad bellow:fromrobot_soccer_python.simulation2Dimportinit_simulationinit_simulation(simulation)ExampleA example of a simple simulation is:fromrobot_soccer_python.simulation2Dimportsimulation2D,init_simulationfromrobot_soccer_python.agentsimportPlayer,Poseimporttimesimulation=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)whileTrue:iftime.time()-now>2:command1=(1+command1[0],1+command1[1])command2=(1+command2[0],-1+command2[1])now=time.time()iftime.time()-now2<3:simulation.set_commands([command1,command2])else:simulation.set_commands([command2,command1])iftime.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!SensorsThere 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 runsimulation.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.GoalLike 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.comIf 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.