This repository contains reinforcement learning (RL) experiments and exercises, with a focus on creating and solving custom environments tailored for robotic learning and social navigation.
We design custom environments inspired by the Gymnasium environment creation tutorial, extending its ideas to support continuous state and action spaces. Force-based dynamics, similar to those found in the CartPole environment, are used for agent control.
-
Fixed Target (
fix_target.py)
The agent must navigate to a static target location. The goal remains unchanged. -
Any Target (
any_target.py)
The agent must reach a randomized target location that changes each episode. -
Socially-Aware Environment (
social_env.py)
The agent operates in a space with moving pedestrians, each with a personal discomfort function based on the work of Kirby (2010). This function models how uncomfortable a person feels as the robot approaches, depending on proximity and orientation.The agent must:
- Reach the randomized target,
- Avoid collisions with people,
- Minimize social discomfort, navigating in a human-aware way by learning socially compliant paths.
We compare two reinforcement learning methods:
-
Basic Q-Learning
- Suitable for smaller, discrete state/action problems.
- Solves:
Fixed TargetandAny Target.
-
Deep Q-Network (DQN) — powered by Stable-Baselines3
- Solves: All environments, including the socially-aware one.
To apply Q-learning to the Fixed Target and Any Target environments, discretization is used to convert the continuous state space into a finite set of states for the Q-table. For the Fixed Target environment, the algorithm was tested on a 10×10 map. In the Any Target environment, it works only on smaller maps, such as 5×5. However, results may not be optimal, particularly in the Any Target case—since better performance would require finer discretization and more extensive training as Q-learning is not well-suited for high-dimensional/continuous problems.
- Open the
tests/QLearning.pyscript. - Choose either
fixed_targetorany_targetin the script. - Run the file.
We use a Deep Q-Network (DQN) implementation based on the Stable-Baselines3 library to solve all environments, including the socially-aware one. Unlike basic Q-learning, DQN uses a neural network to approximate the Q-function, making it more suitable for environments with continuous or high-dimensional state spaces. It consistently achieves better results than Q-learning, especially in more complex tasks like socially-aware navigation.
Use the DQN.py script inside the tests/ folder:
- Open the
tests/DQN.pyscript. - Choose either
fixed,anyorsocialin the script. - Run the file.
The scripts QLearning.py and DQN.py include user-defined parameters that control the environment, rendering, and other settings. You can modify these at the top of each script.
-
ENVIRONMENT: Choose which environment to train/test on.
Options:"fixed","any", or"social" -
RENDERING: If set toTrue, the simulation will visually render each step using pygame (useful for debugging or demonstrations). -
TRAINING: Set toTrueto train a new model. IfFalse, the script will load a pre-trained model for testing. -
N_TIMESTEPS: The number of timesteps used for training the agent. (DQN ONLY) -
N_TESTS: The number of test episodes to evaluate the trained model (only used whenTRAININGis set toFalse). (DQN ONLY) -
TABLE_FILE: The filename used to save/load the Q-table when training is disabled. (Q-Learning ONLY) -
N_EPISODES: The total number of training episodes to run. (Q-Learning ONLY)