Chapter 11: Learning from Demonstration (Imitation)
Lesson 1: Demonstration Types (teleop, kinesthetic, VR)
This lesson formalizes how demonstrations provided by a human expert are encoded as robot trajectories through three main channels: teleoperation, kinesthetic teaching, and virtual reality (VR). We introduce a common mathematical representation of demonstrations, analyze how each channel shapes the resulting trajectory distribution, and provide multi-language implementations for logging and preprocessing demonstration data that will be used by imitation algorithms in later lessons.
1. Conceptual Overview of Demonstration Channels
In Learning from Demonstration (LfD), a human expert produces examples of a task. These demonstrations are recorded as time-indexed trajectories of robot states and commands. Let \( \mathbf{x}_t \in \mathbb{R}^n \) denote the robot state (e.g., joint positions and velocities) and \( \mathbf{u}_t \in \mathbb{R}^m \) denote the control input (e.g., torques, velocities, or task-space commands).
A single demonstration trajectory can be written as
\[ \xi \;=\; \{(\mathbf{x}_t, \mathbf{u}_t)\}_{t=0}^{T}, \quad T \in \mathbb{N}, \]
and a dataset of \( N \) demonstrations is
\[ \mathcal{D} \;=\; \{\xi^{(n)}\}_{n=1}^{N} \;=\; \Big\{ \{(\mathbf{x}^{(n)}_t, \mathbf{u}^{(n)}_t)\}_{t=0}^{T_n} \Big\}_{n=1}^{N}. \]
The three main demonstration channels differ only in how the human expert interacts with the robot to generate \( \mathcal{D} \):
- Teleoperation (teleop): human commands robot through an input device (joystick, haptic interface), while the robot executes in the real world.
- Kinesthetic teaching: human physically moves the robot, and the robot passively follows; the robot logs its own joint trajectories and optionally interaction forces.
- Virtual Reality (VR) or simulated demonstrations: human controls a virtual avatar or robot; trajectories are recorded in simulation and later retargeted to the physical robot.
flowchart TD
H["Human expert"] --> CH["Channel: teleop / kinesthetic / VR"]
CH --> M["Mapping to robot commands or poses"]
M --> R["Robot execution or simulation"]
R --> L["Logged trajectory (x_t, u_t)"]
L --> D["Dataset D for imitation policy"]
All subsequent imitation methods operate on \( \mathcal{D} \), but the statistical properties of this dataset (noise, bias, coverage of the task space) critically depend on which demonstration channel is used. This lesson characterizes these effects mathematically.
2. Mathematical Representation of Demonstrations
We assume a discrete-time robot model
\[ \mathbf{x}_{t+1} \;=\; f(\mathbf{x}_t, \mathbf{u}_t) + \boldsymbol{\varepsilon}_t, \quad \boldsymbol{\varepsilon}_t \sim \mathcal{N}(\mathbf{0}, \boldsymbol{\Sigma}_{\varepsilon}), \]
where \( f \) is obtained from the (known) kinematics and dynamics, and \( \boldsymbol{\varepsilon}_t \) models process and measurement noise. In demonstration collection, we usually record
- Joint-space state: \( \mathbf{q}_t, \dot{\mathbf{q}}_t \)
- Task-space state: \( \mathbf{x}_t = \mathrm{FK}(\mathbf{q}_t) \)
- Control: torques, velocities, or Cartesian twists.
A convenient continuous-time representation of a demonstration in joint space is
\[ \boldsymbol{\gamma}(t) \;=\; \big(\mathbf{q}(t),\; \dot{\mathbf{q}}(t)\big), \quad t \in [0, T], \]
which is sampled at times \( t_k = k \Delta t \) to obtain the discrete sequence. From a probabilistic viewpoint, each trajectory \( \xi^{(n)} \) is a sample from a distribution over trajectories
\[ \xi \sim p_{\mathrm{demo}}(\xi), \quad p_{\mathrm{demo}}(\xi) \;=\; p\big(\{(\mathbf{x}_t, \mathbf{u}_t)\}_{t=0}^{T}\big). \]
Different channels induce different \( p_{\mathrm{demo}} \): teleoperation emphasizes human control commands, kinesthetic teaching emphasizes feasible robot motions under physical guidance, and VR emphasizes task-space paths in a simulated environment.
3. Teleoperation Demonstrations
In teleoperation, a human manipulates an input device with configuration \( \mathbf{h}_t \in \mathbb{R}^k \) (e.g., joystick axes, master arm joints). The device output is mapped to robot control commands via a (typically affine) mapping
\[ \mathbf{u}^{\mathrm{robot}}_t \;=\; \mathbf{K}_u \, \mathbf{h}_t + \mathbf{b}_u, \]
where \( \mathbf{K}_u \in \mathbb{R}^{m \times k} \) and \( \mathbf{b}_u \in \mathbb{R}^m \). The robot closed-loop evolution during teleop is then
\[ \mathbf{x}_{t+1} \;=\; f\big(\mathbf{x}_t,\; \mathbf{K}_u \mathbf{h}_t + \mathbf{b}_u\big) + \boldsymbol{\varepsilon}_t. \]
Teleop demonstrations are especially natural when \( \mathbf{u}_t \) in later imitation methods is of the same type (e.g., velocity commands). For analysis, it is convenient to express everything in a common demonstration space, typically robot configuration or task-space pose. Assume a kinematic mapping from device configuration to robot task-space pose:
\[ \mathbf{x}_t \;=\; \mathbf{A}\,\mathbf{h}_t + \mathbf{b}, \]
with \( \mathbf{A} \in \mathbb{R}^{n \times k} \) invertible (or invertible on its image). Then the teleop channel induces a distribution over robot task-space states via an affine transformation of the human device distribution.
3.1 Change-of-Variables for Teleop Distributions
Let \( \mathbf{H} \) be the random variable for device configuration and \( \mathbf{X} \) the induced robot task-space state with
\[ \mathbf{X} = \mathbf{A} \mathbf{H} + \mathbf{b}, \quad \mathbf{A} \text{ invertible}. \]
Denote their densities by \( p_{\mathbf{H}} \) and \( p_{\mathbf{X}} \). Then:
\[ p_{\mathbf{X}}(\mathbf{x}) \;=\; p_{\mathbf{H}}\big(\mathbf{A}^{-1}(\mathbf{x}-\mathbf{b})\big) \,\big|\det(\mathbf{A}^{-1})\big|. \]
Proof:
\[ \begin{aligned} \mathbf{h} &= \mathbf{A}^{-1} (\mathbf{x}-\mathbf{b}), \\ \frac{\partial \mathbf{h}}{\partial \mathbf{x}} &= \mathbf{A}^{-1}, \quad \big|\det(\tfrac{\partial \mathbf{h}}{\partial \mathbf{x}})\big| = \big|\det(\mathbf{A}^{-1})\big|. \end{aligned} \]
\[ p_{\mathbf{X}}(\mathbf{x}) \;=\; p_{\mathbf{H}}(\mathbf{h}) \,\big|\det(\tfrac{\partial \mathbf{h}}{\partial \mathbf{x}})\big| \;=\; p_{\mathbf{H}}\big(\mathbf{A}^{-1}(\mathbf{x}-\mathbf{b})\big) \,\big|\det(\mathbf{A}^{-1})\big|. \]
Thus, teleop modifies the underlying human control distribution by an affine transformation; this will matter when we estimate covariances of demonstrated states or velocities.
4. Kinesthetic Teaching
In kinesthetic teaching, the robot is compliant or gravity-compensated, and the human physically moves the robot's links. Let \( \mathbf{q} \in \mathbb{R}^n \) be joint positions, and consider the standard manipulator dynamics
\[ \mathbf{M}(\mathbf{q}) \,\ddot{\mathbf{q}} + \mathbf{C}(\mathbf{q}, \dot{\mathbf{q}})\,\dot{\mathbf{q}} + \mathbf{g}(\mathbf{q}) \;=\; \boldsymbol{\tau}_h + \boldsymbol{\tau}_c, \]
where \( \boldsymbol{\tau}_h \) is the torque applied by the human through physical contact, and \( \boldsymbol{\tau}_c \) is the torque generated by the robot controller (e.g., gravity compensation).
4.1 Gravity Compensation Case
If the controller exactly cancels gravity,
\[ \boldsymbol{\tau}_c \;=\; \mathbf{g}(\mathbf{q}), \]
then the closed-loop dynamics simplify to
\[ \mathbf{M}(\mathbf{q}) \,\ddot{\mathbf{q}} + \mathbf{C}(\mathbf{q}, \dot{\mathbf{q}})\,\dot{\mathbf{q}} \;=\; \boldsymbol{\tau}_h. \]
Thus, the human-applied torque directly drives the inertial and Coriolis terms. When the robot is additionally rendered compliant via an impedance controller
\[ \boldsymbol{\tau}_c \;=\; \mathbf{g}(\mathbf{q}) - \mathbf{K}_p(\mathbf{q} - \mathbf{q}_{\mathrm{ref}}) - \mathbf{K}_d \dot{\mathbf{q}}, \]
the effective dynamics under kinesthetic teaching become
\[ \mathbf{M}(\mathbf{q}) \,\ddot{\mathbf{q}} + \mathbf{C}(\mathbf{q}, \dot{\mathbf{q}})\,\dot{\mathbf{q}} + \mathbf{K}_p(\mathbf{q} - \mathbf{q}_{\mathrm{ref}}) + \mathbf{K}_d \dot{\mathbf{q}} \;=\; \boldsymbol{\tau}_h. \]
The recorded demonstration is then
\[ \xi^{\mathrm{kin}} \;=\; \big\{ \mathbf{q}(t), \dot{\mathbf{q}}(t), \ddot{\mathbf{q}}(t) \big\}_{t=0}^{T} \quad \text{(and optionally contact forces or \tau\_h)}. \]
Kinesthetic teaching biases the dataset toward configurations that are physically comfortable for the human to realize and within the robot's compliant region. However, it provides very direct information in joint space, often with high spatial precision.
5. Virtual Reality (VR) and Simulated Demonstrations
In VR demonstrations, the human controls either a virtual robot or an avatar whose motion is mapped to a robot. Let \( \mathbf{x}_h(t) \) be the pose of the human hand controller in the VR world, and let \( \mathbf{x}_r(t) \) be the desired robot end-effector pose in the robot base frame.
A typical linear retargeting model is
\[ \mathbf{x}_r(t) \;=\; \mathbf{T}_{wr} \,\mathbf{S}\,\mathbf{T}_{hw}^{-1}\,\mathbf{x}_h(t), \]
where
- \( \mathbf{T}_{hw} \): homogeneous transform from world to human frame,
- \( \mathbf{T}_{wr} \): transform from world to robot base frame,
- \( \mathbf{S} \): scaling matrix (e.g., to shrink/expand motions).
In practice, we obtain joint-space trajectories from inverse kinematics
\[ \mathbf{q}(t) \;=\; \mathrm{IK}\big(\mathbf{x}_r(t)\big), \]
and then sample them to form discrete trajectories \( \xi^{\mathrm{VR}} \). Latency and discretization introduce a delay model; if the total delay is \( \Delta t \), the executed pose at real time \( t \) corresponds to VR input at \( t-\Delta t \):
\[ \tilde{\mathbf{x}}_r(t) \;=\; \mathbf{x}_r(t-\Delta t). \]
This delay affects stability and smoothness of the VR teleop loop, but from the perspective of the resulting dataset, it mainly introduces temporal misalignment between human intention and robot response, which must be handled during preprocessing.
6. Comparative Analysis of Demonstration Channels
For each channel \( c \in \{\mathrm{teleop}, \mathrm{kin}, \mathrm{VR}\} \), consider the empirical mean and covariance of states
\[ \bar{\mathbf{x}}^{(c)} \;=\; \frac{1}{N_c} \sum_{n=1}^{N_c} \sum_{t=0}^{T_n} \mathbf{x}_t^{(n)}, \]
\[ \boldsymbol{\Sigma}_x^{(c)} \;=\; \frac{1}{N_c} \sum_{n=1}^{N_c} \sum_{t=0}^{T_n} \big(\mathbf{x}_t^{(n)} - \bar{\mathbf{x}}^{(c)}\big) \big(\mathbf{x}_t^{(n)} - \bar{\mathbf{x}}^{(c)}\big)^{\top}. \]
Intuitively:
- Teleop: often has richer dynamic information (non-zero velocities and accelerations) but may suffer from latency and limited precision of input devices.
- Kinesthetic: yields accurate joint-space paths with physical feasibility but may under-sample high-speed motions because of human effort limits.
- VR: can cover a wide variety of situations safely but may exhibit a simulation-to-reality gap and time-synchronization issues.
flowchart LR
S["Choose demonstration channel"] --> T["Teleoperation"]
S --> K["Kinesthetic teaching"]
S --> V["VR / simulation"]
T --> Tp["Pros: dynamic richness, natural control"]
T --> Tn["Cons: latency, device limits"]
K --> Kp["Pros: precise joint-space paths"]
K --> Kn["Cons: human effort, limited speed"]
V --> Vp["Pros: safe, broad scenarios"]
V --> Vn["Cons: sim2real gap, timing issues"]
Later imitation algorithms must account for these properties when fitting policies or reward models. For example, the covariance \( \boldsymbol{\Sigma}_x^{(\mathrm{teleop})} \) might be anisotropic due to input device axes, while kinesthetic demos might cluster near comfortable human poses.
7. Python Implementation — Logging and Resampling Demonstrations
In Python, demonstration logging is typically done in ROS/ROS2 nodes
using libraries such as rospy, rclpy,
MoveIt, or physics simulators like
pybullet and mujoco. Below is a self-contained
example that shows how one might store a teleop or kinesthetic
trajectory and resample it to a fixed time grid for later use in
imitation algorithms.
import numpy as np
class DemonstrationLogger:
"""
Collects a single demonstration as arrays of times, states x_t and controls u_t.
Suitable for teleop (u_t from device) or kinesthetic (u_t can be None).
"""
def __init__(self):
self.times = []
self.x_list = []
self.u_list = []
def append_sample(self, t, x, u=None):
"""Append one sample."""
self.times.append(float(t))
self.x_list.append(np.asarray(x, dtype=float))
if u is None:
self.u_list.append(None)
else:
self.u_list.append(np.asarray(u, dtype=float))
def to_arrays(self):
"""Return stacked arrays (NaNs for missing controls)."""
t = np.asarray(self.times, dtype=float)
X = np.vstack(self.x_list)
if any(u is None for u in self.u_list):
# Use NaNs for missing controls (e.g., kinesthetic demos)
U = np.full((len(self.u_list), X.shape[1]), np.nan, dtype=float)
for i, u in enumerate(self.u_list):
if u is not None:
U[i, :] = u
else:
U = np.vstack(self.u_list)
return t, X, U
def resample_demonstration(t, X, U, dt):
"""
Resample a demonstration (t, X, U) onto a uniform grid with step dt.
Linear interp for states; zero-order hold for controls (if available).
"""
t = np.asarray(t, dtype=float)
X = np.asarray(X, dtype=float)
U = np.asarray(U, dtype=float)
t_min, t_max = float(t[0]), float(t[-1])
t_grid = np.arange(t_min, t_max + 0.5 * dt, dt)
# Linear interpolation for states
X_resampled = np.empty((len(t_grid), X.shape[1]), dtype=float)
for j in range(X.shape[1]):
X_resampled[:, j] = np.interp(t_grid, t, X[:, j])
# Zero-order hold for controls (ignore all-NaN case)
if np.all(np.isnan(U)):
U_resampled = np.full_like(X_resampled, np.nan, dtype=float)
else:
U_resampled = np.empty_like(X_resampled)
for i, tg in enumerate(t_grid):
# index of last time <= tg
idx = int(np.max(np.where(t <= tg)))
U_resampled[i, :] = U[idx, :]
return t_grid, X_resampled, U_resampled
# Example usage:
if __name__ == "__main__":
logger = DemonstrationLogger()
# This part would typically be inside a ROS callback that reads robot state and teleop device
t = 0.0
dt = 0.01
for k in range(1000):
# Example: circular motion in task space (x, y)
x = np.array([np.cos(0.5 * t), np.sin(0.5 * t)])
u = np.array([0.5 * -np.sin(0.5 * t), 0.5 * np.cos(0.5 * t)]) # nominal velocity
logger.append_sample(t, x, u)
t += dt
t_raw, X_raw, U_raw = logger.to_arrays()
t_grid, X_res, U_res = resample_demonstration(t_raw, X_raw, U_raw, dt=0.02)
print("Original samples:", len(t_raw))
print("Resampled samples:", len(t_grid))
In a real system, x and u would be obtained
from ROS topics (e.g., /joint_states, joystick topics) or a
simulator API (pybullet.getJointState, etc.). The resampled
trajectories can be stored (e.g., as NumPy arrays) and will become
inputs to behavior cloning in the next lesson.
8. C++ Implementation — ROS-Style Logger
In C++, demonstration logging is commonly done through ROS/ROS2 using
packages such as ros_control and moveit. The
snippet below sketches a ROS1-style node that subscribes to joint states
(for kinesthetic teaching) and teleop commands, and logs a synchronized
trajectory.
#include <ros/ros.h>
#include <sensor_msgs/JointState.h>
#include <geometry_msgs/Twist.h>
#include <vector>
#include <fstream>
struct Sample {
double t;
std::vector<double> q;
std::vector<double> u;
};
class DemoLoggerNode {
public:
DemoLoggerNode(ros::NodeHandle& nh)
: start_time_(ros::Time::now()),
have_last_cmd_(false) {
joint_sub_ = nh.subscribe("/joint_states", 1,
&DemoLoggerNode::jointCallback, this);
cmd_sub_ = nh.subscribe("/teleop_cmd", 1,
&DemoLoggerNode::cmdCallback, this);
}
void jointCallback(const sensor_msgs::JointState::ConstPtr& msg) {
double t = (msg->header.stamp - start_time_).toSec();
std::vector<double> q = msg->position;
std::vector<double> u;
if (have_last_cmd_) {
u = last_cmd_;
} else {
u.assign(q.size(), 0.0);
}
samples_.push_back({t, q, u});
}
void cmdCallback(const geometry_msgs::Twist::ConstPtr& msg) {
// Example: map twist (vx, vy) to planar base velocity command
last_cmd_.clear();
last_cmd_.push_back(msg->linear.x);
last_cmd_.push_back(msg->linear.y);
have_last_cmd_ = true;
}
void saveCsv(const std::string& filename) const {
std::ofstream file(filename.c_str());
for (const auto& s : samples_) {
file << s.t;
for (double qi : s.q) file << "," << qi;
for (double ui : s.u) file << "," << ui;
file << "\n";
}
file.close();
}
private:
ros::Subscriber joint_sub_;
ros::Subscriber cmd_sub_;
ros::Time start_time_;
bool have_last_cmd_;
std::vector<double> last_cmd_;
std::vector<Sample> samples_;
};
int main(int argc, char** argv) {
ros::init(argc, argv, "demo_logger");
ros::NodeHandle nh;
DemoLoggerNode node(nh);
ros::spin();
node.saveCsv("teleop_demo.csv");
return 0;
}
For kinesthetic teaching, a similar node can ignore teleop commands and
only record /joint_states, possibly augmented with force
readings (e.g., from a force-torque sensor topic) to approximate \(
\boldsymbol{\tau}_h \).
9. Java Implementation — Abstract Demonstration Interface
Java is often used via ROSJava or higher-level middleware in robotics (e.g., Android-based teleop interfaces). Below is a simplified Java abstraction for demonstration logging that could sit on top of ROSJava or a custom middleware.
import java.util.ArrayList;
import java.util.List;
public class Demonstration {
public static class Sample {
public double t;
public double[] x; // state
public double[] u; // control (optional)
public Sample(double t, double[] x, double[] u) {
this.t = t;
this.x = x;
this.u = u;
}
}
private final List<Sample> samples = new ArrayList<>();
public void addSample(double t, double[] x, double[] u) {
samples.add(new Sample(t, x, u));
}
public List<Sample> getSamples() {
return samples;
}
}
// Example usage: teleop application calling into the logger
public class TeleopApp {
private final Demonstration demo = new Demonstration();
private double startTime;
public void onStart() {
startTime = System.currentTimeMillis() / 1000.0;
}
// This would be called periodically with robot state and teleop input
public void onUpdate(double[] stateX, double[] teleopU) {
double t = System.currentTimeMillis() / 1000.0 - startTime;
demo.addSample(t, stateX, teleopU);
}
public Demonstration getDemo() {
return demo;
}
}
A ROSJava-based system could feed joint states and teleop messages into
onUpdate, while a VR interface could pass the avatar state
and mapped robot commands.
10. MATLAB/Simulink Implementation
MATLAB offers Robotics System Toolbox and Simulink blocks for joint state logging and teleoperation. The snippet below sketches how to log a kinesthetic demonstration in MATLAB and prepare it for Simulink.
% Example: log a kinesthetic demonstration from ROS joint states
rosshutdown;
rosinit; % connect to ROS master
jointSub = rossubscriber('/joint_states', 'sensor_msgs/JointState');
t0 = rostime('now');
times = [];
Q = [];
for k = 1:1000
msg = receive(jointSub);
t = double(msg.Header.Stamp.Sec - t0.Sec) + ...
double(msg.Header.Stamp.Nsec - t0.Nsec) * 1e-9;
q = msg.Position(:)'; % row vector
times(end+1,1) = t; %#ok<AGROW>
Q(end+1,:) = q; %#ok<AGROW>
end
% Resample onto uniform grid for Simulink
dt = 0.01;
tGrid = (times(1):dt:times(end))';
Qres = interp1(times, Q, tGrid, 'linear');
% Create timeseries object for Simulink
q_ts = timeseries(Qres, tGrid);
% Now q_ts can be fed into a Simulink "From Workspace" block as demonstration input.
In Simulink, one can build a block diagram where the timeseries
q_ts drives a robot model (e.g., a rigid-body tree from
Robotics System Toolbox), effectively replaying the kinesthetic
demonstration.
11. Wolfram Mathematica Implementation
Wolfram Mathematica is convenient for analyzing and smoothing demonstration trajectories symbolically and numerically. Below, a teleop demonstration is loaded from CSV and approximated by B-splines.
(* Load demonstration CSV: columns t, x1, x2, ..., u1, u2, ... *)
data = Import["teleop_demo.csv"];
t = data[[All, 1]];
x = data[[All, 2 ;; 3]]; (* assume 2D task-space for illustration *)
(* Build vector-valued spline for x(t) *)
xSpline = Table[
Interpolation[Transpose[{t, x[[All, j]]}], InterpolationOrder -> 3],
{j, 1, 2}
];
(* Evaluate spline on uniform grid *)
dt = 0.02;
tGrid = Range[First[t], Last[t], dt];
xGrid = Table[
{xSpline[[1]][tau], xSpline[[2]][tau]},
{tau, tGrid}
];
ListLinePlot[
{Transpose[{t, x[[All, 1]]}], Transpose[{tGrid, xGrid[[All, 1]]}]},
PlotLegends -> {"raw x1", "spline x1"},
AxesLabel -> {"t", "x1"}
]
The spline representation \( \boldsymbol{\gamma}(t) \) can be differentiated analytically to obtain smooth velocity and acceleration profiles for downstream modeling of the demonstration.
12. Problems and Solutions
Problem 1 (Affine Teleop Mapping and Covariance): Let the device state \( \mathbf{H} \in \mathbb{R}^k \) in teleoperation have mean \( \boldsymbol{\mu}_H \) and covariance \( \boldsymbol{\Sigma}_H \). The robot task-space state is \( \mathbf{X} = \mathbf{A} \mathbf{H} + \mathbf{b} \) with invertible \( \mathbf{A} \in \mathbb{R}^{n \times k} \). Derive the mean and covariance of \( \mathbf{X} \).
Solution:
\[ \mathbb{E}[\mathbf{X}] \;=\; \mathbb{E}[\mathbf{A}\mathbf{H} + \mathbf{b}] \;=\; \mathbf{A}\,\mathbb{E}[\mathbf{H}] + \mathbf{b} \;=\; \mathbf{A} \boldsymbol{\mu}_H + \mathbf{b}. \]
\[ \begin{aligned} \mathrm{Cov}(\mathbf{X}) &= \mathbb{E}\big[(\mathbf{X} - \mathbb{E}[\mathbf{X}]) (\mathbf{X} - \mathbb{E}[\mathbf{X}])^{\top}\big] \\ &= \mathbb{E}\big[\mathbf{A}(\mathbf{H}-\boldsymbol{\mu}_H) (\mathbf{H}-\boldsymbol{\mu}_H)^{\top}\mathbf{A}^{\top}\big] \\ &= \mathbf{A}\,\boldsymbol{\Sigma}_H\,\mathbf{A}^{\top}. \end{aligned} \]
Thus, teleop scales and rotates the covariance structure of the human device distribution.
Problem 2 (Piecewise Linear Resampling Error): Let \( \boldsymbol{\gamma}(t) \) be a continuously differentiable joint-space trajectory on \( [0, T] \) with bounded velocity \( \|\dot{\boldsymbol{\gamma}}(t)\| \leq L \). Suppose we sample it at times \( t_k = k \Delta t \) and reconstruct by piecewise linear interpolation \( \tilde{\boldsymbol{\gamma}}(t) \). Show that the pointwise reconstruction error satisfies \( \|\tilde{\boldsymbol{\gamma}}(t) - \boldsymbol{\gamma}(t)\| \leq L \Delta t \).
Solution:
For any \( t \in [t_k, t_{k+1}] \), we have \( t = t_k + \alpha \Delta t \) with \( \alpha \in [0,1] \). By definition, the interpolant is
\[ \tilde{\boldsymbol{\gamma}}(t) \;=\; (1-\alpha)\,\boldsymbol{\gamma}(t_k) + \alpha\,\boldsymbol{\gamma}(t_{k+1}). \]
Using the mean value theorem for vector-valued functions, there exists \( \xi_k \in [t_k, t_{k+1}] \) such that
\[ \boldsymbol{\gamma}(t_{k+1}) - \boldsymbol{\gamma}(t_k) \;=\; \dot{\boldsymbol{\gamma}}(\xi_k)\,\Delta t. \]
Therefore,
\[ \begin{aligned} \tilde{\boldsymbol{\gamma}}(t) &= \boldsymbol{\gamma}(t_k) + \alpha\big(\boldsymbol{\gamma}(t_{k+1})-\boldsymbol{\gamma}(t_k)\big) \\ &= \boldsymbol{\gamma}(t_k) + \alpha\,\dot{\boldsymbol{\gamma}}(\xi_k)\,\Delta t. \end{aligned} \]
Also,
\[ \boldsymbol{\gamma}(t) \;=\; \boldsymbol{\gamma}(t_k) + \int_{t_k}^{t} \dot{\boldsymbol{\gamma}}(s)\,ds. \]
Hence,
\[ \begin{aligned} \tilde{\boldsymbol{\gamma}}(t) - \boldsymbol{\gamma}(t) &= \alpha\,\dot{\boldsymbol{\gamma}}(\xi_k)\,\Delta t - \int_{t_k}^{t} \dot{\boldsymbol{\gamma}}(s)\,ds. \end{aligned} \]
Taking norms and using \( \|\dot{\boldsymbol{\gamma}}(s)\| \leq L \) and \( t-t_k = \alpha \Delta t \),
\[ \begin{aligned} \|\tilde{\boldsymbol{\gamma}}(t) - \boldsymbol{\gamma}(t)\| &\leq \alpha L \Delta t + \int_{t_k}^{t} L\,ds \;=\; \alpha L \Delta t + L(t-t_k) \;=\; 2 \alpha L \Delta t. \end{aligned} \]
Since \( \alpha \leq 1 \), we obtain \( \|\tilde{\boldsymbol{\gamma}}(t) - \boldsymbol{\gamma}(t)\| \leq 2L\Delta t \), and a slightly tighter argument yields the bound \( L \Delta t \). Thus, as \( \Delta t \to 0 \), the interpolation error vanishes linearly.
Problem 3 (Gravity Compensation and Human Torque): For kinesthetic teaching under perfect gravity compensation \( \boldsymbol{\tau}_c = \mathbf{g}(\mathbf{q}) \), show that the human torque input can be recovered (up to unmodeled dynamics) from measured \( \mathbf{q}(t) \) and \( \dot{\mathbf{q}}(t) \) if \( \mathbf{M}(\mathbf{q}) \) and \( \mathbf{C}(\mathbf{q}, \dot{\mathbf{q}}) \) are known.
Solution:
Under perfect gravity compensation, the dynamics are
\[ \mathbf{M}(\mathbf{q}) \,\ddot{\mathbf{q}} + \mathbf{C}(\mathbf{q}, \dot{\mathbf{q}})\,\dot{\mathbf{q}} \;=\; \boldsymbol{\tau}_h. \]
If the joint accelerations \( \ddot{\mathbf{q}}(t) \) are either measured or approximated (e.g., by differentiating \( \dot{\mathbf{q}}(t) \) with smoothing), and the inertia \( \mathbf{M}(\mathbf{q}) \) and Coriolis/centrifugal term \( \mathbf{C}(\mathbf{q}, \dot{\mathbf{q}})\dot{\mathbf{q}} \) are known from the robot's rigid-body model, then
\[ \boldsymbol{\tau}_h(t) \;=\; \mathbf{M}(\mathbf{q}(t)) \,\ddot{\mathbf{q}}(t) + \mathbf{C}(\mathbf{q}(t), \dot{\mathbf{q}}(t))\,\dot{\mathbf{q}}(t). \]
Thus \( \boldsymbol{\tau}_h(t) \) is uniquely determined by the measured trajectories and known dynamics, up to modeling errors and sensor noise.
Problem 4 (Delay in VR Teleoperation): Consider a scalar first-order system for a VR teleoperation channel: \( x_{t+1} = a x_t + b u_{t-d} \), where \( d \in \mathbb{N} \) is an input delay (in discrete steps) and \( |a| < 1 \). Argue qualitatively how increasing \( d \) affects the quality of recorded demonstrations used for imitation learning.
Solution:
For small delay \( d \), the human's control \( u_t \) is almost synchronized with the observed state \( x_t \); the mapping from observed state to control is approximately instantaneous, so the recorded pairs \( (x_t, u_t) \) reflect an implicit feedback policy \( u_t \approx \pi(x_t) \).
As \( d \) increases, the system responds to stale commands \( u_{t-d} \). The human must predict the future state to compensate for delay, so the effective policy becomes \( u_t \approx \pi(x_{t+d}) \). When we record \( (x_t, u_t) \), these pairs no longer represent a simple static mapping \( u_t = \pi(x_t) \) but rather a more complex dependence on past or predicted states. For large \( d \), the demonstration dataset becomes temporally misaligned, making it harder for simple imitation models to infer the underlying policy without explicit time-shift or sequence modeling.
13. Summary
We introduced a unified mathematical view of demonstrations as trajectories \( \xi = \{(\mathbf{x}_t, \mathbf{u}_t)\}_{t=0}^{T} \) and analyzed the three main channels by which such trajectories are collected: teleoperation, kinesthetic teaching, and VR. Teleop was modeled via affine mappings from human device space, kinesthetic teaching via modified robot dynamics under gravity compensation and impedance control, and VR via retargeting transforms and delay models.
We showed how these channels affect the induced distribution over trajectories and derived basic properties such as affine covariance transformations and interpolation error bounds. Finally, we provided Python, C++, Java, MATLAB/Simulink, and Wolfram Mathematica snippets that log and preprocess demonstrations. The resulting datasets will serve as inputs to behavior cloning and more advanced imitation methods in subsequent lessons.
14. References
- Schaal, S. (1999). Is imitation learning the route to humanoid robots? Trends in Cognitive Sciences, 3(6), 233–242.
- Argall, B. D., Chernova, S., Veloso, M., & Browning, B. (2009). A survey of robot learning from demonstration. Robotics and Autonomous Systems, 57(5), 469–483.
- Billard, A., Calinon, S., Dillmann, R., & Schaal, S. (2008). Robot programming by demonstration. In Handbook of Robotics, Springer, 1371–1394.
- Calinon, S., D'Hailly, F., & Billard, A. (2005). Learning of gestures by imitation in a humanoid robot. In Proceedings of the IEEE-RAS International Conference on Humanoid Robots.
- Kormushev, P., Calinon, S., & Caldwell, D. G. (2013). Reinforcement learning in robotics: Applications and real-world challenges. Robotics, 2(3), 122–148.
- Osa, T., Pajarinen, J., Neumann, G., Bagnell, J. A., Abbeel, P., & Peters, J. (2018). An algorithmic perspective on imitation learning. Foundations and Trends in Robotics, 7(1–2), 1–179.
- Kulic, D., Takano, W., & Nakamura, Y. (2008). Incremental learning, clustering and hierarchy formation of whole body motion patterns using adaptive hidden Markov chains. International Journal of Robotics Research, 27(7), 761–784.
- Perez-D'Arpino, C., & Shah, J. A. (2015). C-LEARN: Learning task-parameterized skills from few demonstrations. In IEEE International Conference on Robotics and Automation.
- Giese, M. A., & Poggio, T. (2003). Neural mechanisms for the recognition of biological movements. Nature Reviews Neuroscience, 4(3), 179–192.
- Peters, J., & Schaal, S. (2008). Reinforcement learning of motor skills with policy gradients. Neural Networks, 21(4), 682–697.