Chapter 7: Sensors in Robotics
Lesson 3: Range Sensors (Ultrasonic, LiDAR, RADAR)
This lesson studies three canonical families of range sensors used for perception and obstacle avoidance: ultrasonic, LiDAR, and RADAR. We derive their measurement equations from wave propagation, analyze resolution and error sources, and present basic signal-processing pipelines. Implementations in Python, C++, Java, and MATLAB/Simulink illustrate time-of-flight estimation, scan geometry, and Doppler-based velocity inference.
1. Unifying Principles of Range Sensing
A range sensor estimates the distance from a sensor origin to surfaces in the environment along one or more rays. Most range sensors rely on controlled emission of a wave and observation of its interaction with the scene. Let \( s(t) \) denote a transmitted waveform and \( r(t) \) the received waveform.
Under single-bounce reflection and line-of-sight propagation, the received signal can often be modeled as a delayed and attenuated version of the transmit signal:
\[ r(t) = \alpha \, s(t - T) + n(t), \]
where \( \alpha \) is an amplitude factor (spreading loss, reflectivity), \( T \) is the round-trip delay, and \( n(t) \) is measurement noise. Distance \( d \) follows from propagation speed \( v \):
\[ d = \frac{v T}{2}. \]
Three common modalities differ primarily in wave type, speed, and frequency band:
flowchart TD
A["Transmit known wave s(t)"] --> B["Propagation through medium"]
B --> C["Reflection from surface"]
C --> D["Receive r(t) = alpha*s(t-T)+n(t)"]
D --> E["Estimate delay T"]
E --> F["Compute range d = v*T/2"]
F --> G["Optionally estimate velocity via Doppler"]
The key estimation step is finding \( T \). A standard approach is correlation (matched filtering). Define the cross-correlation:
\[ C(\tau) = \int_{-\infty}^{\infty} r(t)\, s(t-\tau)\, dt. \]
If \( r(t)=\alpha s(t-T) \) and \( s \) has finite energy, then:
\[ C(\tau)=\alpha \int s(t-T) s(t-\tau)\, dt = \alpha \, R_{ss}(\tau-T), \]
where \( R_{ss} \) is the autocorrelation of \( s \). Since autocorrelation achieves its maximum at zero shift, \( C(\tau) \) is maximized at \( \tau=T \). Hence the delay estimator \( \hat{T}=\arg\max_{\tau} C(\tau) \): is consistent under the model.
Two performance quantities recur across modalities:
- Range resolution. Ability to separate two targets at different distances.
- Angular resolution / field of view. How narrow the sensing beam is and how well directions can be distinguished.
2. Ultrasonic Range Sensors
Ultrasonic sensors emit acoustic pulses (typically 40–200 kHz) and measure echo delay. Acoustic propagation speed depends on air temperature. A common approximation is \( v(T_c) \):
\[ v(T_c) \approx 331.3 + 0.606\, T_c \quad \text{m/s}, \]
where \( T_c \) is temperature in Celsius. Therefore, a ToF-based distance estimate is
\[ \hat{d} = \frac{v(T_c)\, \hat{T}}{2}. \]
Beam and footprint. For a circular transducer of radius \( a \) emitting wavelength \( \lambda \), the far-field half-power beamwidth for a uniform piston model is approximately:
\[ \theta_{3\text{dB}} \approx 0.51 \frac{\lambda}{a}. \]
A larger aperture narrows the beam, improving angular selectivity but increasing size and cost.
Attenuation. Acoustic intensity decays roughly with spherical spreading:
\[ I(d) \propto \frac{1}{d^2}. \]
This contributes to a minimum detectable range and makes soft materials (low reflectivity) harder to sense.
Systematic error from temperature mismatch. Suppose the algorithm assumes speed \( v_0 \) but the true speed is \( v \). Then the relative range bias is:
\[ \frac{\hat{d}-d}{d} = \frac{v_0-v}{v}. \]
Even modest temperature changes can yield centimeter-level errors at meter ranges.
3. LiDAR Range Sensors
LiDAR uses laser light (near-IR or visible) with propagation speed approximately the speed of light in air \( c_a \approx 3\times 10^8\ \text{m/s} \): and measures distance via ToF or phase shift. A pulsed ToF LiDAR follows:
\[ d = \frac{c_a T}{2}. \]
Range resolution from bandwidth. A pulse of temporal width \( \Delta t \) has effective bandwidth \( B \approx 1/\Delta t \). Two targets separated by delay \( \Delta T \) are resolvable if their correlation peaks do not overlap, yielding:
\[ \Delta d \approx \frac{c_a \Delta T}{2} \approx \frac{c_a}{2B}. \]
Proof sketch (matched-filter limit). For a signal with spectrum confined to bandwidth \( B \), the autocorrelation mainlobe width is about \( 1/B \). Since delay estimation is limited by this mainlobe, resolvable delays satisfy \( \Delta T \gtrsim 1/B \), giving the stated \( \Delta d \).
Scan geometry. A 2D spinning LiDAR provides ranges \( r_k \): at angles \( \phi_k \):. In the sensor’s local frame,
\[ \mathbf{p}_k = \begin{bmatrix} x_k \\ y_k \end{bmatrix} = \begin{bmatrix} r_k \cos\phi_k \\ r_k \sin\phi_k \end{bmatrix}. \]
This mapping is purely geometric and will later be embedded into coordinate-frame transformations (Chapter 9).
Intensity and reflectance. For a Lambertian patch with albedo \( \rho \), received power decays as:
\[ P_r(d) \propto \rho \frac{1}{d^2}. \]
Thus LiDAR range can fail on dark/absorbing surfaces or strong ambient illumination.
4. RADAR Range Sensors
RADAR emits radio waves and measures echoes. Unlike ultrasonic/LiDAR, RADAR can naturally infer target velocity using the Doppler effect.
ToF ranging. The same delay model gives:
\[ d = \frac{c T}{2}, \]
with \( c \) the speed of light.
Range resolution (FM-CW or pulsed). For a waveform with bandwidth \( B \) (e.g., chirp), the classical radar resolution is:
\[ \Delta d = \frac{c}{2B}. \]
Doppler velocity. A target moving with radial velocity \( v_r \) produces a frequency shift: \( f_d \):
\[ f_d = \frac{2 v_r}{\lambda} = \frac{2 v_r f_c}{c}, \]
where \( \lambda \) is carrier wavelength and \( f_c \) is carrier frequency. Hence \( v_r = \frac{\lambda f_d}{2} \): follows directly.
Radar equation (SNR scaling). The received power from a target with radar cross section \( \sigma \) at range \( d \) is approximated by:
\[ P_r(d) = \frac{P_t G_t G_r \lambda^2 \sigma}{(4\pi)^3 d^4}, \]
where \( P_t \) is transmit power and \( G_t, G_r \) are antenna gains. The \( d^{-4} \) decay explains why radar relies on high power and gain for long-range sensing.
Angular resolution. For an antenna aperture of size \( D \):
\[ \theta \approx \frac{\lambda}{D}. \]
Higher carrier frequency (smaller \( \lambda \)) yields better angular resolution for fixed antenna size, motivating millimeter-wave automotive radars.
5. Comparison and Practical Notes
The modalities differ by physical coupling to the environment:
- Ultrasonic: cheap, short range, wide beam, affected by air properties.
- LiDAR: high range accuracy and angular resolution, sensitive to surface reflectance and weather.
- RADAR: robust in fog/rain/dust, long range, direct velocity via Doppler, lower spatial fidelity at low frequencies.
A minimal processing pipeline is:
flowchart TD
S0["Acquire raw echoes"] --> S1["Preprocess: gain, filtering"]
S1 --> S2["Delay/beat estimation (correlation or FFT)"]
S2 --> S3["Convert to range d"]
S3 --> S4["Optional: Doppler/phase -> velocity"]
S4 --> S5["Output: ranges / scan / point set"]
6. Python Implementation — Time-of-Flight and 2D Scan Geometry
We simulate a transmitted pulse, create a delayed echo, estimate delay by correlation, and map a synthetic LiDAR scan to Cartesian points.
import numpy as np
# ----- (A) Time-of-flight estimation by correlation -----
fs = 200_000 # sample rate (Hz), typical for ultrasonic processing
T_true = 0.0075 # true round-trip delay (s)
v_air = 343.0 # assumed speed (m/s)
# Transmit pulse: windowed sinusoid
t = np.arange(0, 0.01, 1/fs)
f0 = 40_000
s = np.sin(2*np.pi*f0*t) * (t < 0.001)
# Echo: delayed + attenuated + noise
delay_samples = int(T_true * fs)
alpha = 0.6
r = np.zeros_like(s)
r[delay_samples:] = alpha * s[:-delay_samples]
r += 0.02 * np.random.randn(len(r))
# Correlation-based delay estimate
C = np.correlate(r, s, mode="full")
lags = np.arange(-len(s)+1, len(s))
T_hat = lags[np.argmax(C)] / fs
d_hat = v_air * T_hat / 2
print("Estimated delay (s):", T_hat)
print("Estimated range (m):", d_hat)
# ----- (B) LiDAR scan to Cartesian points -----
K = 360
phi = np.deg2rad(np.arange(K))
r_k = 2.0 + 0.2*np.sin(3*phi) # synthetic range profile (m)
x = r_k * np.cos(phi)
y = r_k * np.sin(phi)
points = np.stack([x, y], axis=1)
print("First 5 points:\n", points[:5])
Libraries often used in robotics for real sensors: NumPy for numeric processing, SciPy for correlation/FFT, and open3d or PCL bindings for point-cloud work (introduced fully later).
7. C++ Implementation — Correlation ToF Estimator
This example implements discrete correlation from scratch and computes range.
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
int main() {
const double fs = 200000.0;
const double f0 = 40000.0;
const double v_air = 343.0;
const int N = 2000; // 0.01 s at 200 kHz
const int pulseN = 200; // 0.001 s pulse
std::vector<double> s(N, 0.0), r(N, 0.0);
// transmit pulse
for(int n = 0; n < pulseN; ++n) {
double t = n / fs;
s[n] = std::sin(2*M_PI*f0*t);
}
// create delayed echo
double T_true = 0.0075;
int dSamp = static_cast<int>(T_true * fs);
double alpha = 0.6;
for(int n = dSamp; n < N; ++n) {
r[n] = alpha * s[n - dSamp];
}
// full correlation C[k] = sum_n r[n] s[n-k]
std::vector<double> C(2*N - 1, 0.0);
for(int k = -(N-1); k <= (N-1); ++k) {
double sum = 0.0;
for(int n = 0; n < N; ++n) {
int idx = n - k;
if(idx >= 0 && idx < N) sum += r[n] * s[idx];
}
C[k + (N-1)] = sum;
}
auto it = std::max_element(C.begin(), C.end());
int k_hat = static_cast<int>(std::distance(C.begin(), it)) - (N-1);
double T_hat = k_hat / fs;
double d_hat = v_air * T_hat / 2.0;
std::cout << "Estimated delay: " << T_hat << " s\n";
std::cout << "Estimated range: " << d_hat << " m\n";
return 0;
}
For faster correlation in practice, C++ robotics stacks use FFT libraries such as FFTW or Eigen’s FFT module.
8. Java Implementation — Discrete Correlation ToF
import java.util.Arrays;
public class ToFCorrelation {
public static void main(String[] args) {
double fs = 200000.0;
double f0 = 40000.0;
double vAir = 343.0;
int N = 2000;
int pulseN = 200;
double[] s = new double[N];
double[] r = new double[N];
// transmit pulse
for (int n = 0; n < pulseN; n++) {
double t = n / fs;
s[n] = Math.sin(2.0 * Math.PI * f0 * t);
}
// delayed echo
double Ttrue = 0.0075;
int dSamp = (int)(Ttrue * fs);
double alpha = 0.6;
for (int n = dSamp; n < N; n++) {
r[n] = alpha * s[n - dSamp];
}
// full correlation
double[] C = new double[2 * N - 1];
int offset = N - 1;
for (int k = -(N - 1); k <= (N - 1); k++) {
double sum = 0.0;
for (int n = 0; n < N; n++) {
int idx = n - k;
if (idx >= 0 && idx < N) sum += r[n] * s[idx];
}
C[k + offset] = sum;
}
int kHat = 0;
double maxVal = C[0];
for (int i = 1; i < C.length; i++) {
if (C[i] > maxVal) {
maxVal = C[i];
kHat = i - offset;
}
}
double THat = kHat / fs;
double dHat = vAir * THat / 2.0;
System.out.println("Estimated delay (s): " + THat);
System.out.println("Estimated range (m): " + dHat);
}
}
Java robotics projects often rely on libraries like EJML (linear algebra) and JTransforms (FFT) for real-time sensor processing.
9. MATLAB/Simulink Implementation — Chirp RADAR Range and Doppler
FMCW RADAR estimates range from beat frequency and velocity from Doppler shift. A linear chirp has instantaneous frequency \( f(t)=f_c + kt \): where slope \( k=B/T_c \). The beat frequency for a target at delay \( T \) is approximately:
\[ f_b \approx kT. \]
Therefore: \( d=\frac{c}{2k} f_b \):
% ----- Parameters -----
fs = 2e6; % sampling rate
Tc = 2e-3; % chirp duration
B = 200e6; % bandwidth
fc = 77e9; % carrier (mmWave)
c = 3e8;
k = B / Tc; % chirp slope
% ----- Transmit chirp -----
t = (0:1/fs:Tc-1/fs).';
s = exp(1j*2*pi*(fc*t + 0.5*k*t.^2));
% ----- Simulate delayed echo + Doppler -----
d_true = 20; % meters
vr_true = 3; % m/s radial velocity
T_true = 2*d_true/c;
fd = 2*vr_true*fc/c; % Doppler frequency
delaySamp = round(T_true*fs);
r = zeros(size(s));
r(delaySamp+1:end) = 0.8*s(1:end-delaySamp).*exp(1j*2*pi*fd*t(1:end-delaySamp));
% ----- Mix (dechirp) to get beat signal -----
bSig = r .* conj(s);
% ----- FFT to estimate beat frequency -----
N = length(bSig);
Bf = abs(fft(bSig));
[~, idx] = max(Bf(1:floor(N/2)));
fb_hat = (idx-1)*fs/N;
d_hat = (c/(2*k)) * fb_hat;
fprintf("Estimated range: %.2f m\n", d_hat);
% ----- Doppler via phase slope across chirps (toy: single chirp) -----
% For multi-chirp processing, stack beat signals and FFT over slow-time.
Simulink hint: A basic ToF model can be built using blocks: Chirp Signal → Transport Delay → Gain → Sum (with noise) → Product (mixing) → FFT.
10. Problems and Solutions
Problem 1 (Ultrasonic Distance with Temperature): An ultrasonic sensor measures a round-trip delay of \( T=6.0 \) ms in air at \( T_c=25^\circ \)C. Compute the distance. Then compute the distance if the algorithm incorrectly assumes \( T_c=0^\circ \)C.
Solution:
The speed at \( 25^\circ \)C is \( v_{25} = 331.3 + 0.606(25)=346.45\ \text{m/s} \):.
\[ d_{25}=\frac{v_{25}T}{2}=\frac{346.45\times 6.0\times 10^{-3}}{2} \approx 1.039\ \text{m}. \]
If assuming \( 0^\circ \)C, \( v_0=331.3 \) m/s, hence
\[ d_0 = \frac{331.3\times 6.0\times 10^{-3}}{2} \approx 0.994\ \text{m}. \]
The bias is about \( 4.5 \) cm.
Problem 2 (LiDAR Range Resolution): A pulsed LiDAR has effective bandwidth \( B=300 \) MHz. What is its theoretical range resolution?
Solution:
\[ \Delta d = \frac{c}{2B} = \frac{3\times 10^8}{2\times 3\times 10^8} = 0.5\ \text{m}. \]
Problem 3 (Radar Doppler Velocity): An automotive radar at \( f_c=77 \) GHz measures Doppler shift \( f_d=1.54 \) kHz. Estimate radial velocity.
Solution:
\[ v_r = \frac{c f_d}{2 f_c} = \frac{3\times 10^8 \times 1.54\times 10^3}{2\times 77\times 10^9} \approx 3.0\ \text{m/s}. \]
Problem 4 (Beamwidth Comparison): Two ultrasonic transducers have the same frequency (wavelength \( \lambda=8.5 \) mm) but radii \( a_1=5 \) mm and \( a_2=15 \) mm. Compare their approximate half-power beamwidths.
Solution:
\[ \theta_{1}\approx 0.51\frac{\lambda}{a_1} =0.51\frac{8.5}{5}\approx 0.867\ \text{rad}, \quad \theta_{2}\approx 0.51\frac{8.5}{15}\approx 0.289\ \text{rad}. \]
The larger transducer has roughly three times narrower beam.
Problem 5 (Radar Power Falloff): Using the radar equation scaling, by what factor does received power change if distance doubles?
Solution:
Since \( P_r(d)\propto d^{-4} \): doubling distance gives \( P_r(2d)/P_r(d)=2^{-4}=1/16 \):. Received power drops by a factor of sixteen.
11. Summary
We unified ultrasonic, LiDAR, and RADAR under a wave-based delay model, derived the central time-of-flight equation \( d=vT/2 \):, and showed how bandwidth governs range resolution \( \Delta d=c/(2B) \):. Ultrasonic sensing is cost-effective but environmentally sensitive; LiDAR provides high-fidelity geometry; RADAR offers robustness and direct velocity via Doppler. The provided implementations demonstrated correlation ToF, scan-to-point conversion, and chirp radar ranging.
12. References
- Skolnik, M.I. (1962). An analysis of radar range resolution. IRE Transactions on Information Theory, 8(2), 95–100.
- Cook, C.E., & Bernfeld, M. (1967). Radar signals: An introduction to theory and application. IEEE Transactions on Aerospace and Electronic Systems, 3(5), 688–699.
- Bufton, J.L. (1989). Laser altimetry measurements from aircraft and spacecraft. Proceedings of the IEEE, 77(3), 463–477.
- Kamakura, A., & Hasegawa, T. (1993). Theoretical limits on ultrasonic time-of-flight estimation by correlation. IEEE Transactions on Ultrasonics, Ferroelectrics, and Frequency Control, 40(5), 557–564.
- Richards, M.A. (2005). Fundamental principles of matched filtering for range and Doppler estimation. IEEE Signal Processing Magazine, 22(3), 44–56.
- Levanon, N., & Mozeson, E. (2004). Ambiguity function analysis for wideband ranging waveforms. IEEE Transactions on Aerospace and Electronic Systems, 40(4), 1279–1291.