Short-Range Sensors
Overview
Short-range sensors detect obstacles, cliffs, and physical contact around a robot at close distances (typically <5m). They serve as the last line of defense in robot safety systems and are widely used in robot vacuums, service robots, and industrial robots.
Infrared Proximity Sensors
Working Principle
Infrared proximity sensors emit modulated infrared light and measure distance by detecting the intensity or position of reflected light.
Reflective ranging:
Where \(\rho\) is the target surface reflectivity and \(d\) is the distance. Received signal intensity decays with the square of distance.
Sharp GP2Y0A21YK0F
The most classic infrared distance sensor, using triangulation.
| Parameter | Value |
|---|---|
| Range | 10-80 cm |
| Output | Analog voltage (nonlinear relationship with distance) |
| Response Time | ~39 ms |
| Supply | 4.5-5.5V |
| Current | ~30 mA |
| Size | 29.5 x 13 x 13.5 mm |
| Price | ~$10 |
Voltage-distance relationship (approximate):
Where \(V\) is the output voltage, and \(a\), \(b\) are empirical coefficients (requires calibration).
import numpy as np
def sharp_gp2y0a21_distance(voltage):
"""
Sharp GP2Y0A21 voltage to distance conversion
voltage: ADC read voltage (V)
Returns distance (cm)
"""
if voltage < 0.4 or voltage > 3.1:
return None # Out of valid range
# Empirical formula (adjust based on actual calibration)
distance = 29.988 * pow(voltage, -1.173)
return distance
Other Infrared Sensors
| Model | Range | Output | Features | Price |
|---|---|---|---|---|
| GP2Y0A21 | 10-80cm | Analog | Classic general-purpose | ~$10 |
| GP2Y0A02 | 20-150cm | Analog | Long range | ~$12 |
| GP2Y0A41SK | 4-30cm | Analog | Short range | ~$8 |
| TCRT5000 | 1-25mm | Analog | Reflective, suitable for line following | ~$0.5 |
Ultrasonic Sensors
Working Principle
Emits ultrasonic pulses (typically 40kHz) and measures echo time to calculate distance:
Where \(v_s \approx 343 \, \text{m/s}\) (speed of sound in air at 20 deg C).
Speed of Sound and Temperature
Speed of sound varies with temperature: \(v_s = 331.3 + 0.606 \cdot T\) (m/s), where \(T\) is temperature in Celsius. Accurate ranging requires temperature compensation.
HC-SR04
The most commonly used ultrasonic ranging module.
| Parameter | Value |
|---|---|
| Range | 2-400 cm |
| Accuracy | +/-3 mm |
| Beam Angle | ~15 deg (conical) |
| Operating Frequency | 40 kHz |
| Trigger Method | 10us high-level pulse |
| Supply | 5V |
| Current | ~15 mA |
| Price | ~$2 |
Usage:
- Send a >10us high-level pulse to the Trigger pin
- Module automatically sends 8 ultrasonic pulses at 40kHz
- Echo pin outputs a high level whose duration equals the echo time
import RPi.GPIO as GPIO
import time
TRIG = 23
ECHO = 24
def measure_distance():
"""HC-SR04 ranging"""
GPIO.output(TRIG, True)
time.sleep(0.00001) # 10us trigger pulse
GPIO.output(TRIG, False)
# Wait for Echo high level start
while GPIO.input(ECHO) == 0:
pulse_start = time.time()
# Wait for Echo high level end
while GPIO.input(ECHO) == 1:
pulse_end = time.time()
duration = pulse_end - pulse_start
distance = duration * 34300 / 2 # cm
return distance
Ultrasonic Limitations
| Problem | Cause | Impact |
|---|---|---|
| Conical beam | Ultrasonic spread angle ~15 deg | Low angular resolution, small objects may be missed |
| Specular reflection | Smooth angled surfaces deflect sound waves | Ranging failure |
| Sound-absorbing materials | Fabric, foam absorb sound | No echo |
| Crosstalk | Multiple ultrasonic modules interfere | Requires time-division multiplexing |
| Minimum distance | Time gap needed between emission and reception | Blind zone ~2cm |
ToF Proximity Sensors
Working Principle
Uses miniaturized laser ToF, emitting VCSEL lasers with SPAD detector reception.
VL53L0X
A micro ToF sensor from STMicroelectronics.
| Parameter | Value |
|---|---|
| Range | 30-2000 mm |
| Accuracy | +/-3% (long-range mode) |
| FOV | 25 deg (conical) |
| Light Source | 940nm VCSEL |
| Interface | I2C |
| Measurement Rate | Up to 50Hz |
| Supply | 2.6-3.5V |
| Size | 4.4 x 2.4 x 1.0 mm |
| Price | ~$3 |
VL53L1X (Upgraded Version)
| Parameter | Value |
|---|---|
| Range | 40-4000 mm |
| FOV | 27 deg (programmable ROI) |
| Measurement Rate | Up to 50Hz |
| Multi-Zone | Supports 4x4 zone detection |
| Price | ~$4 |
import board
import adafruit_vl53l0x
# I2C initialization
i2c = board.I2C()
sensor = adafruit_vl53l0x.VL53L0X(i2c)
# Read distance
distance_mm = sensor.range
print(f"Distance: {distance_mm} mm")
# Set measurement mode
sensor.measurement_timing_budget = 200000 # 200ms, high-accuracy mode
Cliff Sensors
Purpose
Cliff sensors are critical safety sensors on mobile platforms like robot vacuums and service robots, used to detect sudden drops in the ground surface (stairs, step edges) and prevent the robot from falling.
Working Principle
Uses downward-facing infrared reflective sensors to detect ground reflection signals:
- Normal ground: Infrared light is reflected back, strong received signal
- Cliff/step: Infrared light shoots into the distance, very weak or no reflected signal
Typical Configuration
Robot vacuums typically have 3-6 cliff sensors installed at the front bottom:
graph TD
subgraph "Robot Vacuum Bottom View (front at top)"
direction TB
A["Front Left"] --- B["Front Center"] --- C["Front Right"]
D["Side Left"] --- E["(Chassis)"] --- F["Side Right"]
end
style A fill:#ff6666
style B fill:#ff6666
style C fill:#ff6666
style D fill:#ff9966
style F fill:#ff9966
Common Sensors
| Model | Type | Detection Distance | Description | Price |
|---|---|---|---|---|
| TCRT5000 | IR reflective | 1-25mm | Most commonly used | ~$0.5 |
| ITR9608 | IR reflective | 1-15mm | Small package | ~$0.3 |
| QRD1114 | IR reflective | 1-10mm | Discrete | ~$1 |
Cliff Detection Reliability
Cliff sensors are safety-critical sensors. Note the following failure scenarios:
- Dark floors: Black carpet/flooring may be falsely detected as a cliff
- Transparent floors: Glass floors cannot reflect infrared light
- Sensor contamination: Dust coverage causes signal attenuation
- Strong ambient light: Direct sunlight may interfere with infrared detection
In actual products, multi-sensor redundancy + conservative strategies are used to ensure safety.
Bumper Sensors
Working Principle
Bumper sensors are the simplest short-range detection method -- physical contact triggers. Typically uses micro-switches or force-sensitive sensors.
Types
| Type | Principle | Advantages | Disadvantages |
|---|---|---|---|
| Micro-switch | Mechanical contacts | Simple, reliable, low cost | Requires physical contact |
| Force-sensitive resistor | Resistance changes with pressure | Can sense force magnitude | Requires ADC |
| Capacitive | Proximity changes capacitance | Non-contact (~1cm) | Environment-sensitive |
| Piezoelectric | Piezoelectric effect | Sensitive, fast response | Complex signal processing |
Robot Vacuum Bumper
Most robot vacuums use a front arc-shaped bumper with internal micro-switches or optical switches:
# Simple bumper interrupt handling
import RPi.GPIO as GPIO
BUMPER_LEFT = 17
BUMPER_RIGHT = 27
def bumper_callback(channel):
if channel == BUMPER_LEFT:
print("Left collision! Backing up and turning right")
# motor.backward()
# motor.turn_right()
elif channel == BUMPER_RIGHT:
print("Right collision! Backing up and turning left")
# motor.backward()
# motor.turn_left()
GPIO.setup(BUMPER_LEFT, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(BUMPER_RIGHT, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(BUMPER_LEFT, GPIO.FALLING,
callback=bumper_callback, bouncetime=200)
GPIO.add_event_detect(BUMPER_RIGHT, GPIO.FALLING,
callback=bumper_callback, bouncetime=200)
Robot Vacuum Sensor Layout
graph TD
subgraph "Robot Vacuum Sensor System"
subgraph "Top"
L["LiDAR<br>2D Laser Radar<br>360 deg SLAM"]
end
subgraph "Front"
B["Bumper<br>Collision Sensor<br>Left/Right Detection"]
IR["IR/ToF<br>Front Obstacle Avoidance<br>3-5cm to 2m"]
end
subgraph "Bottom"
C1["Cliff Sensors x4-6<br>IR Reflective<br>Fall Prevention"]
W["Wheel Encoders x2<br>Odometry"]
end
subgraph "Side"
WALL["Wall-Following Sensor<br>IR/ToF<br>Maintain Wall Distance"]
end
end
Sensor Coordination Logic
class VacuumRobotSafety:
"""Robot vacuum safety sensor management"""
def __init__(self):
self.cliff_threshold = 100 # ADC threshold
self.wall_distance = 50 # mm
self.obstacle_distance = 200 # mm
def check_cliff(self, cliff_sensors):
"""Check cliff sensors; emergency stop if any triggers"""
for i, value in enumerate(cliff_sensors):
if value < self.cliff_threshold:
return True, i # Cliff detected
return False, -1
def check_bumper(self, bumper_left, bumper_right):
"""Check bumper sensors"""
if bumper_left and bumper_right:
return 'front' # Head-on collision
elif bumper_left:
return 'left' # Left collision
elif bumper_right:
return 'right' # Right collision
return None
def safety_loop(self, sensors):
"""Safety check main loop - highest priority"""
# 1. Cliff detection (highest priority)
cliff_detected, cliff_id = self.check_cliff(
sensors['cliff'])
if cliff_detected:
return 'EMERGENCY_STOP', f'Cliff at sensor {cliff_id}'
# 2. Collision detection
bump = self.check_bumper(
sensors['bumper_left'],
sensors['bumper_right'])
if bump:
return 'BACKUP_AND_TURN', bump
# 3. Approaching obstacle
if sensors['front_tof'] < self.obstacle_distance:
return 'SLOW_DOWN', sensors['front_tof']
return 'NORMAL', None
Comprehensive Sensor Comparison
| Sensor | Range | Accuracy | Rate | Cost | Strength | Weakness |
|---|---|---|---|---|---|---|
| Sharp IR | 10-80cm | +/-1cm | 25Hz | $10 | Simple, reliable | Affected by lighting |
| HC-SR04 | 2-400cm | +/-3mm | 20Hz | $2 | Cheap | Low angular resolution |
| VL53L0X | 3-200cm | +/-3% | 50Hz | $3 | Compact, digital output | Limited range |
| Cliff IR | 1-25mm | Detection-level | Fast | $0.5 | Extremely low cost | Detect only presence/absence |
| Bumper | 0cm | Contact | Fast | $0.5 | Most reliable | Requires physical contact |
ROS2 Integration
Range Message
# sensor_msgs/msg/Range
Header header
uint8 radiation_type # ULTRASOUND=0, INFRARED=1
float32 field_of_view # Detection cone angle (rad)
float32 min_range # Minimum range (m)
float32 max_range # Maximum range (m)
float32 range # Current range (m)
Publishing Sensor Data
from sensor_msgs.msg import Range
def publish_ultrasonic(self, distance_m):
msg = Range()
msg.header.stamp = self.get_clock().now().to_msg()
msg.header.frame_id = 'ultrasonic_front'
msg.radiation_type = Range.ULTRASOUND
msg.field_of_view = 0.26 # ~15 deg
msg.min_range = 0.02
msg.max_range = 4.0
msg.range = distance_m
self.range_pub.publish(msg)
References
- Sharp GP2Y0A21 Datasheet
- HC-SR04 Technical Documentation
- STMicroelectronics VL53L0X/VL53L1X Datasheets
- iRobot Roomba Open Interface Specification
- ROS2 sensor_msgs Documentation