Skip to content

feat!: unified controllers - #353

Open
juelg wants to merge 39 commits into
masterfrom
feat/controller-interface
Open

juelg wants to merge 39 commits into
masterfrom
feat/controller-interface

Conversation

@juelg

@juelg juelg commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

No description provided.

juelg added 30 commits November 20, 2026 16:45
Header-only interfaces in the core package. Nothing uses them yet.
Run sim controllers in a control hook between mj_step1 and mj_step2, since
callbacks now run after integration. Use MuJoCo gravity compensation in place
of the Franka firmware. Drop the Coriolis step and the torque limit question,
both are fixed on master.
Both backends fill ControllerState with a shared PinocchioDynamics instead of
MuJoCo and franka::Model. The FR3 controllers then need nothing from libfranka
and move to core, so the sim can use them without rcs_fr3.
The sim backend adds PinocchioDynamics gravity for the arm plus the configured
payload, as the firmware does, instead of using MuJoCo gravcomp. A wrong tool
configuration then acts on the simulated arm as it does on the real robot.
Use the FR3 MJCF without armature as the model, which matches the URDF both
of our robots report.
With the state coming from PinocchioDynamics, the controller no longer needs
MuJoCo quantities from between mj_step1 and mj_step2, so Sim needs no control
hook. Clarify the step 3 and step 5 tests.
Segments have a fixed duration and start at the current setpoint. An optional
duration on set_goal overrides it for one goal, e.g. for the slow approach
when control starts far from the goal.
Linear interpolators only, 1 ms timestep in torque-controlled sim scenes,
segments start at the current setpoint.
Each goal starts a segment from the current setpoint that moves with constant
velocity over a fixed duration, with slerp for the orientation, then holds
the goal. Time advances only through the dt passed to step().
Computes mass matrix, Coriolis, gravity, TCP Jacobian and TCP pose for one arm
like libfranka's franka::Model: the payload is added to the flange body, joint
armature is ignored. Matches MuJoCo on the FR3 model to 1e-8.
Move the shortest-path rotation vector from the linear interpolator to utils.h,
so that the OSC can use it too.
JointPD is a joint-space PD around the interpolated setpoint with velocity
feed-forward. OSC is decoupled operational-space control, critically damped,
with a posture task in the dynamically consistent null space. Both add the
Coriolis torque.
Use the full 6x6 task-space inertia instead of separate position and
orientation inertias. The cross terms of the decoupled form slowed convergence
for combined translation and rotation: on a plant equal to the controller
model, an 11 cm / 13 degree move took 4 s instead of 1 s.
With PinocchioDynamics and a joint and/or Cartesian controller installed, the
arm actuators become motors and a per-step callback applies the controller
torque plus gravity from the configured payload, as the firmware does. MuJoCo
gravity compensation is switched off for the robot. Without a configured
payload the MJCF bodies after the flange are used, and a configured payload
that differs from them is reported.
FR3JointController and FR3OSC are the control laws of Franka::joint_controller
and Franka::osc, moved out of the libfranka loop: same gains, residual mass,
null-space posture, joint-limit avoidance and guard, deadband, torque rate
limit and clip. Dynamics come from the ControllerState, and the rate limit
uses the controller's previous output, so the sim can run them too.
Franka::osc and Franka::joint_controller now step FR3OSC and
FR3JointController with the ControllerState from PinocchioDynamics, which
matches franka::Model on logged states of our FR3s. The controllers are
created with the gains from FrankaConfig when a control thread starts.
libfranka is no longer used for the model or the rate limit, and the old
interpolator header is gone.
The FR3 controllers used joint limits hard coded in Franka.cpp, which
were the Panda limits (e.g. joint 6 from -0.02 instead of 0.44 rad on the
FR3). They now take RobotConfig::joint_limits in their constructors, and
FR3TorqueLimits is replaced by a torque_limit field in the configs.
SimConfig::timestep replaces the model's timestep, so torque control runs
at 1 kHz like the FR3 loop. FrankaConfig::timestep rejects anything other
than 1 ms. max_convergence_steps defaults to 1000 so that synchronous
control keeps waiting up to 1 s.
FrankaConfig and PandaConfig redeclared joint_limits, so the limits set
from Python (RobotConfig::joint_limits, rcs.ROBOTS) never reached
Franka.cpp, which read the hidden member with conservative defaults.
PandaConfig now sets the inherited member instead.
The controller is identified by its config (JointPDConfig, OSCConfig,
FR3JointControllerConfig, FR3OSCConfig); make_controller() builds it with
an interpolator over one control period and the robot's joint limits.
SimRobot installs it once it has the dynamics, which the env creators now
set when a controller is configured. Franka uses it instead of its default
FR3 controllers. Goals of the other kind go through IK or forward
kinematics, and a configured controller needs asynchronous control.
…ype and robot_platform

FrankaConfig, PandaConfig and SimRobotConfig redeclared robot_type and
robot_platform, which hid the RobotConfig members that Python and the
backends use. Set the inherited members in the constructors instead.
RobotConfig and FrankaConfig no longer default to robot specific values
(the C++ copies of the FR3 limits had drifted from rcs.ROBOTS). The
defaults are now empty: no robot type, dof 0, 2x0 joint limits, empty
model path and site. PandaConfig no longer sets the Panda limits.

rcs.ROBOTS[robot_type].apply(cfg) sets type, model, IK site, dof, joint
limits and home pose, and the configs use it. SimRobot and Franka reject
a config without type, dof and matching joint limits.

This also gives EmptyWorldUR5e its robot type, which it inherited as FR3
from EmptyWorldFR3.
The joint, actuator and collision geom names default to empty lists
instead of the FR3's, they belong to the robot model of the scene.
SimRobot rejects a config without one joint and one actuator name per
dof. SimRobotConfig sets robot_platform to SIMULATION in its
constructor, as FrankaConfig sets HARDWARE.
They were empty C++ subclasses of FrankaConfig. Now they are Python
classes in rcs_fr3.hw and rcs_panda.hw that call
rcs.ROBOTS[robot_type].apply() in their constructor, so a bare
FR3Config(ip=...) has the FR3's type, model, dof, joint limits and home
pose, defined only in rcs.ROBOTS. Further fields are keyword arguments,
an unknown field raises TypeError.

rcs_fr3.hw and rcs_panda.hw re-export the classes of the C++ module, the
packages import hw from there.
SafetyStage is the safety stage of Franka.cpp for any number of joints:
no torque towards a joint limit closer than a margin, a torque rate limit
per step of the nominal control period (libfranka limits per command),
and a per-joint torque clip, configured by SafetyConfig.

SafeJointController and SafeCartesianController run a controller's
torques through it. RobotConfig::safety holds the robot's SafetyConfig;
make_controller wraps the configured controller with it, so the sim and
the Franka backend use the same code. JointLimits moves to utils.h.
The joint-limit guard, torque rate limit and torque clip at the end of
FR3JointController and FR3OSC are now the shared SafetyStage, configured
by RobotConfig::safety. The FR3 controllers keep only their control laws;
FR3JointController no longer takes joint limits, the torque_limit fields
of both configs and of FrankaConfig are gone.

rcs.ROBOTS holds the safety values of the FR3 and the Panda (87/12 Nm,
franka::limitRate's 999.999 Nm/s) and apply() sets RobotConfig::safety,
so FR3Config, PandaConfig and the FR3 sim scenes have it. Franka refuses
async (torque) control without it.

The FR3 controllers with the stage give bit-identical torques to the
previous controllers on an open-loop sequence that saturates, hits the
rate limit and passes the joint-limit zones.
kp, kd, kp_p and kp_r duplicated FR3JointControllerConfig and
FR3OSCConfig. Without RobotConfig::controller, async control now runs
the FR3 controllers with their default configs, which have the same
values; other gains are set through RobotConfig::controller.
RobotConfig::end_effector (EndEffectorConfig) holds the tool after the
attachment site: tcp_offset, which replaces RobotConfig::tcp_offset, and
the optional payload, which replaces SimRobotConfig::payload. Sim uses
the payload as before; on a Franka the dynamics keep using the mass
properties the robot reports.

The Franka backend warns when connecting and in set_config() if Desk's
end effector differs from the config: F_T_EE from tcp_offset (1 mm, 1
deg) and, if a payload is set, the reported total mass and centre of
mass from it (50 g, 1 cm).

FrankaConfig no longer redeclares tcp_offset, which hid the RobotConfig
member, and the unused tcp_offset_explicit flag is gone.
rcs/PyCopy.h adds a copy constructor, __copy__ and __deepcopy__ to a
bound value type, shared by the core and the rcs_fr3 bindings. The C++
part is copied with the type's copy constructor; for a Python subclass
(e.g. rcs_fr3.hw.FR3Config) the copy keeps the subclass and copies its
__dict__ shallow or deep. It replaces the hand-written __deepcopy__ of
six configs, which returned the C++ base type.

All configs and states, the robot, gripper and hand types, payload, end
effector, controller and safety configs, setpoints, the linear
interpolators and the safety stage are copyable. Pose and RPY keep
copying through pickling. Objects that own a simulation, a robot
connection or other objects (Sim, robots, grippers, controllers,
kinematics, dynamics) are not copyable.
…+ module

The explicit list missed classes added later (ControlStateBuffer).
The FR3 OSC (from deoxys' osc_impedance) pushed a joint away from a limit
in the null space within 0.1-0.25 rad of it, with a torque of w*d that
starts with a step at 0.25 rad and shrinks towards the limit. Together
with the 0.1 rad torque cut it made poses close to the base unreachable
under control. Joint limits are handled in joint space by the safety
stage instead; FR3OSC no longer takes the joint limits and
FR3OSCConfig.avoidance_weights is gone.
The safety stage's 0.1 rad torque cut is replaced by a guard in joint
space, per joint, based on the position based velocity limits
v(d) = min(v_max, sqrt(2 a d) - c), which reach zero at d0 = c^2/2a in
front of a limit:
- a damper on the velocity towards a limit above 80% of v(d); slower
  motion and motion away from a limit are not affected,
- in the last spring_range (0.05 rad) in front of d0 the controller's
  torque towards the limit fades out and a spring pushes back, like the
  soft end stop of guiding mode.

rcs.ROBOTS holds the parameters: for the FR3 deceleration_limit and
velocity_offset from the URDF the robots report (as libfranka's
getUpperJointVelocityLimits, d0 = 0.006-0.035 rad), for the Panda the
plain sqrt(2 a d); damping 100 / 20 Nm s/rad, spring 10 / 3 Nm. In sim a
joint goal 0.15 rad beyond the lower limit of joint 4 stops the joint
0.024-0.033 rad in front of it, also when streamed fast; without the
guard it runs into the limit.
On the real FR3 the generic OSC did not rotate about the tool axis at
all: the rigid-body model has no motor inertia, joint 7 weighs 0.0007
kg m^2, so the commanded torque for a 30 deg yaw error was 0.045 Nm,
below the joint friction. The unrealized yaw error then grew and the
coupled task inertia drove joints 1-4 instead (37 Nm peaks), which felt
stiff.

OSCConfig.residual_mass is added to the diagonal of the mass matrix
(empty: none). With the FR3's motor inertia from its MJCF (armature
0.195 / 0.074) the rotation is done by joint 7, as in the sim test; the
FR3 OSC's 0.1 / 0.5 / 0.5 on joints 5-7 only makes this OSC turn joints
1, 3 and 5 instead.
OSCConfig.velocity_feedforward (default true) damps towards the
setpoint velocity of the interpolator; false damps towards zero
velocity, as the FR3 OSC. With streamed teleop goals the setpoint
velocity jumps with every goal (hand jitter over one period): on the
real FR3 the generic OSC's torque changes peaked about 15 ms into every
30 Hz step (when the goal arrives) and ran into the 1000 Nm/s rate
limit, which felt stiff. In sim with jittery 30 Hz goals: torque rate
p99 1008 Nm/s with, 105 without the feed-forward (FR3 OSC 220), at
12.4 mm tracking error (FR3 OSC 15.8, with feed-forward 4.8).
OSCConfig.velocity_feedforward defaults to false: with streamed goals
(teleop, policies at 15-30 Hz) the setpoint velocity jumps with every
goal and the feed-forward kicks the torques at the goal rate.
JointPD damped towards the setpoint velocity of the interpolator. With
streamed goals (30 Hz policies, IK-labelled targets) that velocity
jumps with every goal and kicks the torques at the goal rate: in sim
with jittery 30 Hz joint goals the torque rate sat at the 1000 Nm/s
limit (p99 1000 Nm/s, 10% of steps at the limit), without the
feed-forward p99 21 Nm/s. As for the OSC (91f2c4f), JointPD and
JointPDConfig get velocity_feedforward, default false, which is the
law of the FR3 joint controller and libfranka's joint impedance
example.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant