A PyMunk physics simulation trained using Stable Baselines3 PPO to balance an inverted pendulum (cartpole system).
- Custom physics simulation using PyMunk
- Reinforcement learning with PPO algorithm
- Manual control mode for testing
- Visual rendering with Pygame
- Parallel environment training
- Reward shaping for better learning
- Python
- See requirements.txt for dependencies
pip install -r requirements.txtTrain the RL agent with default parameters:
python train.pyThe model will be saved to models/cartpole by default.
View a trained model in action:
python render_model.pyTo load a specific model:
python render_model.py models/my_custom_modelTry balancing the pendulum yourself:
python manual.pyThe controls work in both manual and rendering modes.
- Press mouse and move left/right to apply force proportional to mouse position
- Left/Right arrows: Move cart
- R: Reset simulation
- W/S/A/D/Q/E: Set pendulum to specific angles
- ESC: Quit
The reward combines:
- Upright position bonus (quadratic)
- Position penalty (keeps cart centered)
