Poznan's Deep Q-Network Beats Classical Control for Magnetic Medical Robots
A DQN agent learns to swing up and stabilize a rolling ellipse with tiny torques, beating a classical energy-shaping plus LQR baseline on most tasks.
ProTakeaways
- Poznan researchers frame magnetic-capsule control as an RL benchmark: rotate an elliptical cylinder with sub-millinewton-meter torque.
- A minimal DQN with three discrete actions and 64-unit hidden layers learns four rotation tasks between horizontal and vertical.
- RL beats a classical swing-up plus LQR baseline on ISE, ITSE, and settling time in nearly every configuration.
- Horizontal-to-vertical settling time drops from 1.45 s (classical) to 0.68 s (learned).
- Performance degrades sharply for heavier cylinders or high major-to-minor axis ratios above 34 mm.
- The agent easily releases potential energy but struggles to accumulate it, a general RL weakness.
Rolling an egg-shaped object to a specific orientation with a tiny amount of push sounds like a physics-class curiosity. But it turns out to be a surprisingly good stand-in for a real robotics problem: steering an untethered magnetic capsule inside the human body, where the actuating magnet sits far away and can only apply a whisper of torque. A team from Poznan University of Technology has now framed this as a reinforcement learning benchmark and shown that a plain Deep Q-Network can outperform the textbook control-theory answer.
The setup, described in their new paper, is inspired by systems like magnetically actuated laparoscopy cameras. A magnetic elliptical cylinder sits inside a tunnel made of a material that does not shield the magnetic field, such as rubber hoses, plastic pipes or vessels, and is driven by a moving electromagnet with controlled magnetic torque. Because the magnet is far away, torque is severely capped, which makes this an underactuated control problem in the same family as the inverted pendulum or acrobot.

Why an ellipse is harder than a ball
A ball rolls forever under any initial velocity. An ellipse, thanks to its non-uniform shape, has stable equilibria (lying on its long side) and unstable ones (balanced on its short end). The authors define four movement scenarios: vertical-to-vertical (half turn), horizontal-to-vertical, horizontal-to-horizontal, and vertical-to-horizontal. Two are easy because gravity does most of the work as potential energy is released. The two starting from horizontal are hard, because the controller must inject energy through a series of pushes to build up enough momentum to tip the ellipse over its unstable upright position, and then bleed off just the right amount to stop there.
The learner and its rulebook
The agent is deliberately minimal. Each network takes a 3-dimensional state vector containing the current angle, angular velocity, and target angle, and is built with three fully connected hidden layers of size 64, each followed by a ReLU activation. The final output layer produces Q-values for all 3 possible actions. Those three actions are a positive micro-torque of 10-3 Nm, its negative, or zero. Training uses the standard DQN toolkit: an online network plus a target network, an epsilon-greedy schedule decaying from 1.0 to 0.05, a replay buffer, and Adam at learning rate 0.001 with discount 0.99.
The reward is a scaled version of the Gymnasium pendulum reward. It penalizes deviations from the reference angle, excessive angular velocity, and large control torques. Crucially, the penalty terms are rescaled per task so that the reward surface looks similar regardless of how large a rotation is required, which prevents one task from being trivially easier to train than another.
Beating the classical baseline
The comparison target is a hybrid controller familiar to anyone who has studied underactuated pendulums: an energy-shaping swing-up law that drives the state toward the target equilibrium, then a Linear Quadratic Regulator obtained by linearizing the nonlinear model around the goal. Both controllers see the same torque limit and same physical parameters.
The learned policy wins on nearly every metric. On the horizontal-to-vertical task with default parameters, RL cut the integral squared error from 3.09 to 1.00 and the time-weighted version from 1.86 to 0.17. Settling times also drop significantly:
- Vertical to vertical: 0.72 s (SU) vs 0.81 s (RL)
- Horizontal to vertical: 1.45 s vs 0.68 s
- Horizontal to horizontal: 2.43 s vs 1.46 s
- Vertical to horizontal: 1.20 s vs 0.83 s

Where it breaks
The paper is refreshingly honest about failure modes. Stabilization in the upward position or rotating a half turn becomes very difficult as mass increases or when the ellipse has a strongly unequal perimeter ratio. With heavier cylinders (25 g vs 20 g) or more elongated shapes (a = 36 mm vs 34 mm), the agent needs more epochs to converge and the trajectory starts oscillating around the target instead of settling cleanly. There is also a subtle overtraining effect: models kept training for the full 1000 epochs actually regressed compared to the best snapshot taken mid-training.
What this is really useful for
Two takeaways matter beyond the specific benchmark. First, this is another data point showing that a vanilla DQN with a three-way discrete action space is competitive with carefully hand-designed hybrid controllers on a genuinely nonlinear, underactuated problem. That is relevant for anyone building magnetic capsule endoscopes, soft robotic actuators, or any system where you cannot freely apply large forces and analytical linearization only holds in a narrow band around equilibrium.
Second, the paper points to a broader pattern: reinforcement learning easily learns how to release potential energy but struggles to learn how to accumulate it to perform a control goal. Building potential energy requires deliberately moving away from the target first, a form of temporal credit assignment that stresses standard reward shaping. No code release is mentioned in the paper, and the authors note next steps include modeling viscous friction and validating on a physical laboratory setup, since the current formulation uses discrete non-continuous torque that is hard to produce with a real actuator.