7.17 从理论对象到 PHP 对象
上一节建立了触觉感知元素理论模型。
现在进入 WSaiOS 的 PHP OOP 工程实现。
理论中的:
Touch Element
{
ID
Object
Contact
Pressure
Temperature
Material
Position
State
Relation
Event
}
在 PHP OOP 中对应:
class TouchElement
{
protected $id;
protected $object;
protected $contact;
protected $pressure;
protected $temperature;
protected $material;
protected $position;
protected $state;
protected $relations;
protected $events;
}
因此:
触觉感知元素可以直接映射为 WSaiOS 中的领域对象(Domain Object)。
但 TouchElement 只负责描述触觉对象本身,不负责数据库、控制器或页面输出。
7.18 WSaiOS Touch Engine 的 OOP 分层
触觉系统不能把所有功能写进 TouchElement。
例如:
class TouchElement
{
public function detect()
{
// 触觉检测
}
public function save()
{
// 数据库存储
}
public function render()
{
// 页面输出
}
}
这种结构会把:
触觉对象
+
触觉处理
+
数据库
+
页面显示
全部混在一起。
WSaiOS 应采用:
TouchElement
↓
Touch Service
↓
Touch Engine
↓
Repository
↓
Database
页面部分:
Controller
↓
Smarty
↓
HTML
因此形成:
Domain Object
Service
Engine
Repository
Controller
View
7.19 TouchElement Class 详细设计
建议目录:
app/
├── Models/
│ └── Touch/
│ ├── TouchElement.php
│ ├── ContactElement.php
│ ├── PressureElement.php
│ ├── TemperatureElement.php
│ ├── MaterialElement.php
│ ├── TouchPosition.php
│ ├── TouchRelation.php
│ ├── TouchEvent.php
│ └── TouchState.php
│
├── Services/
│ └── Touch/
│
├── Repositories/
│ └── Touch/
│
├── Controllers/
│ └── Touch/
│
└── Views/
└── touch/
核心对象:
<?php
class TouchElement
{
protected $id;
protected $object;
protected $contact;
protected $pressure;
protected $temperature;
protected $material;
protected $position;
protected $state;
protected $relations = [];
protected $events = [];
public function __construct(array $data = [])
{
$this->id = $data['id'] ?? null;
$this->object = $data['object'] ?? null;
$this->contact = $data['contact'] ?? null;
$this->pressure = $data['pressure'] ?? null;
$this->temperature = $data['temperature'] ?? null;
$this->material = $data['material'] ?? null;
$this->position = $data['position'] ?? null;
$this->state = $data['state'] ?? null;
$this->relations = $data['relations'] ?? [];
$this->events = $data['events'] ?? [];
}
public function getId()
{
return $this->id;
}
public function getObject()
{
return $this->object;
}
public function getContact()
{
return $this->contact;
}
public function getPressure()
{
return $this->pressure;
}
public function getTemperature()
{
return $this->temperature;
}
public function getMaterial()
{
return $this->material;
}
public function getPosition()
{
return $this->position;
}
public function getState()
{
return $this->state;
}
public function getRelations()
{
return $this->relations;
}
public function getEvents()
{
return $this->events;
}
}
这就是:
WSaiOS 触觉感知领域对象。
7.20 ContactElement 接触对象
触觉的第一个核心对象是:
ContactElement
它描述两个对象之间是否发生物理接触。
<?php
class ContactElement
{
protected $sourceObject;
protected $targetObject;
protected $state;
protected $location;
protected $time;
public function __construct(
$sourceObject,
$targetObject,
$state = 'contact',
array $location = [],
$time = null
) {
$this->sourceObject = $sourceObject;
$this->targetObject = $targetObject;
$this->state = $state;
$this->location = $location;
$this->time = $time;
}
public function getSourceObject()
{
return $this->sourceObject;
}
public function getTargetObject()
{
return $this->targetObject;
}
public function getState()
{
return $this->state;
}
public function getLocation()
{
return $this->location;
}
public function getTime()
{
return $this->time;
}
}
例如:
Robot Hand
↓
Contact
↓
Cup
对应:
$contact = new ContactElement(
'robot_hand',
'cup',
'stable_contact'
);
7.21 Contact State 接触状态
接触不是简单的:
true / false
而是一个状态过程:
No Contact
↓
Initial Contact
↓
Stable Contact
↓
Release
↓
No Contact
因此可以建立:
class ContactState
{
const NONE = 'none';
const INITIAL = 'initial';
const STABLE = 'stable';
const RELEASE = 'release';
protected $current;
public function __construct($current = self::NONE)
{
$this->current = $current;
}
public function getCurrent()
{
return $this->current;
}
}
这样触觉系统开始具备:
状态机特征。
7.22 PressureElement 压力对象
压力是触觉系统的重要物理属性。
理论结构:
Pressure Element
{
Value
Direction
Area
Change
}
PHP:
<?php
class PressureElement
{
protected $value;
protected $direction;
protected $area;
protected $change;
public function __construct(
$value = 0,
$direction = null,
$area = 0,
$change = 0
) {
$this->value = $value;
$this->direction = $direction;
$this->area = $area;
$this->change = $change;
}
public function getValue()
{
return $this->value;
}
public function getDirection()
{
return $this->direction;
}
public function getArea()
{
return $this->area;
}
public function getChange()
{
return $this->change;
}
}
形成:
TouchElement
│
└── PressureElement
7.23 Pressure 状态分析
压力本身只是数据。
真正的认知需要分析压力变化。
例如:
Pressure = 2N
变化:
Pressure = 5N
再变化:
Pressure = 8N
形成:
Pressure Increase
因此建立:
class PressureService
{
public function analyze(
PressureElement $current,
PressureElement $previous
) {
$change =
$current->getValue()
- $previous->getValue();
if ($change > 0) {
return 'increase';
}
if ($change < 0) {
return 'decrease';
}
return 'stable';
}
}
形成:
Pressure(t)
+
Pressure(t-1)
↓
Change
7.24 TemperatureElement 温度对象
温度同样对象化。
<?php
class TemperatureElement
{
protected $object;
protected $value;
protected $unit;
protected $change;
protected $state;
public function __construct(
$object,
$value,
$unit = 'C',
$change = 0,
$state = 'normal'
) {
$this->object = $object;
$this->value = $value;
$this->unit = $unit;
$this->change = $change;
$this->state = $state;
}
public function getObject()
{
return $this->object;
}
public function getValue()
{
return $this->value;
}
public function getUnit()
{
return $this->unit;
}
public function getChange()
{
return $this->change;
}
public function getState()
{
return $this->state;
}
}
7.25 TemperatureService 温度分析
例如:
Machine
Temperature:
60°C
历史:
50°C
形成:
Temperature Increase
服务:
class TemperatureService
{
public function analyze(
TemperatureElement $current,
TemperatureElement $previous
) {
$change =
$current->getValue()
- $previous->getValue();
if ($change > 0) {
return 'increase';
}
if ($change < 0) {
return 'decrease';
}
return 'stable';
}
}
因此:
Temperature
↓
Change
↓
State
7.26 MaterialElement 材质对象
触觉还可以描述材质。
<?php
class MaterialElement
{
protected $name;
protected $texture;
protected $hardness;
protected $elasticity;
protected $surface;
public function __construct(
$name = null,
$texture = null,
$hardness = null,
$elasticity = null,
$surface = null
) {
$this->name = $name;
$this->texture = $texture;
$this->hardness = $hardness;
$this->elasticity = $elasticity;
$this->surface = $surface;
}
public function getName()
{
return $this->name;
}
public function getTexture()
{
return $this->texture;
}
public function getHardness()
{
return $this->hardness;
}
public function getElasticity()
{
return $this->elasticity;
}
public function getSurface()
{
return $this->surface;
}
}
例如:
Material
Metal
Hard
Cold
Smooth
7.27 TouchPosition 接触位置对象
触觉需要知道:
在哪里接触。
因此建立:
<?php
class TouchPosition
{
protected $x;
protected $y;
protected $z;
protected $surface;
public function __construct(
$x = 0,
$y = 0,
$z = 0,
$surface = null
) {
$this->x = $x;
$this->y = $y;
$this->z = $z;
$this->surface = $surface;
}
public function toArray()
{
return [
'x' => $this->x,
'y' => $this->y,
'z' => $this->z,
'surface' => $this->surface
];
}
}
这样:
Touch
↓
Position
↓
Object Surface
形成空间化触觉。
7.28 TouchState 状态对象
触觉状态应该独立对象化。
<?php
class TouchState
{
protected $current;
protected $previous;
protected $change;
public function __construct(
$current = null,
$previous = null,
$change = null
) {
$this->current = $current;
$this->previous = $previous;
$this->change = $change;
}
public function getCurrent()
{
return $this->current;
}
public function getPrevious()
{
return $this->previous;
}
public function getChange()
{
return $this->change;
}
}
例如:
Holding
↓
Sliding
↓
Dropped
就是一个:
TouchState Transition
7.29 TouchRelation 触觉关系对象
触觉的本质之一是:
Actor
↓
Touch
↓
Object
因此:
<?php
class TouchRelation
{
protected $actor;
protected $object;
protected $type;
protected $state;
public function __construct(
$actor,
$object,
$type = 'touch',
$state = 'active'
) {
$this->actor = $actor;
$this->object = $object;
$this->type = $type;
$this->state = $state;
}
public function toArray()
{
return [
'actor' => $this->actor,
'object' => $this->object,
'type' => $this->type,
'state' => $this->state
];
}
}
例如:
Robot Hand
↓
Holding
↓
Cup
7.30 TouchEvent 触觉事件对象
当多个触觉变化组合后,就形成事件。
<?php
class TouchEvent
{
protected $object;
protected $contact;
protected $change;
protected $time;
protected $meaning;
public function __construct(
$object,
$contact,
$change,
$time = null,
$meaning = null
) {
$this->object = $object;
$this->contact = $contact;
$this->change = $change;
$this->time = $time;
$this->meaning = $meaning;
}
public function getObject()
{
return $this->object;
}
public function getContact()
{
return $this->contact;
}
public function getChange()
{
return $this->change;
}
public function getTime()
{
return $this->time;
}
public function getMeaning()
{
return $this->meaning;
}
}
例如:
Contact
↓
Pressure Increase
↓
Stable Hold
最终:
Object Grasp Event
7.31 TouchEventBuilder
事件不应该由 Controller 创建。
建立 Service:
class TouchEventBuilder
{
public function build(
TouchElement $element
) {
$state = $element->getState();
return new TouchEvent(
$element->getObject(),
$element->getContact(),
$state,
date('Y-m-d H:i:s'),
'touch_state_change'
);
}
}
因此:
TouchElement
↓
TouchEventBuilder
↓
TouchEvent
7.32 TouchElementService
领域对象建立之后,由 Service 负责业务处理。
<?php
class TouchElementService
{
protected $repository;
public function __construct(
TouchElementRepository $repository
) {
$this->repository = $repository;
}
public function create(array $data)
{
$element = new TouchElement($data);
return $this->repository->save($element);
}
public function get($id)
{
return $this->repository->find($id);
}
}
结构:
Controller
↓
TouchElementService
↓
TouchElement
↓
Repository
7.33 TouchAnalyzer
触觉系统需要一个统一分析器。
<?php
class TouchAnalyzer
{
protected $contactAnalyzer;
protected $pressureService;
protected $temperatureService;
protected $eventBuilder;
public function __construct(
$contactAnalyzer,
$pressureService,
$temperatureService,
$eventBuilder
) {
$this->contactAnalyzer =
$contactAnalyzer;
$this->pressureService =
$pressureService;
$this->temperatureService =
$temperatureService;
$this->eventBuilder =
$eventBuilder;
}
public function analyze(
TouchElement $element
) {
return [
'object' =>
$element->getObject(),
'contact' =>
$element->getContact(),
'pressure' =>
$element->getPressure(),
'temperature' =>
$element->getTemperature(),
'state' =>
$element->getState()
];
}
}
最终形成:
Touch Input
↓
TouchAnalyzer
↓
TouchElement
↓
Contact
Pressure
Temperature
Material
State
Relation
Event
7.34 Touch Engine
现在形成独立的:
WSaiOS Touch Engine
建议目录:
engine/
└── Touch/
├── TouchParser.php
├── ContactDetector.php
├── PressureAnalyzer.php
├── TemperatureAnalyzer.php
├── MaterialAnalyzer.php
├── TouchRelationBuilder.php
├── TouchEventBuilder.php
├── TouchStateAnalyzer.php
└── TouchAnalyzer.php
对应:
Input
↓
Parser
↓
Contact
↓
Pressure
↓
Temperature
↓
Material
↓
State
↓
Relation
↓
Event
↓
Analyzer
7.35 TouchParser
TouchParser 负责输入标准化。
<?php
class TouchParser
{
public function parse(array $input)
{
return [
'object' =>
$input['object'] ?? null,
'contact' =>
$input['contact'] ?? null,
'pressure' =>
$input['pressure'] ?? null,
'temperature' =>
$input['temperature'] ?? null,
'material' =>
$input['material'] ?? null,
'position' =>
$input['position'] ?? [],
'state' =>
$input['state'] ?? null
];
}
}
它不负责认知判断。
只负责:
触觉输入标准化。
7.36 ContactDetector
<?php
class ContactDetector
{
public function detect(array $touchData)
{
if (
isset($touchData['contact'])
&& $touchData['contact']
) {
return 'contact';
}
return 'none';
}
}
未来可以连接:
触觉传感器
机器人传感器
压力传感器
外部设备
规则引擎
AI Adapter
但:
TouchElement不应该知道数据来自什么设备。
7.37 PressureAnalyzer
<?php
class PressureAnalyzer
{
public function analyze($value)
{
if ($value <= 0) {
return 'none';
}
if ($value < 2) {
return 'low';
}
if ($value < 8) {
return 'normal';
}
return 'high';
}
}
形成:
Pressure Value
↓
Pressure State
例如:
5N
↓
Normal Pressure
7.38 TemperatureAnalyzer
<?php
class TemperatureAnalyzer
{
public function analyze($temperature)
{
if ($temperature < 10) {
return 'cold';
}
if ($temperature <= 40) {
return 'normal';
}
return 'high';
}
}
形成:
Temperature Value
↓
Temperature State
7.39 MaterialAnalyzer
<?php
class MaterialAnalyzer
{
public function analyze(array $data)
{
return new MaterialElement(
$data['name'] ?? null,
$data['texture'] ?? null,
$data['hardness'] ?? null,
$data['elasticity'] ?? null,
$data['surface'] ?? null
);
}
}
因此:
Material Input
↓
MaterialElement
7.40 TouchRelationBuilder
<?php
class TouchRelationBuilder
{
public function build(
$actor,
$object,
$type,
$state
) {
return new TouchRelation(
$actor,
$object,
$type,
$state
);
}
}
例如:
$relation =
$builder->build(
'robot_hand',
'cup',
'holding',
'stable'
);
得到:
Robot Hand
↓
Holding
↓
Cup
7.41 TouchStateAnalyzer
触觉系统的重要功能是状态变化。
<?php
class TouchStateAnalyzer
{
public function compare(
$previous,
$current
) {
if ($previous === $current) {
return 'stable';
}
return [
'previous' => $previous,
'current' => $current,
'change' => 'changed'
];
}
}
因此:
State(t-1)
+
State(t)
↓
State Transition
7.42 Touch Engine 完整处理流程
最终:
Touch Input
↓
TouchParser
↓
ContactDetector
↓
PressureAnalyzer
↓
TemperatureAnalyzer
↓
MaterialAnalyzer
↓
TouchStateAnalyzer
↓
TouchRelationBuilder
↓
TouchEventBuilder
↓
TouchAnalyzer
↓
TouchElement
这就是:
WSaiOS Touch Engine v1
7.43 触觉数据库设计
第一版不需要把所有触觉属性拆成几十张表。
建议:
touch_inputs
touch_elements
touch_contacts
touch_pressures
touch_temperatures
touch_materials
touch_relations
touch_events
touch_inputs
CREATE TABLE touch_inputs (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
source VARCHAR(100) DEFAULT NULL,
device VARCHAR(100) DEFAULT NULL,
object_name VARCHAR(255) DEFAULT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
INDEX idx_source (source),
INDEX idx_object_name (object_name)
);
7.44 touch_elements
CREATE TABLE touch_elements (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
input_id INT UNSIGNED NOT NULL,
object_name VARCHAR(255) DEFAULT NULL,
contact_state VARCHAR(100) DEFAULT NULL,
state VARCHAR(100) DEFAULT NULL,
x DECIMAL(12,4) DEFAULT 0,
y DECIMAL(12,4) DEFAULT 0,
z DECIMAL(12,4) DEFAULT 0,
confidence DECIMAL(6,4) DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
INDEX idx_input_id (input_id),
INDEX idx_object_name (object_name),
INDEX idx_state (state)
);
7.45 touch_contacts
CREATE TABLE touch_contacts (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
element_id INT UNSIGNED NOT NULL,
source_object VARCHAR(255) DEFAULT NULL,
target_object VARCHAR(255) DEFAULT NULL,
contact_state VARCHAR(100) DEFAULT NULL,
contact_time DATETIME DEFAULT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
INDEX idx_element_id (element_id),
INDEX idx_source_object (source_object),
INDEX idx_target_object (target_object)
);
7.46 touch_pressures
CREATE TABLE touch_pressures (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
element_id INT UNSIGNED NOT NULL,
pressure_value DECIMAL(12,4) DEFAULT 0,
direction VARCHAR(100) DEFAULT NULL,
area DECIMAL(12,4) DEFAULT 0,
change_value DECIMAL(12,4) DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
INDEX idx_element_id (element_id)
);
7.47 touch_temperatures
CREATE TABLE touch_temperatures (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
element_id INT UNSIGNED NOT NULL,
temperature_value DECIMAL(12,4) DEFAULT 0,
temperature_unit VARCHAR(20) DEFAULT 'C',
change_value DECIMAL(12,4) DEFAULT 0,
state VARCHAR(100) DEFAULT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
INDEX idx_element_id (element_id)
);
7.48 touch_materials
CREATE TABLE touch_materials (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
element_id INT UNSIGNED NOT NULL,
material_name VARCHAR(100) DEFAULT NULL,
texture VARCHAR(100) DEFAULT NULL,
hardness VARCHAR(100) DEFAULT NULL,
elasticity VARCHAR(100) DEFAULT NULL,
surface VARCHAR(100) DEFAULT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
INDEX idx_element_id (element_id),
INDEX idx_material_name (material_name)
);
7.49 touch_relations
CREATE TABLE touch_relations (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
element_id INT UNSIGNED NOT NULL,
actor_object VARCHAR(255) NOT NULL,
target_object VARCHAR(255) NOT NULL,
relation_type VARCHAR(100) NOT NULL,
relation_state VARCHAR(100) DEFAULT NULL,
confidence DECIMAL(6,4) DEFAULT 1,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
INDEX idx_element_id (element_id),
INDEX idx_actor_object (actor_object),
INDEX idx_target_object (target_object),
INDEX idx_relation_type (relation_type)
);
7.50 touch_events
CREATE TABLE touch_events (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
element_id INT UNSIGNED NOT NULL,
object_name VARCHAR(255) DEFAULT NULL,
event_type VARCHAR(100) NOT NULL,
change_data TEXT,
event_time DATETIME DEFAULT NULL,
meaning VARCHAR(255) DEFAULT NULL,
confidence DECIMAL(6,4) DEFAULT 1,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
INDEX idx_element_id (element_id),
INDEX idx_event_type (event_type),
INDEX idx_event_time (event_time)
);
7.51 数据库与 OOP 对象映射
形成:
MySQL
touch_inputs
↓
TouchInput
touch_elements
↓
TouchElement
touch_contacts
↓
ContactElement
touch_pressures
↓
PressureElement
touch_temperatures
↓
TemperatureElement
touch_materials
↓
MaterialElement
touch_relations
↓
TouchRelation
touch_events
↓
TouchEvent
因此:
数据库记录 → PHP OOP 对象 → WSaiOS 触觉感知元素。
7.52 TouchRepository
数据库访问通过 Repository 完成。
<?php
class TouchElementRepository
{
protected $db;
public function __construct(PDO $db)
{
$this->db = $db;
}
public function save(TouchElement $element)
{
$sql = "
INSERT INTO touch_elements
(
object_name,
contact_state,
state
)
VALUES
(
:object_name,
:contact_state,
:state
)
";
$stmt = $this->db->prepare($sql);
$stmt->execute([
':object_name' =>
$element->getObject(),
':contact_state' =>
$element->getContact(),
':state' =>
$element->getState()
]);
return $this->db->lastInsertId();
}
public function find($id)
{
$stmt = $this->db->prepare(
"SELECT *
FROM touch_elements
WHERE id = :id"
);
$stmt->execute([
':id' => $id
]);
return $stmt->fetch(PDO::FETCH_ASSOC);
}
}
7.53 为什么 Repository 必须独立
不能这样:
class TouchElement
{
public function save()
{
mysql_query(...);
}
}
因为这会导致:
Domain Object
+
Database
高度耦合。
正确方式:
TouchElement
↓
TouchElementRepository
↓
PDO
↓
MySQL
这样以后可以更换:
MySQL
SQLite
其他数据库
文件存储
Memory Store
而不需要改变 TouchElement。
7.54 TouchService
Service 负责协调触觉业务。
<?php
class TouchService
{
protected $repository;
protected $analyzer;
public function __construct(
TouchElementRepository $repository,
TouchAnalyzer $analyzer
) {
$this->repository = $repository;
$this->analyzer = $analyzer;
}
public function create(array $data)
{
$element =
new TouchElement($data);
return $this->repository
->save($element);
}
public function analyze($element)
{
return $this->analyzer
->analyze($element);
}
}
形成:
Controller
↓
TouchService
↓
TouchAnalyzer
↓
TouchElement
↓
Repository
↓
Database
7.55 MVC 中的 TouchController
Controller 不负责触觉算法。
只负责:
接收请求
↓
调用 Service
↓
准备数据
↓
Smarty 输出
例如:
<?php
class TouchController
{
protected $service;
protected $smarty;
public function __construct(
TouchService $service,
Smarty $smarty
) {
$this->service = $service;
$this->smarty = $smarty;
}
public function detail($id)
{
$element =
$this->service->get($id);
$this->smarty->assign(
'element',
$element
);
$this->smarty->display(
'touch/detail.tpl'
);
}
}
7.56 Smarty 的位置
Smarty 只负责:
View
它不负责:
触觉识别
压力分析
温度分析
状态判断
数据库操作
只负责:
TouchElement
↓
Smarty
↓
HTML
7.57 Smarty 触觉模板
例如:
<h1>触觉感知元素</h1>
<div class="touch-element">
<div>
Object:
{$element->getObject()}
</div>
<div>
Contact:
{$element->getContact()}
</div>
<div>
State:
{$element->getState()}
</div>
<div>
Pressure:
{$element->getPressure()}
</div>
<div>
Temperature:
{$element->getTemperature()}
</div>
</div>
因此:
PHP Object
↓
Smarty
↓
HTML
7.58 MVC 完整请求链路
用户访问:
/touch/element/100
系统:
Router
↓
TouchController
↓
TouchService
↓
TouchAnalyzer
↓
TouchElement
↓
Repository
↓
MySQL
返回:
MySQL
↓
Repository
↓
TouchElement
↓
TouchService
↓
TouchController
↓
Smarty
↓
HTML
完整结构:
WSaiOS Touch System
│
┌──────────┴──────────┐
↓ ↓
Touch Engine Touch Domain
│ │
↓ ↓
TouchAnalyzer TouchElement
│ │
└──────────┬──────────┘
↓
Repository
↓
MySQL
↓
Controller
↓
Smarty
↓
View
7.59 触觉与 Visual Engine 的连接
上一章已经建立:
Visual Engine
包括:
ImageElement
VisualPosition
VisualRelation
VisualScene
现在加入:
Touch Engine
形成:
Visual Engine
│
│
↓
VisualElement
│
│
↓
Touch Engine
│
↓
TouchElement
例如视觉首先发现:
Cup
然后触觉确认:
Cup
+
Stable Grip
形成:
Cup Handling
7.60 视觉与触觉对象统一
两个系统虽然感知方式不同,但最终都应该进入统一的元素体系。
视觉:
ImageElement
音频:
AudioElement
触觉:
TouchElement
统一抽象:
PerceptionElement
因此:
PerceptionElement
│
├── ImageElement
│
├── AudioElement
│
└── TouchElement
这是下一章“多感知元素融合”的基础。
7.61 TouchElement → CognitiveElement
触觉系统最终不能停留在:
Pressure = 5N
Temperature = 25°C
Contact = Stable
这些只是感知数据。
需要形成:
CognitiveElement
例如:
TouchElement
Object = Cup
Contact = Stable
Pressure = Normal
State = Holding
经过:
Touch Semantic Mapping
形成:
CognitiveElement
type = ObjectHandling
subject = RobotHand
object = Cup
state = StableHolding
因此:
Touch Engine
↓
Semantic Mapping
↓
Cognitive Engine
正式连接。
7.62 TouchSemanticMapper
可以建立:
<?php
class TouchSemanticMapper
{
public function map(
TouchElement $element
) {
return [
'type' => 'TouchInteraction',
'object' =>
$element->getObject(),
'contact' =>
$element->getContact(),
'state' =>
$element->getState()
];
}
}
这不是最终的认知系统,而是:
触觉元素向认知元素转换的接口层。
7.63 触觉 → 行为决策
触觉最大的特点是:
它与执行系统关系非常密切。
例如机器人:
视觉发现杯子
↓
Robot Hand 接触杯子
↓
Pressure Increase
↓
Stable Contact
↓
Successful Grasp
↓
继续执行
如果:
Pressure
↓
Too High
则:
Risk
↓
Reduce Grip
因此:
Touch Element
↓
State Analysis
↓
Cognitive Element
↓
Decision
↓
Action
形成:
Perception → Cognition → Action
7.64 多感知融合入口
触觉系统完成后,WSaiOS 已经形成三个主要感知方向:
Visual
Audio
Touch
分别对应:
ImageElement
AudioElement
TouchElement
下一步不能让三个系统各自独立。
应该进入:
Multi-Perception Engine
统一处理:
VisualElement
+
AudioElement
+
TouchElement
↓
MultiPerceptionElement
↓
CognitiveElement
这就是第八章的核心。
7.65 WSaiOS Touch Engine 第一版完整架构
最终形成:
Touch Input
│
↓
TouchParser
│
↓
ContactDetector
│
┌───────────┼───────────┐
↓ ↓ ↓
Pressure Temperature Material
Analyzer Analyzer Analyzer
│ │ │
└───────────┼───────────┘
↓
TouchStateAnalyzer
│
↓
TouchRelationBuilder
│
↓
TouchEventBuilder
│
↓
TouchElement
│
↓
TouchAnalyzer
│
↓
CognitiveMapper
│
↓
CognitiveElement
7.66 第一版工程目录
综合本章:
wsaios/
│
├── app/
│ │
│ ├── Controllers/
│ │ └── Touch/
│ │ └── TouchController.php
│ │
│ ├── Models/
│ │ └── Touch/
│ │ ├── TouchElement.php
│ │ ├── ContactElement.php
│ │ ├── PressureElement.php
│ │ ├── TemperatureElement.php
│ │ ├── MaterialElement.php
│ │ ├── TouchPosition.php
│ │ ├── TouchState.php
│ │ ├── TouchRelation.php
│ │ └── TouchEvent.php
│ │
│ ├── Services/
│ │ └── Touch/
│ │ ├── TouchService.php
│ │ ├── PressureService.php
│ │ ├── TemperatureService.php
│ │ ├── TouchEventBuilder.php
│ │ └── TouchSemanticMapper.php
│ │
│ ├── Repositories/
│ │ └── Touch/
│ │ └── TouchElementRepository.php
│ │
│ └── Views/
│ └── touch/
│ ├── detail.tpl
│ └── event.tpl
│
├── engine/
│ └── Touch/
│ ├── TouchParser.php
│ ├── ContactDetector.php
│ ├── PressureAnalyzer.php
│ ├── TemperatureAnalyzer.php
│ ├── MaterialAnalyzer.php
│ ├── TouchStateAnalyzer.php
│ ├── TouchRelationBuilder.php
│ ├── TouchEventBuilder.php
│ └── TouchAnalyzer.php
│
├── config/
│ └── database.php
│
└── public/
└── index.php
7.67 本章形成的 OOP 对象体系
最终:
PerceptionElement
│
└── TouchElement
│
├── ContactElement
│
├── PressureElement
│
├── TemperatureElement
│
├── MaterialElement
│
├── TouchPosition
│
├── TouchState
│
├── TouchRelation
│
└── TouchEvent
处理体系:
TouchParser
↓
ContactDetector
↓
PressureAnalyzer
↓
TemperatureAnalyzer
↓
MaterialAnalyzer
↓
TouchStateAnalyzer
↓
TouchRelationBuilder
↓
TouchEventBuilder
↓
TouchAnalyzer
应用体系:
Controller
↓
Service
↓
Touch Engine
↓
Repository
↓
Database
显示体系:
Controller
↓
Smarty
↓
HTML
认知体系:
TouchElement
↓
TouchSemanticMapper
↓
CognitiveElement
↓
Cognitive Engine
7.68 本章核心工程结论
到这里,第七章已经从:
触觉感知元素结构理论
进入真正的:
WSaiOS Touch OOP Architecture
核心关系可以压缩成:
TOUCH INPUT
│
↓
TouchParser
│
↓
TouchElement
│
┌──────────────┼──────────────┐
↓ ↓ ↓
Contact Pressure Temperature
│ │ │
└──────────────┼──────────────┘
↓
TouchState
│
↓
TouchRelation
│
↓
TouchEvent
│
↓
TouchSemanticMapper
│
↓
CognitiveElement
│
↓
Cognitive Engine
│
↓
Action
PHP MVC 工程结构则是:
WSaiOS
│
┌──────┴──────┐
│ │
Touch Engine Cognitive Engine
│
┌─────┴─────┐
│ │
Domain Service
Objects │
│ │
└─────┬─────┘
│
Repository
│
MySQL
│
Controller
│
Smarty
│
View
因此,第七章完成了一个重要的工程转换:
Touch → Element → Object → Service → Engine → Repository → Controller → Smarty → Database → CognitiveElement
而第八章就可以在这个基础上继续,重点研究:
第八章 多感知元素融合理论
从:
ImageElement
AudioElement
TouchElement
进一步建立:
PerceptionElement
↓
MultiPerceptionElement
↓
PerceptionFusion
↓
ConflictResolution
↓
SceneUnderstanding
↓
CognitiveElement
并继续保持同一套 PHP OOP + MVC + Smarty + Repository + Engine 工程编号体系。