Reinforcement learning and control from scratch
Exercises from June 2026. A hand-tuned controller, an optimal one and a learned one on the same cart-pole, REINFORCE, PPO and SAC written from scratch, and a LiDAR navigation task in simulation that mostly did not work.
Project facts
- What it is
- Study exercises with a write-up for each. Not research
- Evidence
- Single seeds and training returns, unless a line says otherwise
- Built with
- PyTorch, Gymnasium, NumPy, SciPy, ROS 2 Humble, Gazebo
- When
- Jun 2026
- Status
- Completed
- Page updated
Why this is here
Before the robot-learning projects I worked through the fundamentals by writing them myself. These are exercises, and the results are what an exercise produces: one seed, standard benchmarks, no claims beyond “it runs and I understand why”. I list what did not work as well.
Three controllers, one cart-pole
The same nonlinear cart-pole, started from a 0.2 rad tilt, balanced three ways: PID tuned by hand, LQR solved from the linear model, and a linear policy found by the cross-entropy method from reward alone.

| Controller | Cost | Peak force | Cost with a 50 % heavier pole |
|---|---|---|---|
| PID, tuned by hand | 1.624 | 12.00 N | 1.645 |
| LQR | 1.387 | 9.91 N | 1.415 |
| Learned, cross-entropy method | 1.417 | 11.94 N | 1.444 |
The learned controller ended within about 2 % of the optimal cost, with gains of the same shape as LQR’s, after thousands of simulated rollouts. LQR got there with one equation solved once. On a problem with a good linear model that is the comparison that matters.
Three algorithms, written out
- REINFORCE on LunarLander: training return from −200 to a peak of 208, ending at 133.
- PPO on LunarLander: three runs ended at 88, 72 and 173. On CartPole my implementation stayed below a reference library’s on the same task.
- SAC on HalfCheetah: a return of 5,495 after 150,000 steps. That is far from the state of the art.
All of these are training returns from single seeds, with no separate evaluation.
Navigation that mostly did not work
A goal-reaching task for the robot’s base in a Gazebo simulation, observing LiDAR ranges. I wrote the environment and the reward.
- PPO never reached the goal: 0 % success over 20 evaluation episodes, with a sparse reward and with a shaped one.
- SAC did better on an easier version of the task. My notes say 3 goals reached in 6 episodes, with a collision in half of them. I kept no log of that run.
- Nothing from this ran on the real robot.
A ROS 2 interface to the real base
An action server that takes velocity commands with a speed clamp and a safe mode that is on by default, an observation publisher, and a Gymnasium wrapper around both. It was exercised on the robot with a random agent for a few steps. It is plumbing.