Week 11: Temporal Imitation Learning with Force and Contact Feedback
Upgrading the UR5e imitation-learning pipeline with force/torque sensing, task-relative observations, temporal history, and action chunking.
Week 11 — Temporal Imitation Learning with Force and Contact Feedback
Internship: JdeRobot 2026 — Ahmed Algharib
Package: vibe_version
Platform: UR5e MuJoCo twin · ROS 2 Jazzy · MoveIt 2 · PyTorch
Scope of this week: upgrade the demonstration schema, integrate force/torque and contact information, investigate expert trajectory repeatability, and train a first Transformer-based policy using temporal observations and action chunks.
TL;DR
- Implemented a load-derived force/torque sensing approach with EMA-based baseline compensation.
- Published and recorded a 6D wrench signal and a contact measurement in the ROS 2 pipeline.
- Migrated the demonstration schema to 38-dimensional observations and 7-dimensional actions.
- Implemented four-step observation history and ten-step action chunking.
- Built a Transformer policy and trained it using 926 samples from one demonstration episode.
- Obtained a final training loss of approximately 0.61 after 20 epochs.
- Investigated expert repeatability and found byte-identical Cartesian planner trajectories in the tested repeatability experiments.
- Identified reachability-map generation, involving multi-seed IK search, as a source of stochasticity requiring further investigation.
1. Force/Torque Sensing and Contact Detection
This week, the simulation sensing pipeline was extended to provide physical interaction information to the learning system.
Challenge
MuJoCo’s native touch sensors did not provide reliable contact measurements for the current weld-based suction-gripper setup.
Engineering approach
A load-derived contact signal was implemented in the C++ MuJoCo plugin.
An Exponential Moving Average (EMA) was used to estimate the baseline contribution from the tool’s weight and gravity. The baseline was then compensated to isolate changes associated with the object’s load.
Results
- Published a six-dimensional wrench signal.
- Published a one-dimensional contact measurement to ROS 2.
- Verified the recorded signals in HDF5.
- Observed a maximum contact measurement of approximately 21.17 N while lifting the yellow box in the tested episode.
This provides an additional physical-interaction signal for the imitation-learning pipeline.
2. Dataset Schema Migration — Level 1
The previous dataset representation was upgraded to a task-relative observation and action schema.
Observation vector — 38 dimensions
| Component | Dimensions | Description |
|---|---|---|
Joint position (q) | 6 | UR5e joint positions |
Joint velocity (qvel) | 6 | UR5e joint velocities |
| Suction command | 1 | Gripper command |
| Object pose relative to EE | 9 | Object position and rotation representation |
| Target pose relative to base | 9 | Target position and rotation representation |
| Wrench | 6 | Force and torque measurements |
| Contact | 1 | Contact measurement |
| Total | 38 |
Action vector — 7 dimensions
The previous absolute next-joint-position representation was replaced with a task-relative end-effector action:
- 6 dimensions: end-effector delta (translation and rotation).
- 1 dimension: suction command.
The resulting action representation is:
EE delta (6) + suction (1)
Recorder implementation
The demonstration_recorder.py pipeline was updated to record the new schema.
The HDF5 dataset was verified against the expected 38D observation and 7D action representation.
3. Expert Trajectory Repeatability and Entropy Investigation
An important issue raised during the internship was the stochasticity introduced by sampling-based planning and reachability generation.
Investigation
Repeatability experiments were conducted to investigate whether the expert demonstration pipeline produces consistent trajectories under repeated conditions.
Findings
- Cartesian planner execution was byte-identical in the tested repeatability experiments.
- The observed stochasticity was isolated to reachability-map generation.
- MoveIt’s multi-seed IK search can introduce variation in the generated reachability results.
Proposed engineering solution
Cache the generated reachability_report.json after the initial reachability computation and reuse it during subsequent data-collection runs.
This should reduce variation introduced by repeatedly generating the reachability map.
Status: caching is an identified engineering action, not yet a verified implementation. Further repeatability tests are required after implementation.
4. PyTorch Dataset Pipeline — Level 2
The learning pipeline was upgraded to support the new HDF5 schema.
Dataset processing
The new dataset.py implementation handles:
- Reading the 38D observation and 7D action schema.
- Processing the pose and rotation representations.
- Computing normalization statistics.
- Applying mean/std normalization.
- Preparing temporal observation histories and future action chunks.
Temporal observation history
Instead of processing only the current observation, the model receives the previous four observations.
Hobs = 4
This provides temporal context for interpreting robot motion and interaction transitions.
Action chunking
The model predicts ten future action steps instead of a single next action.
Hact = 10
This produces a 70-value action prediction:
10 steps × 7 action dimensions = 70 values
Verified tensor shapes
| Tensor | Shape |
|---|---|
| Observation | (Batch, 4, 38) |
| Action | (Batch, 10, 7) |
5. Transformer Policy Training — Level 3
A Transformer-based policy was implemented in PyTorch.
Architecture
The policy receives a four-step observation history, projects the observation features into a Transformer Encoder, and predicts a ten-step action chunk.
The input and output dimensions are:
- Input:
(Batch, 4, 38) - Output:
(Batch, 10, 7)
Training experiment
| Metric | Result |
|---|---|
| Demonstration episodes | 1 |
| Dataset samples | 926 |
| Training epochs | 20 |
| Observation dimensions | 38 |
| Action dimensions | 7 |
| Observation history | 4 steps |
| Action chunk | 10 steps |
| Final training loss | Approximately 0.61 |
| Model checkpoint | policy_transformer.pt |
The training loss decreased from approximately 0.97 to 0.61 during the experiment.
The model checkpoint was saved successfully.
Important limitation: this is an initial training experiment on one episode. It does not establish generalization or successful closed-loop manipulation.
6. Understanding the Training Loss Difference
The previous week’s simpler schema achieved a reported loss of approximately 0.018, while the new Transformer experiment reached approximately 0.61.
These values should not be interpreted as a direct performance comparison.
The learning problem has changed substantially:
- The previous model used a simpler observation/action representation.
- The new model predicts seven action dimensions over ten future steps.
- The observation now includes velocities, relative poses, wrench, and contact information.
- Temporal history and action chunking change the prediction task.
- The loss depends on the target normalization, reduction method, and evaluation procedure.
Consequently, a higher numerical loss does not automatically mean that the new model is worse.
A fair comparison requires consistent evaluation conditions and a clear understanding of the loss calculation.
The next experiment should establish a reliable baseline for the new schema before increasing its complexity.
7. Open Questions and Research Direction
The current implementation raises two important questions for the next development stage.
7.1 Action chunking and loss scaling
Does the higher loss primarily reflect the change from single-step prediction to ten-step action prediction, or does it reveal a learning difficulty caused by the richer observation/action representation?
The investigation should include:
- Checking the exact loss reduction method.
- Inspecting per-action-dimension errors.
- Evaluating prediction errors across the ten future steps.
- Comparing predictions on a consistent held-out dataset.
7.2 Dataset size and additional sensing inputs
Should additional demonstrations be collected before adding further sensing features?
The current experiment uses one episode and 926 samples. This is sufficient for an initial pipeline test, but not enough to establish generalization across different object poses, target locations, and interaction conditions.
Adding more features should be justified by their usefulness to the task and supported by sufficient demonstration coverage.
8. What Is Not Done Yet
The following items remain open:
- No successful closed-loop learned-policy rollout has been demonstrated.
- The Transformer has been trained on only one demonstration episode.
- Generalization across object positions, target positions, and robot configurations remains unverified.
- The proposed reachability-map caching solution still requires implementation and repeatability testing.
- The new loss has not yet been compared against the previous model under identical evaluation conditions.
- The learned policy has not yet been compared against the MoveIt expert using matched scenarios.
The current model should therefore be treated as an experimental offline baseline, not a validated robot controller.
9. Next Milestones
- Validate the current policy: run a controlled simulation experiment before adding more input features.
- Inspect the loss: examine per-dimension and per-horizon prediction errors and verify normalization and loss reduction.
- Expand the dataset: collect more successful demonstrations covering object, target, and robot configurations.
- Improve expert repeatability: implement reachability-map caching and repeat the deterministic-collection tests.
- Evaluate closed-loop behavior: introduce bounded rollouts, safety checks, and takeover conditions.
- Compare against the expert: use identical scenarios and metrics to compare learned-policy and MoveIt performance.
Appendix — Current Experiment Configuration
| Parameter | Value |
|---|---|
| Observation dimension | 38 |
| Action dimension | 7 |
| Observation history | 4 |
| Action horizon | 10 |
| Dataset samples | 926 |
| Demonstration episodes | 1 |
| Training epochs | 20 |
| Final training loss | Approximately 0.61 |
| Policy architecture | Transformer Encoder |
| Framework | PyTorch |
| Output checkpoint | policy_transformer.pt |