Skip to main content
Open In Colab In the previous section, DDPG learned to reach the goal and then lost that skill again, while its critic predicted returns the robot never obtained. Twin delayed DDPG (TD3) (Fujimoto2018-uc) keeps the DDPG actor and critic and makes three changes aimed at that overestimation. In this section you add them, train on the same robot, and then use the trained agent to see how the reward weights shape its behavior. The section ends with what changes when the policy moves from this simulation to a real TurtleBot3.

Three changes to DDPG

The overestimation comes from the actor update, which acts as a max over noisy critic estimates. The actor moves its output toward actions where the critic’s value is high. Where the critic has an error that happens to be positive, the actor moves there and stays, and the bootstrapped targets yy then carry that error back to earlier states. Each change below removes one route for it.

Clipped double Q-learning

TD3 trains two critics, Qw1Q_{w_1} and Qw2Q_{w_2}, on the same targets, and builds the target from the smaller of their two target networks: y=r+γ (1−1[terminal])min⁡i=1,2Qwi′(s′,a~′).y = r + \gamma\,(1 - \mathbb 1[\text{terminal}]) \min_{i = 1, 2} Q_{w_i'}\big(s', \tilde a'\big). The same upward bias affects tabular Q-learning, whose target takes a max over noisy table entries. Double Q-learning (van Hasselt, 2010) removed it there with two tables: one picks the best next action, and the other evaluates it. TD3 adapts that idea to two critics and takes the minimum. An error that inflates one critic is unlikely to inflate the other at the same action, so the minimum tends to come out too low. A low bias is safer here: the actor avoids actions that look worse than they are, instead of seeking actions that look better.

Target policy smoothing

The next action in the target is the target actor’s output plus clipped noise, a~′=clip⁡(μθ′(s′)+clip⁡(ϵ,−0.5,0.5), −1, 1),ϵ∼N(0,0.22).\tilde a' = \operatorname{clip}\big(\mu_{\theta'}(s') + \operatorname{clip}(\epsilon, -0.5, 0.5),\ -1,\ 1\big), \qquad \epsilon \sim \mathcal N(0, 0.2^2). The critic then learns the value of a small neighborhood of actions, not of a single point. A narrow spike in QQ that the actor could exploit is averaged away. Both this change and the previous one alter only the TD target yy. The critics still minimize the squared TD error, as in DDPG.

Delayed policy updates

The critics update on every step, and the actor and all target networks update every second step. The actor then follows a critic whose errors have had time to shrink. Everything else, from the network sizes to the replay buffer, the exploration noise and the step sizes, is the DDPG setup of the previous section. The training function below marks the three changes.
Output from cell 6 Left: greedy success rate on 50 fixed episodes during TD3 training. Right: the first critic’s estimate of the start-state value and the return actually obtained. The success rate is zero for the first 30,000 steps, passes 0.9 at 60,000 steps, and stays between 0.94 and 1 from then on. From 30,000 steps on, the critic’s estimate stays below the return the robot actually collects. The minimum over two critics errs low, and a low estimate gives the actor no reason to move toward actions that only look good to the critic. On the 300 test episodes:
Output from cell 8 Left: the TD3 policy from the four starts used in every section. Right: its speed and turn-rate commands along the pink trajectory, each as a fraction of the Waffle’s limit. Three of the four starts reach the goal. From the bottom left start (green), the robot takes almost the same path as from the pink start and collides with the small obstacle at (3.0, 3.0), short of the goal. The value-iteration policy of the navigation MDP section reached the goal from all four starts, but only for one goal, with the true pose and a model of the dynamics. TD3 needs none of these: it works from the lidar and the goal’s relative position, for any goal in the room. From the pink start, the go-to-goal controller collided with the small obstacle at (3.0, 3.0). TD3 drives between the large obstacle and the small one at (2.8, 1.1), then passes below the obstacle at (3.0, 3.0) and reaches the goal from below. The commands on the right are continuous, but they are not smooth. The speed stays at its limit for the first 8 s and then drops several times, to about a third of its limit near 9 s and 10 s, as the robot turns toward the goal. The turn rate jumps between about −0.9-0.9 and +0.8+0.8 of its limit from one step to the next, even on the straight stretch. The reward penalizes turning only a little, and nothing in it penalizes a change of command, so the policy has no reason to be smooth. The simulator applies each command at once, so the jumps do no harm there. On a real robot the motors lag behind the commands, and the robot would shake. Navigation agents for real robots usually add a penalty on the change in ω\omega to the reward, or pass the commands through a low-pass filter.

The reward decides the behavior

The page that defined this MDP chose a collision penalty of 20 next to a goal bonus of 20. Here is the same training with the collision penalty raised to 200 and everything else unchanged:
Output from cell 10 The policy trained with a collision penalty of 200, from the same four starts. The agent mostly stops trying. Of the 300 test episodes, 85% end in a timeout, 10% in a collision and 5% at the goal. From the start on the right, below the goal, the robot reaches the goal. From the other three starts it drives part of the way and has not reached the goal when the 40 s run out. This is the best policy it found for the reward it was given. The likely reason is the balance early in training: random actions near obstacles end in collisions that now cost 200, while the goal bonus is still 20 and the robot rarely reaches it. Staying put costs only the time penalty of 0.01 per step, about 2 over a whole episode. Under this reward, doing nothing is a reasonable answer, and the agent never collects enough goal bonuses to learn otherwise. Nothing in the algorithm changed. One number in the reward moved the behavior from reaching the goal in 96% of the test episodes to 5%. The reward is part of the problem specification. The agent maximizes the return that this reward defines, whether or not that matches the behavior you wanted. In practice, reward weights for navigation are tuned the way any other hyperparameter is, by training and watching what the robot does.

From simulation to the robot

Everything above ran in a 2D simulation with perfect geometry. A policy trained this way meets several differences on a real TurtleBot3:
  • The lidar is noisy, drops returns on dark or shiny surfaces, and sees chair legs and people that are not disks.
  • The robot has inertia and motor limits, and its commands arrive with a delay, so (v,ω)(v, \omega) is not applied exactly or at once.
  • The goal’s distance and bearing come from odometry or localization, which drift and jump.
  • The room is new. The policy saw four fixed obstacles in a 4 m square.
The usual answers are a simulator closer to the robot, such as Gazebo with the TurtleBot3 model, which is what turtlebot3_drlnav uses, and randomization during training: random obstacle layouts, noise on the ranges and the commands, and random delays, so that the real robot looks like one more variation. Niu et al. trained a DDPG-based collision avoidance agent in Gazebo, added human teleoperation data to the replay buffer to cut the training time, and ran the trained policy on a real robot without further tuning (Niu et al., 2021). The state you used here, with lidar ranges, the goal’s distance and bearing, and the previous command, is the turtlebot3_drlnav state. Moving to the real robot therefore changes the environment the agent trains in, while the agent’s inputs, outputs and learning algorithm stay the same.

References

  • Niu, H., Ji, Z., Arvin, F., Lennox, B., Yin, H., et al. (2021). Accelerated Sim-to-real deep reinforcement learning: Learning collision avoidance from human player. arXiv [cs.AI]. Link

Found an error on this page? Report an issue.