This project compares a model-based Feedback Linearization Controller (FLC) with a model-free Soft Actor-Critic (SAC) reinforcement learning agent for the Gymnasium Reacher-v5 environment.
The objective is to move the endpoint of a two-joint robotic manipulator to a randomly generated target, stop the motion and maintain a stable position.
This project was developed and tested with Python 3.14.3.
All required Python packages are listed in requirements.txt.
pip install -r requirements.txtOpen main.py and uncomment the controller that should be used.
For example:
# controller = RandomController(...)
# controller = PDController(...)
controller = FeedbackLinearizationController(...)
# controller = RLController(...)Only one controller should be active at a time.
python main.pyA trained SAC model is already included in the repository and can be used directly by selecting the RL controller in main.py.
To train a new SAC model from scratch, run:
python train_rl.py An episode is considered successful when both conditions are satisfied:
for 20 consecutive simulation steps.
Where:
-
$d$ is the distance between the fingertip and the target, -
$\dot{q}$ is the vector of joint angular velocities.
The manipulator must therefore:
- reach the target,
- reduce its joint velocity,
- maintain the stable position for 20 steps.
Briefly passing through the target is not considered a success.
The two-joint manipulator is described by:
where:
-
$q$ is the joint position vector, -
$\dot{q}$ is the joint velocity vector, -
$M(q)$ is the inertia matrix, -
$C(q,\dot{q})$ represents Coriolis and centrifugal effects, -
$\tau$ is the control torque vector.
The Cartesian target is converted into a desired joint configuration using analytical inverse kinematics.
A third-order polynomial trajectory generates the reference position, velocity and acceleration:
The virtual acceleration is calculated as:
The Feedback Linearization control law is:
After ideal compensation of the nonlinear dynamics:
The resulting tracking-error dynamics are:
The final controller parameters were:
kp = 225.0
kd = 30.0
trajectory_time = 0.25The physical torque is converted into the MuJoCo actuator control input using the actuator gear ratio:
The selected reinforcement learning algorithm is Soft Actor-Critic.
The SAC training configuration can be found in train_rl.py.
The custom reward function is:
The reward contains:
| Component | Purpose |
|---|---|
| Encourages faster episode completion | |
| Penalizes distance from the target | |
| Broad bonus for approaching the target | |
| Precise positioning bonus | |
| Encourages the manipulator to slow down | |
| Rewards maintaining a stable position | |
| Final reward after satisfying the success condition |
The standard Reacher-v5 reward is completely replaced by this custom reward.
The final evaluation was performed over 1000 episodes.
| Method | Success rate | Average number of steps |
|---|---|---|
| Feedback Linearization Control | 99.5% | 49.209 |
| Soft Actor-Critic | 97.2% | 48.341 |
FLC achieved a success rate higher by 2.3 percentage points, while SAC completed successful episodes approximately 0.868 simulation steps faster on average.
Although FLC performed better in this experiment, SAC may be a more suitable choice for systems that are difficult to model accurately, contain complex nonlinearities or include unknown disturbances and constraints. In such cases, a model-free controller can learn the required behaviour directly from interaction with the environment without relying on an analytical dynamic model.
| Feedback Linearization Control | Soft Actor-Critic |
|
|
This project is licensed under the MIT License. See the LICENSE file for details.

