Skip to content

PyGame-based quadcopter simulator & Reinforcement Learning Project

License

Notifications You must be signed in to change notification settings

RsGoksel/Mechopter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reinforcement Learning Python Quadcopter Pygame PPO A2C DQN

Mech-opter 🎮

This repository provides code exercise and solution for Reinforcement Learning. All code is written in Python and uses custom RL environment from OpenAI Gym.

Goal was train the Reinforcement Learning Drone Agent mastering the flying and accurately hitting a target balloon. A2C was used primaly, PPO and DQN also can be used. Explanations and details are down below ↓

Game Screen (Before training, trained one is down below!)

Quad

Environment & Game Mechanism

Reward:

  • -score | Proportional to the distance to the target
  • Hitting the target is +score, & restart
  • Flying out of the game screen is -score & restart

Observation Space:

  • Agent Y Coordinate
  • Angle to Up
  • Velocity
  • Angular Velocity
  • Angle to Target
  • Angle Between Target and Velocity
  • Distance to Target

Action Space:

Action space is discrete(5). It means there is certain 5 moves the Agent has to do. Do Nothing, Up, Down, Right, Left


Files

  • test.py: Testing for the environment. You can display game screen.
  • train.py: Trains the Agent. You can change total_steps from Constants.py.
  • Agent.py: Drone class.
  • evaluate.py: Evaluate the trained model. Elaborated usage is at down below.
  • env.py : Environment class. You can alter the game rules, Reward mechanism etc.
  • Constants.py : Constant variables of the Game. Screen width, hyperparameters etc.

Install required libraries:

$ pip install -r requirements.txt

Test the environment and check everything is OK:

$ python test.py

Let's Train!

Default step is 300k. You can alter it from Constants.py
(Loading Libraries may take a while)

$ python train.py

Evaluting the Agent

! After the training, your model will be saved in 'models' file. Evaluate your trained model with adding --model parameter to terminal, Or use pretrained models Which in models folder. There is a already pretrained model which named "Crayz_bill" and it is default model.

$ python evaluate.py

If you would like to evaluate your custom model:

$ python evaluate.py --model models/yourmodel
$ python evaluate.py --model models/200k

After the Training 🦾

Quad

Releases

No releases published

Packages

No packages published