第206章 State Class|状态类
建立对象和环境的实时状态
第203章到第205章已经依次建立:
Element
元素
↓
Object
对象
↓
Attribute
属性
↓
Relation
关系
现在系统已经能够描述:
有什么对象
对象有什么属性
对象之间有什么关系
但机器真正面对现实世界时,还必须回答一个更重要的问题:
这些对象和关系在当前这一时刻处于什么状态?
因此,第206章建立 State Class|状态类。
206.1 State|状态
ICAI 中的 State 不是简单的:
$status = 'active';
状态表示的是:
对象、环境以及它们之间关系在某一个时间点上的动态状态。
例如机械手抓取鸡蛋:
Hand
机械手
Position = ...
Velocity = ...
Force = ...
Pressure = ...
Egg
鸡蛋
Position = ...
Distance = ...
Fragility = ...
Stability = ...
Relation
Hand → contacts → Egg
这些实时信息共同决定当前状态。
可以表示为:
Statet=F(Objectt,Attributet,Relationt,Environmentt)State_t = F(Object_t, Attribute_t, Relation_t, Environment_t)
即:
当前状态
↓
对象
+
属性
+
关系
+
环境
206.2 State 不是固定标签
不能简单设计成:
Egg = "normal"
因为现实世界一直变化。
例如:
Egg
正常
↓
被接近
↓
被接触
↓
被施加压力
↓
被抓取
↓
被移动
↓
被释放
因此:
State(t0)
↓
State(t1)
↓
State(t2)
↓
State(t3)
状态本质上是一个动态过程。
206.3 State Class|状态类
建立基础 Class:
<?php
class State
{
protected $name;
protected $value;
protected $timestamp;
protected $source;
protected $status;
}
其中:
Name
状态名称
Value
状态内容
Timestamp
状态时间
Source
状态来源
Status
状态有效状态
例如:
State
name = contact
value = true
timestamp = ...
source = tactile_sensor
status = active
206.4 State Instance|状态实例
Class 定义结构。
真正运行的是:
$state = new State(
'contact',
true,
'tactile_sensor'
);
于是:
State Class
状态类
↓
State Instance
状态实例
例如:
Egg Contact State
Name = contact
Value = true
Source = tactile_sensor
206.5 Object State|对象状态
Object 可以拥有自己的 State。
例如:
Egg Object
鸡蛋对象
↓
Current State
当前状态
可以在 Object 中增加:
protected $state;
并提供:
public function setState(State $state)
{
$this->state = $state;
}
public function getState()
{
return $this->state;
}
于是:
$egg->setState($state);
对象就拥有了当前状态。
206.6 状态由动态属性产生
例如:
Egg
Position = [10,20,30]
Distance = 0.03
Pressure = 0.20
Force = 0.15
Stability = 0.92
系统根据这些实时属性判断:
Contact = true
于是形成:
Egg
↓
Attributes
↓
Current Values
↓
State
因此 State 并不是脱离数据凭空产生的。
它来自实时对象信息。
206.7 Relation State|关系状态
第205章已经建立 Relation。
关系本身也会变化。
例如:
Hand → near → Egg
当距离继续下降:
Hand → contacts → Egg
因此关系状态可以表示:
Relation
↓
State
例如:
Relation Type = contacts
State = active
或者:
Relation Type = contacts
State = inactive
因此:
Object State
对象状态
Relation State
关系状态
都属于 ICAI 动态状态体系。
206.8 Environment State|环境状态
ICAI 不只需要维护 Object State。
还必须维护:
Environment State|环境状态。
例如机器人面对桌面:
Environment
环境
│
├── Table
├── Egg
├── Robot Hand
├── Light
├── Temperature
├── Obstacles
└── Free Space
这些信息共同构成:
Current Environment State
当前环境状态
例如:
Table = stable
Egg = stationary
Hand = moving
Obstacle = detected
Light = sufficient
206.9 Environment 也是动态的
环境不是静态背景。
例如:
t0
Egg
on Table
Hand
far
然后:
t1
Hand
near Egg
再到:
t2
Hand
contacts Egg
再到:
t3
Hand
holds Egg
环境状态一直发生变化:
Environmentt+1≠EnvironmenttEnvironment_{t+1} \neq Environment_t
因此 ICAI 必须持续更新环境状态。
206.10 State Update|状态更新
建立状态更新方法:
public function update(
$value,
$source = null
) {
$this->value = $value;
if ($source !== null) {
$this->source = $source;
}
$this->timestamp = time();
}
这样:
State
↓
Old Value
↓
New Value
↓
Timestamp Update
就形成了实时状态更新。
206.11 状态变化
例如:
contact = false
变成:
contact = true
程序:
$state->update(
true,
'tactile_sensor'
);
系统记录:
Old State
false
↓ update
New State
true
因此状态变化本身成为系统运行的一部分。
206.12 State Transition|状态转换
状态之间还可以形成转换:
Far
↓
Near
↓
Contact
↓
Hold
↓
Move
↓
Release
这不是为每一个场景写一套程序。
而是对象的:
Attribute
+
Relation
+
Real-Time Data
发生变化以后,状态自然发生转换。
因此:
Statet+1=F(Statet,Datat)State_{t+1} = F(State_t,Data_t)
更进一步:
Statet+1=F(Statet,Attributest,Relationst,Environmentt)State_{t+1} = F( State_t, Attributes_t, Relations_t, Environment_t )
这为后面的 Dynamic Cognition 打下基础。
206.13 State 与人工行为逻辑
这正好对应人的行为逻辑。
人抓鸡蛋时,并不是:
发现鸡蛋
↓
执行固定代码
而是持续感知:
鸡蛋在哪里?
↓
手在哪里?
↓
距离多远?
↓
是否接触?
↓
压力多大?
↓
鸡蛋是否稳定?
↓
是否继续施力?
这些都是:
State
状态
不断变化。
人的行为实际上是:
感知
↓
当前状态
↓
判断
↓
动作
↓
状态变化
↓
再次感知
ICAI 的工程结构也采用同样的循环。
206.14 State Runtime|状态运行时
因此系统运行时可以形成:
Real-Time Data
实时数据
↓
Element
元素
↓
Object
对象
↓
Attribute
属性
↓
Relation
关系
↓
State
状态
↓
Current World Condition
当前世界状态
这时机器已经不仅仅拥有对象数据库。
而拥有:
一个不断更新的实时世界状态。
206.15 State Class 基础实现
本章可以先建立基础版本:
<?php
class State
{
protected $name;
protected $value;
protected $timestamp;
protected $source;
protected $status;
public function __construct(
$name,
$value,
$source = null
) {
$this->name = $name;
$this->value = $value;
$this->source = $source;
$this->timestamp = time();
$this->status = 'active';
}
public function getName()
{
return $this->name;
}
public function getValue()
{
return $this->value;
}
public function getTimestamp()
{
return $this->timestamp;
}
public function getSource()
{
return $this->source;
}
public function getStatus()
{
return $this->status;
}
public function update(
$value,
$source = null
) {
$this->value = $value;
if ($source !== null) {
$this->source = $source;
}
$this->timestamp = time();
$this->status = 'updated';
}
}
206.16 一个实际运行实例
例如:
$eggContactState = new State(
'contact',
false,
'tactile_sensor'
);
开始时:
Egg
↓
Contact State
↓
false
机械手接触鸡蛋:
$eggContactState->update(
true,
'tactile_sensor'
);
现在:
Egg
↓
Contact State
↓
true
如果压力继续增加:
Pressure
0.10
↓
0.20
↓
0.30
状态系统持续获得新的实时信息。
206.17 本章暂不负责行为决策
这里必须保持架构边界。
第206章只负责:
State
状态
不负责:
Cognition
认知
Method
方法
Action
动作
Behavior
行为
也就是说:
State
↓
告诉系统“现在是什么状态”
而不是:
State
↓
直接决定“下一步做什么”
下一层才会进入认知和方法。
这样整个工程不会混乱。
206.18 第206章形成的完整对象链
到这里:
Real-Time Data
实时数据
↓
Element
元素
↓
Object
对象
↓
Attribute
属性
↓
Relation
关系
↓
State
状态
软件工程对应:
Element Class
↓
Object Class
↓
Attribute Class
↓
Relation Class
↓
State Class
Runtime 对应:
Element Instance
↓
Object Instance
↓
Attribute Instance
↓
Relation Instance
↓
State Instance
206.19 ICAI 当前世界表示
因此,一个简单的现实场景现在可以被表示为:
Environment
环境
│
┌──────────────┼──────────────┐
↓ ↓ ↓
Hand Egg Table
机械手 鸡蛋 桌面
│ │ │
Attributes Attributes Attributes
│ │ │
└──────────────┼──────────────┘
↓
Relations
关系
↓
State
状态
而且这个结构不是静态的。
随着实时数据进入:
Real-Time Data
↓
Attribute Update
↓
Relation Update
↓
State Update
↓
New World State
整个系统持续变化。
206.20 本章核心结论
State Class 将 ICAI 从“描述世界”推进到“表示世界当前状态”。
前面的:
Object
解决:
有什么。
Attribute
解决:
有什么特征。
Relation
解决:
对象之间有什么关系。
而:
State
解决:
现在处于什么状态。
最终形成:
Real-Time Data
↓
Element
↓
Object
↓
Attribute
↓
Relation
↓
State
这一步完成后,ICAI 才真正拥有了一个可以持续变化的实时世界状态层(Real-Time World State Layer)。
下一章再进入 第207章 Scene Class|场景类:
Objects
+
Attributes
+
Relations
+
States
↓
Scene
场景
也就是把当前分散的对象、属性、关系和状态,在同一个时间点组织成一个完整的实时场景实例。