Teaching My Robot Arm to Pick and Place with Reinforcement Learning
SAC vs PPO on a custom 6-DOF arm in PyBullet
For my reinforcement learning class (CS 5180), I trained my own 6-DOF robot arm to pick up a cube and place it on a target, entirely in simulation. I compared two popular deep RL algorithms, Soft Actor-Critic (SAC) and Proximal Policy Optimization (PPO), against a scripted controller that knows exactly where everything is.
SAC came out well ahead. At their best checkpoints, all five SAC runs succeeded 91 to 100% of the time, and three of them kept that to the end of training. PPO learned the task on only one run out of five. This page covers how I built the environment, the results, and what the training logs show about why runs failed.
Why Build My Own Environment?
Most RL manipulation research uses ready-made environments for well-known robots like the Franka Panda, with the rewards and observations already tuned. My arm is my own design, and its robot description (URDF) was built alongside the real hardware so that a trained policy could one day run on the real arm. That meant there was no pre-tuned environment to use. I had to build the simulation, the reward function, the observations and the actions from scratch, and getting those right turned out to be most of the project.
The Environment
The simulation runs in PyBullet, wrapped in the standard Gymnasium interface. To keep the problem small enough to train on a laptop, I simplified the task:
- The cube is a 3 cm cube that spawns at a random spot on the table.
- The target is a fixed spot on the table.
- The arm starts 16 cm directly above the cube, with the gripper open.
- Success means releasing the cube within 5 cm of the target.
- Grasping is simplified. When the gripper closes and both fingers touch the cube, the simulator locks the cube to the gripper. It doesn't model friction holding the cube.
What the agent sees
The agent gets a 10-number observation every step:
- Where the gripper is: the \((x, y, z)\) position of the gripper's tool center point (3 numbers)
- Whether it's holding the cube (1 number, read from the simulator)
- Where the cube is, relative to the gripper (3 numbers)
- Where the target is, relative to the cube (3 numbers)
What the agent controls
The agent outputs 4 numbers between −1 and 1: \((a_x, a_y, a_z, a_{\text{grip}})\). The first three move the gripper by up to 5 mm in each direction, and the sign of the fourth opens or closes the gripper. An inverse kinematics solver turns the target gripper position into joint angles every step, and keeps the gripper pointing straight down.
I started out letting the agent control the joint speeds directly, but that space was too big and the agent never learned anything useful. Switching to moving the gripper in \(x\), \(y\), \(z\) made the problem much smaller and lined the actions up with the task, and the agent started learning right away.
The reward
Before the agent grabs the cube, it's rewarded for getting the gripper closer to the cube. While it holds the cube, it's rewarded for getting the cube closer to the target:
On top of that:
| Event | Reward |
|---|---|
| Every step | −0.02 |
| First grasp of the episode | +5 |
| Each step holding the cube | +0.01 |
| Release within 5 cm of the target (episode ends) | +50 |
| Release anywhere else | −3 |
| Arm or gripper touching the floor, per step | −1 or −0.5 |
| Arm hitting itself (episode ends) | −20 |
| Hints before the first grasp: far from the cube with the gripper open / close to it and closing / close to it and open | +0.01 / up to +0.02 / −0.02 |
My first version penalized the absolute distance to the goal, and the agent learned to hover next to the cube without grabbing it, collecting reward just for being close. Rewarding progress instead fixed that for SAC. As it turned out, the small hint terms brought a version of the problem back for PPO (more on that below).
Episodes
An episode ends on success, when the arm hits itself, or after 150 steps. Dropping the cube doesn't end it, so the agent can try to grab it again.
Getting the physics to behave
PyBullet kept reporting contacts that weren't really there on the gripper's sliding fingers, which ended episodes for no reason. The fingers were using detailed mesh models for collisions. I replaced them with simple boxes, and the phantom collisions went away.
How the environment changed
| What | Change | Why | Result |
|---|---|---|---|
| Actions | Joint speeds → gripper \(x\), \(y\), \(z\) moves | Agent couldn't learn in the larger space | Learned from scratch |
| Reward | Absolute distance → progress | Agent hovered next to the cube | SAC stopped hovering |
| Dropping the cube | Ends episode → doesn't end episode | Agent couldn't recover from a bad grasp | Recovers from failed grasps |
| Collisions | Meshes → simple boxes | Phantom collisions ended episodes | Stable contact physics |
The Two Algorithms
Soft Actor-Critic (SAC)
SAC is an off-policy algorithm, which means it saves past experience in a replay buffer and keeps learning from it. It also tries to act as randomly as it can while still doing the task, which keeps it exploring instead of locking into one behavior too early. A temperature setting \(\alpha\) (the entropy coefficient) controls how much it cares about randomness compared to reward. Its two Q-networks are trained toward this target:
where \(\tilde{a}'\) is an action sampled from the current policy and \(d\) marks the end of an episode.
Proximal Policy Optimization (PPO)
PPO is on-policy. It collects a batch of experience with the current policy, updates the policy, and then throws that data away. To keep any single update from changing the policy too much, it clips the ratio \(r_t(\theta)\) between the new and old policies:
where \(\hat{A}_t\) is how much better an action was than expected, and \(\epsilon\) sets how far the ratio can move. I also used a KL-divergence limit, which stops an update early if the policy changes too much.
The baseline
I also wrote a scripted controller that reads the exact positions of the cube and the target from the simulator. It runs through six steps (hover, descend, close, lift, transport and release), using the same 4-number actions as the RL agents.
Training Setup
I used the SAC and PPO implementations from Stable-Baselines3. Both used neural networks with two hidden layers of 256 units, and both normalized their observations and rewards. I trained five runs of each algorithm with seeds 1 to 5. During training, each run was tested every 10k steps on 20 episodes, and the best checkpoint was saved. At the end, I tested every best checkpoint, and the final weights, on 100 fresh episodes without action noise.
| Setting | SAC | PPO |
|---|---|---|
| Learning rate | 3e-4 | 3e-4 |
| Batch size | 256 | 256 |
| Discount \(\gamma\) | 0.98 | 0.99 |
| Entropy coefficient | 0.01 (fixed) | 0.01 |
| Replay buffer | 500k | None |
| Steps per update | n/a | 512 × 8 parallel envs |
| Epochs per update | n/a | 10 |
| Clip range / target KL | n/a | 0.2 / 0.05 |
| Total timesteps | 700k | 2.5M |
Results
| Run | Best checkpoint | Final weights |
|---|---|---|
| Scripted controller | 81% (grasps 99%) | |
| SAC seed 1 | 98% | 0% |
| SAC seed 2 | 99% | 100% |
| SAC seed 3 | 100% | 98% |
| SAC seed 4 | 99% | 100% |
| SAC seed 5 | 91% | 0% |
| PPO seed 1 | 97% | 97% |
| PPO seed 2 | 0% | 0% |
| PPO seed 3 | 0% | 0% |
| PPO seed 4 | 0% (grasps 97%) | 0% (grasps 90%) |
| PPO seed 5 | 0% | 0% |
| Seeds that solved it | SAC 5 of 5, PPO 1 of 5 | SAC 3 of 5, PPO 1 of 5 |
Success rates over 100 test episodes. At its best checkpoint, SAC averaged 97.4% and finished in about 48 steps. Two SAC runs, seeds 1 and 5, collapsed during training and ended at 0%. SAC seed 5's best checkpoint comes from only 70k steps in, before its collapse.
One detail of the test loop: Stable-Baselines3 resets the environment by itself at the end of each episode, and my loop reset it again. So the RL agents were tested on every other starting setup, not the same 100 as the scripted controller. Testing them on exactly the same setups changes every result by 3 points or less.
What Went Wrong, and Why
The training logs and checkpoints show what was behind each of these results.
The scripted controller missed because it steered the wrong point
The scripted controller grabbed the cube 99% of the time but only placed it 81% of the time. It wasn't the cube's size, which never changes. In 18 of its 19 failures, the controller put the gripper within 2 mm of the drop point, but the cube was 4 to 9 cm off target. The simulated grasp locks the cube wherever it happens to be when the fingers close, and in some grasps that's about 5 cm above the gripper's tool point. The controller steers the tool point, while SAC sees the cube's actual position, so SAC corrects for it. Beating the controller says more about its bug than about SAC. If it steered the cube instead, it should get close to 100%.
SAC's collapses came from its critic
Every SAC collapse lines up with the critic's loss blowing up. Seed 5's went from 0.07 to about 9,000, seed 1's to about 700, and seed 4's to about 50 before it recovered. That points to the value estimates becoming unstable, rather than the policy simply running out of exploration.
Changing the entropy coefficient
I also trained SAC with a higher entropy coefficient, 0.05 instead of 0.01. None of those five runs collapsed, but none scored above 49% in the 100-episode tests either, even without action noise. Those runs trained for 500k steps instead of 700k, and 3 collapses out of 5 against 0 out of 5 isn't conclusive with this few seeds. Still, the lower setting reached a much better policy, but less reliably.
PPO got stuck hovering just outside the hint zone
The three PPO runs that never grabbed the cube all did the same thing: they never closed the gripper, and they stopped 5.2 to 5.3 cm from the cube. That's right at the edge of the 5 cm zone where my hint terms change. Outside the zone with the gripper open, the agent loses 0.01 per step. Inside it with the gripper open, which is how you have to approach a cube, it loses 0.04 per step. Hovering just outside the zone is a local optimum that my own hints created. Their action noise also shrank to about 0.3 early in training, so they stopped exploring. The one PPO run that succeeded kept its noise around 1.0. Seed 4 got further: it learned to grab the cube but never to place it.
The "reward sensitivity" experiment changed more than the reward
I also tried PPO with a slightly different reward: a smaller floor penalty and simpler hints. In that experiment, I had also raised PPO's entropy coefficient from 0.01 to 0.05 and trained for 4M steps instead of 2.5M. With the higher entropy bonus, PPO's action noise grew without limit, from about 5 to over 108. Two runs looked like they learned the task and then forgot it. In fact, only their noisy training behavior ever worked: tested without noise, those runs never got above about 55%, and their final weights scored 0%. The collapse came from the noise blowing up, not from the reward change. I also never ran SAC with this reward, so the experiment doesn't compare the two algorithms.
Comparing with published work
Lobbezoo and Kwon (2023) found the opposite on a Panda arm, with PPO beating SAC (85% vs 71%). Their PPO, though, needed 8.3M steps, hyperparameter sweeps, high entropy settings and 5- to 7-layer networks. Mine had 2.5M steps and no tuning, which is enough to explain the difference.
What I'd Change
- Fix the scripted controller so it steers the cube instead of the gripper, so it's a fair baseline.
- Remove the hint terms, or redesign them so approaching the cube with the gripper open isn't penalized.
- Let SAC tune its own entropy (
ent_coef="auto"), and limit how large PPO's action noise can grow. - Pick checkpoints more carefully, since two SAC runs only look good because their best checkpoint was saved before they collapsed, and fix the double reset in the test loop.
- Make the task harder before claiming it generalizes: randomize the target and the starting pose, and grasp with friction instead of locking the cube on.
- Run it on the real arm. The simulation was built from the real arm's design for exactly this.
Conclusion
On this simplified pick-and-place, SAC reached about 99% on all five seeds and kept it on three. PPO learned it on one. The bigger lesson came from the logs: most of the failures traced back to choices I made in the environment and the experiments, not to the algorithms. The controller steered the wrong point, my reward hints created a trap, and one experiment changed two things at once. Most of my time went into environment design, and that's also where most of the problems were.
Thanks for reading!