第六篇 Scene 场景采集
第25章 Sensor
本章大纲
- Sensor 定义
- Camera
- Distance
- Position
- Motion
- Temperature
- Direction
- Acceleration
- Custom Sensor
- Sensor 数据统一
- Sensor → SceneCollector
25.1 Sensor 定义
**Sensor(传感器)**是 SAI Framework 用于从外部环境、设备或对象中获取某类可测量信息的输入组件。
简单来说:
Sensor 负责“测量和获取”,而不是“理解和决策”。
例如:
Temperature Sensor
↓
32℃
Distance Sensor
↓
5m
Position Sensor
↓
x=120, y=80
Sensor 获取的是原始或结构化数据。
然后:
Sensor
↓
Sensor Data
↓
Information
↓
SceneCollector
↓
Scene
↓
Perception
Sensor 与 InformationSource
第21章已经定义了 InformationSource。
Sensor 可以作为一种具体的 InformationSource:
InformationSource
│
├── Human
├── Device
├── Sensor
├── System
├── API
└── Environment
因此:
Sensor
↓
InformationSource
↓
Information
Sensor 本身负责获取数据。
InformationSource 则负责描述:
谁提供了这条信息?
例如:
sensor-001
type = temperature
name = Room Temperature Sensor
产生:
32℃
形成:
Information
{
source = sensor-001,
type = data,
content = 32
}
25.2 Camera
Camera 是一种视觉信息采集 Sensor。
它可以获取:
Image
Video
Object Position
Object Movement
Scene Change
例如:
Camera
↓
Image
↓
Objects
├── Person
├── Car
└── Door
需要注意:
Camera 本身主要负责获取视觉数据。
例如:
Camera
→ Image
而:
Image
→ Person
→ Car
→ Door
属于后续的视觉信息处理或 Perception。
因此:
Camera
→ 获取视觉数据
Perception
→ 从视觉数据中识别场景对象
这符合 SAI 的模块职责分离。
Camera 数据
可以统一成:
{
sensor_id: "camera-001",
type: "camera",
time: "2026-09-12 14:20:00",
content: "image-data"
}
实际系统中 content 可以是:
Image
Frame
Video Frame
Image File
Device Data
具体格式由 Camera Adapter 或设备接口决定。
25.3 Distance
Distance Sensor 用于获取对象之间或者传感器与目标之间的距离。
例如:
DistanceSensor
↓
5m
或者:
Robot → Person = 5m
Robot → Wall = 2m
Car → Obstacle = 12m
基本数据:
{
sensor_id: "distance-001",
type: "distance",
value: 5,
unit: "m"
}
Distance 可以来自:
Ultrasonic
LiDAR
Infrared
Camera
Position Calculation
Sensor 只负责获取:
distance = 5m
而:
5m 是否危险?
属于后续的:
Perception
Cognition
Reasoning
Decision
25.4 Position
Position Sensor 用于获取对象、设备或者 Individual 的空间位置。
例如:
PositionSensor
↓
x = 120
y = 80
z = 2
也可以是:
latitude
longitude
altitude
或者简单的位置:
location = living-room
Position 数据可以统一为:
{
sensor_id: "position-001",
type: "position",
x: 120,
y: 80,
z: 2
}
Position 与 Scene
Position 是 Scene 的重要组成部分:
PositionSensor
↓
Position Information
↓
SceneCollector
↓
Scene
↓
Object Position
例如:
Person
position = x120,y80
这样 Scene 才能知道:
对象是谁
对象在哪里
对象之间距离多少
25.5 Motion
Motion Sensor 用于获取对象或者设备的运动状态。
例如:
MotionSensor
↓
moving
也可以获取:
speed
direction
velocity
movement_state
例如:
Car
├── speed = 40 km/h
├── direction = north
└── movement = moving
Motion 数据:
{
sensor_id: "motion-001",
type: "motion",
speed: 40,
direction: "north",
state: "moving"
}
Motion 与 Position
位置是:
当前位置
运动是:
位置如何变化
例如:
14:20
x=100,y=50
14:21
x=110,y=50
可以得到:
对象发生移动
但这个变化分析属于后续处理。
Sensor 负责获取:
位置
速度
方向
加速度
而不是直接进行行为判断。
25.6 Temperature
Temperature Sensor 用于获取温度。
例如:
TemperatureSensor
↓
32℃
数据结构:
{
sensor_id: "temperature-001",
type: "temperature",
value: 32,
unit: "C"
}
也可以存在多个温度传感器:
Room A → 25℃
Room B → 30℃
Machine → 70℃
Outdoor → 28℃
通过 sensor_id 区分:
temperature-001
temperature-002
temperature-003
temperature-004
Temperature 与 Scene
例如:
TemperatureSensor
↓
32℃
↓
Information
↓
SceneCollector
↓
Scene.environment.temperature
最终:
Scene
└── Environment
└── Temperature = 32℃
后面的认知系统才可以进一步处理:
当前温度是否正常?
是否过高?
是否需要采取行动?
25.7 Direction
Direction Sensor 或方向数据用于获取对象当前朝向或运动方向。
例如:
direction = north
或者:
angle = 90°
也可以使用:
heading
yaw
pitch
roll
在简单 SAI 模型中,可以先统一成:
{
type: "direction",
value: "north"
}
或者:
{
type: "direction",
angle: 90
}
Direction 的两种意义
方向需要注意两种情况。
1. 对象朝向
Robot
heading = north
2. 对象运动方向
Car
movement_direction = east
两者可能相同,也可能不同。
因此最好在数据结构中明确区分。
orientation
movement_direction
25.8 Acceleration
Acceleration Sensor 用于获取加速度变化。
例如:
AccelerationSensor
↓
2.5 m/s²
三轴数据:
x = 1.2
y = 0.5
z = 0.8
统一结构:
{
sensor_id: "acceleration-001",
type: "acceleration",
x: 1.2,
y: 0.5,
z: 0.8,
unit: "m/s2"
}
加速度数据可以支持后续:
Motion
State
Device State
Vehicle State
Robot State
例如:
Acceleration
↓
Motion
↓
Object State
↓
Scene
但 Sensor 本身不负责判断:
是否发生碰撞?
是否紧急制动?
是否危险?
这些属于后续处理。
25.9 Custom Sensor
SAI Framework 不应该把 Sensor 限制在固定的几种类型。
现实世界中可能存在:
PressureSensor
HumiditySensor
SoundSensor
GasSensor
SmokeSensor
LightSensor
VibrationSensor
WeightSensor
CustomDeviceSensor
因此需要支持:
Custom Sensor(自定义传感器)
例如:
PressureSensor
↓
101.3 kPa
或者:
HumiditySensor
↓
65%
或者用户自行定义:
MySensor
↓
custom-value
Custom Sensor 接口
可以定义统一接口:
<?php
namespace SAI\Scene;
interface SensorInterface
{
public function getId();
public function getType();
public function read();
}
温度 Sensor:
<?php
namespace SAI\Scene;
class TemperatureSensor implements SensorInterface
{
public function getId()
{
return 'temperature-001';
}
public function getType()
{
return 'temperature';
}
public function read()
{
return array(
'value' => 32,
'unit' => 'C'
);
}
}
距离 Sensor:
<?php
namespace SAI\Scene;
class DistanceSensor implements SensorInterface
{
public function getId()
{
return 'distance-001';
}
public function getType()
{
return 'distance';
}
public function read()
{
return array(
'value' => 5,
'unit' => 'm'
);
}
}
这样不同 Sensor 就拥有统一接口。
25.10 Sensor 数据统一
这是本章的核心。
不同 Sensor 的数据格式不同:
Temperature
→ 32
Distance
→ 5m
Position
→ x120,y80
Motion
→ moving
Direction
→ north
Acceleration
→ x1.2,y0.5,z0.8
如果后续系统分别处理这些格式,系统会越来越复杂。
因此需要统一成:
SensorData
{
sensor_id
sensor_type
value
unit
time
state
metadata
}
统一 SensorData
例如温度:
{
sensor_id: "temperature-001",
sensor_type: "temperature",
value: 32,
unit: "C",
time: "...",
state: "valid"
}
距离:
{
sensor_id: "distance-001",
sensor_type: "distance",
value: 5,
unit: "m",
time: "...",
state: "valid"
}
位置:
{
sensor_id: "position-001",
sensor_type: "position",
value: {
x: 120,
y: 80,
z: 2
},
time: "...",
state: "valid"
}
SensorData 的意义
统一以后:
Camera
Distance
Position
Motion
Temperature
Direction
Acceleration
Custom
│
▼
SensorData
│
▼
Information
│
▼
SceneCollector
后面的系统不需要关心每个传感器的底层接口差异。
25.11 Sensor → SceneCollector
这是本章最终要建立的关系。
Sensor
│
│ read()
▼
SensorData
│
▼
Information
│
▼
SceneCollector
│
├── Environment
├── Object
├── Position
├── Motion
├── Distance
└── State
│
▼
Scene
一个完整案例
假设一个机器人处于房间中。
机器人拥有:
Camera
DistanceSensor
PositionSensor
MotionSensor
TemperatureSensor
Camera
Camera
→ Image
Distance
DistanceSensor
→ 5m
Position
PositionSensor
→ x=120,y=80
Motion
MotionSensor
→ speed=2m/s
Temperature
TemperatureSensor
→ 28℃
统一
SceneCollector 获得:
SensorData
├── Camera
├── Distance
├── Position
├── Motion
└── Temperature
转换成 Scene:
Scene
│
├── Time
│ └── 14:20:00
│
├── Space
│ └── Room
│
├── Environment
│ └── Temperature = 28℃
│
├── Objects
│ └── Robot
│
├── Position
│ └── Robot = x120,y80
│
├── Motion
│ └── Robot = moving
│
└── Distance
└── Robot → Object = 5m
最终:
Camera ──────────┐
DistanceSensor ──┤
PositionSensor ──┤
MotionSensor ────┤
TemperatureSensor┘
│
▼
SensorData
│
▼
Information
│
▼
SceneCollector
│
▼
Scene
│
▼
Perception
25.12 Sensor 的基础类设计
可以进一步建立基础 Sensor:
<?php
namespace SAI\Scene;
abstract class Sensor
{
protected $id;
protected $type;
protected $state;
public function __construct($id, $type)
{
$this->id = $id;
$this->type = $type;
$this->state = 'online';
}
public function getId()
{
return $this->id;
}
public function getType()
{
return $this->type;
}
public function getState()
{
return $this->state;
}
public function setState($state)
{
$this->state = $state;
}
abstract public function read();
}
温度 Sensor:
<?php
namespace SAI\Scene;
class TemperatureSensor extends Sensor
{
public function __construct($id)
{
parent::__construct($id, 'temperature');
}
public function read()
{
return array(
'value' => 32,
'unit' => 'C'
);
}
}
调用:
$sensor = new TemperatureSensor('temperature-001');
$data = $sensor->read();
得到:
{
value: 32,
unit: "C"
}
25.13 SensorManager
当系统拥有多个 Sensor 时,可以使用管理器:
<?php
namespace SAI\Scene;
class SensorManager
{
protected $sensors = array();
public function register(Sensor $sensor)
{
$this->sensors[$sensor->getId()] = $sensor;
}
public function get($id)
{
if (!isset($this->sensors[$id])) {
return null;
}
return $this->sensors[$id];
}
public function all()
{
return $this->sensors;
}
}
注册:
$manager = new SensorManager();
$manager->register(
new TemperatureSensor('temperature-001')
);
于是:
SensorManager
│
├── temperature-001
├── distance-001
├── position-001
├── motion-001
└── camera-001
25.14 Sensor 与 SceneCollector 的职责边界
最终可以明确:
| 组件 | 职责 |
|---|---|
| Sensor | 获取某类测量数据 |
| SensorManager | 管理 Sensor |
| InformationSource | 描述数据来源 |
| InformationReceiver | 接收信息 |
| Information | 统一的信息对象 |
| SceneCollector | 汇总信息形成 Scene |
| Scene | 描述当前场景 |
| Perception | 对场景进行感知 |
所以:
Sensor
→ 测量
InformationReceiver
→ 接收
SceneCollector
→ 汇总
Scene
→ 描述
Perception
→ 感知
这几个层次不能混淆。
本章完整架构
外部世界
│
┌──────────────────┼──────────────────┐
▼ ▼ ▼
Environment Object Device
│ │ │
└──────────────────┼──────────────────┘
│
Sensor
│
┌──────────┬─────────┼─────────┬──────────┐
▼ ▼ ▼ ▼ ▼
Camera Distance Position Motion Temperature
│ │ │ │ │
└──────────┴─────────┼─────────┴──────────┘
│
Direction / Acceleration
│
▼
SensorData
│
▼
Information
│
▼
InformationReceiver
│
▼
SceneCollector
│
▼
Scene
│
▼
Perception
本章小结
Sensor 是 SAI Framework 的外部数据采集基础组件。
本章建立了:
Sensor
├── Camera
├── Distance
├── Position
├── Motion
├── Temperature
├── Direction
├── Acceleration
└── Custom Sensor
这些 Sensor 最终通过统一的数据结构进入 SAI:
Sensor
↓
SensorData
↓
Information
↓
InformationReceiver
↓
SceneCollector
↓
Scene
↓
Perception
最重要的职责边界是:
Sensor 负责获取数据,InformationReceiver 负责接收信息,SceneCollector 负责组织场景,Scene 负责描述场景,Perception 才负责感知场景。
这样,第19章到第25章已经形成了一条完整的信息与场景输入链:
Information
↓
InformationType
↓
InformationSource
↓
InformationReceiver
↓
Scene
↑
SceneCollector
↑
Sensor
而下一阶段进入 Central 时,就可以把已经建立好的 Information → Scene 输入体系与 SAI Individual 的内部协调机制连接起来。
以上 PHP 代码是本章的设计示例,用于说明 SAI Framework 的 OOP 结构,未作为实际项目代码执行验证。