首页 理论 架构 工程 文档 白皮书 著作 研究 案例 下载 博客 关于 开始使用 →

第255章 Device Model|设备模型

第255章 Device Model|设备模型

255.1 提出背景

第254章建立了 Behavior Model|行为模型

行为模型解决的是:

机器在当前目标、场景、状态和方法条件下,应该如何组织行为。

但是,行为模型产生的仍然是机器内部的行为结构。

要让行为真正作用于现实世界,还必须经过一个现实执行层:

Cognitive Model
↓
Method
↓
Behavior Model
↓
Action
↓
Device
↓
Real World

因此,本章建立:

Device Model|设备模型

Device Model解决的问题不是“机器应该做什么”,而是:

机器通过什么设备执行什么动作,以及设备当前具有什么能力、状态、参数和执行条件。

这使ICAI从:

机器认知
↓
机器行为

进一步进入:

机器行为
↓
机器执行
↓
现实世界变化

因此,Device Model是ICAI连接软件认知系统与物理执行世界的重要工程模型。


255.2 Device Model 的定义

Device Model|设备模型,是ICAI用于描述设备身份、设备类型、设备能力、设备状态、设备参数、设备接口以及设备执行动作能力的动态软件模型。

可以定义:

DMt=F(I,C,Cap,Pt,St,Int,Rt)DM_t=F(I,C,Cap,P_t,S_t,Int,R_t)

其中:

  • DMtDM_t:时间 tt 的Device Model;
  • II:Identity,设备身份;
  • CC:Class,设备类别;
  • CapCap:Capability,设备能力;
  • PtP_t:当前设备参数;
  • StS_t:当前设备状态;
  • IntInt:Interface,设备接口;
  • RtR_t:设备运行信息;
  • FF:设备模型构造函数。

因此:

Device Model
├── Identity
├── Device Class
├── Capability
├── Parameters
├── State
├── Interface
├── Constraints
└── Runtime Information

Device Model不是设备本身,而是设备在ICAI认知系统中的软件对象表示


255.3 Device 与 Device Model 的区别

需要明确:

Physical Device
Device Object
Device Model

三个概念并不相同。

Physical Device|物理设备

现实中的实际设备。

例如:

机械臂
电机
夹爪
摄像设备
压力传感器
移动平台

Device Object|设备对象

物理设备在软件系统中的对象实例:

robot_arm_001
gripper_001
motor_001
sensor_001

Device Model|设备模型

设备对象的完整动态结构:

Device Model
├── Identity
├── Type
├── Capability
├── Position
├── Velocity
├── Force
├── Power
├── State
├── Interface
└── Constraints

因此:

PhysicalDevice→DeviceObject→DeviceModelPhysicalDevice \rightarrow DeviceObject \rightarrow DeviceModel

Device Model使软件系统能够对现实设备进行结构化计算。


255.4 Device Model 的基本组成

ICAI中的Device Model可以定义为:

Device Model
│
├── Identity
├── Class
├── Type
├── Capability
├── Attributes
├── State
├── Parameters
├── Position
├── Interface
├── Constraints
├── Status
└── Feedback

其中:

Identity|设备身份

用于唯一识别设备。

Class|设备类

表示设备属于哪一类。

Type|设备类型

表示设备具体类型。

Capability|设备能力

描述设备可以执行什么。

Attributes|设备属性

描述设备自身的参数。

State|设备状态

描述设备当前运行状态。

Parameters|设备参数

描述执行动作时的动态参数。

Position|设备位置

描述设备在空间中的位置。

Interface|设备接口

定义软件系统与设备之间的通信和控制接口。

Constraints|设备约束

描述设备允许的运行范围。

Status|设备运行状态

描述设备当前是否可执行、运行中、暂停或故障。

Feedback|设备反馈

描述设备执行后返回的信息。


255.5 Device Class|设备类

与Object Class类似,Device Model首先需要设备类别。

例如:

Device Class
│
├── Sensor
├── Actuator
├── Motor
├── Robot
├── Gripper
├── Camera
├── Mobile Device
└── Controller

设备类定义一般结构。

例如:

Gripper
├── Open
├── Close
├── Force
├── Pressure
├── Position
└── State

具体设备实例:

gripper_001
gripper_002
gripper_003

都可以属于:

Gripper

因此:

DeviceClass→DeviceInstanceDeviceClass\rightarrow DeviceInstance

再形成:

DeviceInstance→DeviceModelDeviceInstance\rightarrow DeviceModel


255.6 Device Capability|设备能力

设备模型最重要的结构之一是:

Capability|能力

设备不是简单的物理对象。

设备必须能够表达:

我能够做什么。

例如机械臂:

Move
Rotate
Position
Stop

夹爪:

Open
Close
Grip
Release
AdjustForce

摄像设备:

CaptureImage
DetectObject
TrackObject

因此:

Cap(D)={c1,c2,…,cn}Cap(D)=\{c_1,c_2,…,c_n\}

其中:

  • DD:设备;
  • Cap(D)Cap(D):设备能力集合;
  • cic_i:某一项设备能力。

例如:

Gripper
↓
Capability
├── Open
├── Close
├── Grip
├── Release
└── ForceControl

这使Behavior Model可以判断:

当前行为
↓
需要什么能力
↓
当前设备是否具备

255.7 Behavior 与 Device Capability 的匹配

行为模型产生的是行为需求。

设备模型提供的是设备能力。

二者需要进行匹配:

Match(B,D)={1,Capability(D)⊇Requirement(B)0,otherwiseMatch(B,D)= \begin{cases} 1,&Capability(D)\supseteq Requirement(B)\\ 0,&otherwise \end{cases}

其中:

  • BB:行为;
  • DD:设备;
  • Requirement(B)Requirement(B):行为所需要的设备能力;
  • Capability(D)Capability(D):设备拥有的能力;
  • MatchMatch:能力匹配结果。

例如:

Behavior
↓
Grasp
↓
Requirement
├── Close
├── ForceControl
└── PositionControl

系统查询:

Device Model
↓
Capability

如果:

Gripper_001
├── Close
├── ForceControl
└── PositionControl

则:

Requirement
↓
Capability Match
↓
Executable

否则:

Requirement
↓
Capability Match
↓
Unavailable

这使设备成为认知系统中的可计算执行资源


255.8 Device State|设备状态

设备本身也具有动态状态。

例如:

Device State
├── Offline
├── Ready
├── Running
├── Paused
├── Completed
├── Error
└── EmergencyStop

设备状态可以随时间变化:

DSt→DSt+1DS_t\rightarrow DS_{t+1}

例如:

Offline
↓
Ready
↓
Running
↓
Completed

如果发生故障:

Running
↓
Error

因此Device Model必须能够实时维护设备状态。


255.9 Device Parameter|设备动态参数

设备执行动作时,需要大量动态参数。

例如机械设备:

Position
Velocity
Acceleration
Force
Torque
Temperature
Power

可以形成:

Pt=[p1(t),p2(t),…,pn(t)]TP_t= [p_1(t),p_2(t),…,p_n(t)]^T

其中:

  • PtP_t:设备当前参数向量;
  • pi(t)p_i(t):第 ii 个设备参数;
  • TT:向量转置。

例如:

Pt=[Position,Velocity,Force,Torque]TP_t= [ Position, Velocity, Force, Torque ]^T

行为模型提供目标动作:

Move

Device Model负责根据:

Target Position
Current Position
Velocity Limit
Acceleration Limit

形成设备实际执行参数。


255.10 Device Constraint|设备约束

现实设备具有物理限制。

例如:

MaximumVelocity
MaximumAcceleration
MaximumForce
MaximumTorque
OperatingTemperature
WorkingRange

因此:

Pmin≤Pt≤PmaxP_{min}\leq P_t\leq P_{max}

其中:

  • PtP_t:当前设备参数;
  • PminP_{min}:最小允许值;
  • PmaxP_{max}:最大允许值。

例如:

Force
≤
MaximumForce

如果Behavior Model产生:

Force = 100

而Device Model定义:

MaximumForce = 50

则:

Behavior Output
↓
Device Constraint Check
↓
Invalid
↓
Adjust

因此Device Model不仅表示“设备能做什么”,还必须表示:

设备能够做到什么程度。


255.11 Action 与 Device 的关系

第254章已经区分了:

Behavior
↓
Action

本章进一步加入:

Action
↓
Device

例如:

Action:
MoveHand

可能需要:

Device:
RobotArm

而:

Action:
Grip

可能需要:

Device:
Gripper

因此:

Action→DeviceAction\rightarrow Device

但并不是简单的一对一关系。

一个Action可能需要多个设备:

Move
+
Grip

可能需要:

RobotArm
+
Gripper

因此:

Ai→{D1,D2,…,Dn}A_i\rightarrow\{D_1,D_2,…,D_n\}

形成设备协同执行结构。


255.12 Device Action|设备动作

设备模型可以建立设备动作集合:

Device Action
├── Start
├── Stop
├── Move
├── Rotate
├── Open
├── Close
├── Grip
├── Release
├── SetForce
└── SetVelocity

每个动作都需要对应参数。

例如:

Move
{
    position
    velocity
    acceleration
}

或者:

Grip
{
    force
    pressure
    position
}

因此:

Action=F(Command,Parameters)Action=F(Command,Parameters)

其中:

  • CommandCommand:设备命令;
  • ParametersParameters:执行参数;
  • ActionAction:具体设备动作。

255.13 Device Interface|设备接口

Device Model不能直接把整个认知系统与物理设备硬编码在一起。

需要建立:

Device Interface|设备接口

结构:

Behavior Model
↓
Action
↓
Device Interface
↓
Device Model
↓
Physical Device

例如:

Move()
Grip()
Release()
Stop()

这些是软件层动作接口。

真正的设备通信可能是:

USB
Serial
Ethernet
CAN
TCP/IP
PLC
Controller API

但是ICAI认知层不需要直接知道底层通信细节。

因此:

Cognitive System
↓
Action
↓
Device Interface
↓
Driver / Controller
↓
Physical Device

这样能够保持:

认知逻辑与物理设备通信逻辑分离。


255.14 Device Model 与 MVC 工程

在ICAI PHP MVC系统中,可以将Device Model放在设备模型层。

例如:

app/
├── Models/
│   ├── ObjectModel.php
│   ├── SceneModel.php
│   ├── CognitiveModel.php
│   ├── BehaviorModel.php
│   └── DeviceModel.php
│
├── Services/
│   ├── CognitiveService.php
│   ├── BehaviorService.php
│   └── DeviceService.php
│
├── Controllers/
│   └── DeviceController.php
│
└── Interfaces/
    └── DeviceInterface.php

这里:

DeviceModel

描述设备结构。

DeviceService

负责设备运行逻辑。

DeviceController

负责设备相关请求和控制流程。

DeviceInterface

负责设备接口抽象。

这样就不会把设备驱动代码直接写进认知模型。


255.15 Device Model 的 PHP OOP 实现

可以建立基础的DeviceModel:

class DeviceModel
{
    protected $identity;
    protected $className;
    protected $type;

    protected $capabilities = array();
    protected $attributes = array();
    protected $parameters = array();
    protected $state = 'Offline';
    protected $constraints = array();

    public function __construct($identity, $className)
    {
        $this->identity  = $identity;
        $this->className = $className;
    }

    public function addCapability($capability)
    {
        $this->capabilities[] = $capability;
    }

    public function setAttribute($name, $value)
    {
        $this->attributes[$name] = $value;
    }

    public function setParameter($name, $value)
    {
        $this->parameters[$name] = $value;
    }

    public function setState($state)
    {
        $this->state = $state;
    }

    public function addConstraint($name, $value)
    {
        $this->constraints[$name] = $value;
    }

    public function hasCapability($capability)
    {
        return in_array($capability, $this->capabilities);
    }

    public function getState()
    {
        return $this->state;
    }

    public function getParameters()
    {
        return $this->parameters;
    }
}

这个类保持通用性。

例如:

$gripper = new DeviceModel(
    'gripper_001',
    'Gripper'
);

$gripper->addCapability('Grip');
$gripper->addCapability('Release');
$gripper->addCapability('ForceControl');

另一个设备:

$arm = new DeviceModel(
    'robot_arm_001',
    'RobotArm'
);

$arm->addCapability('Move');
$arm->addCapability('Rotate');
$arm->addCapability('PositionControl');

不同设备通过:

Device Identity
+
Device Class
+
Capability
+
Parameter
+
State

形成不同Device Model。


255.16 Behavior → Action → Device

至此,前两章可以形成完整关系:

Cognitive Model
↓
Goal
↓
Method
↓
Behavior Model
↓
Action
↓
Device Model
↓
Device Capability
↓
Device Interface
↓
Physical Device

例如:

Goal
↓
Grasp Egg
↓
Grasp Behavior
↓
Close Gripper
↓
Gripper Device
↓
Set Force
↓
Physical Gripper

这里的关键关系是:

Behavior→Action→DeviceBehavior\rightarrow Action\rightarrow Device

Behavior决定行为过程。

Action决定当前动作。

Device Model决定:

当前有哪些设备能够执行这个动作,以及应该以什么参数执行。


255.17 Device Model 与实时反馈

设备执行之后必须返回反馈。

例如:

Command
↓
Device
↓
Execution
↓
Feedback

反馈可以包括:

Position
Velocity
Force
Torque
Pressure
Temperature
Error
Status

形成:

Ft+1=Feedback(Dt,At)F_{t+1}=Feedback(D_t,A_t)

其中:

  • Ft+1F_{t+1}:下一时刻设备反馈;
  • DtD_t:当前设备状态;
  • AtA_t:当前设备动作。

反馈再进入:

Device Model
↓
Object Model
↓
Scene Model
↓
Cognitive Model
↓
Behavior Model

形成完整闭环。


255.18 Device Feedback 与世界变化

Device Model并不是闭环终点。

真正的过程是:

Device
↓
Physical Action
↓
World Change
↓
Sensor
↓
Real-Time Data
↓
Object Update
↓
Scene Update
↓
Cognition Update

例如:

Gripper
↓
Close
↓
Contact Egg
↓
Pressure Sensor
↓
Pressure Data
↓
Egg State Update
↓
Scene State Update
↓
Cognitive Update

因此:

Device Action→World Change→Feedback→Re−CognitionDevice\ Action \rightarrow World\ Change \rightarrow Feedback \rightarrow Re-Cognition

设备执行最终改变的是现实世界。


255.19 Device Model 与 Object Model

Device Model本身也是一种特殊的对象模型。

因为设备也具有:

Identity
+
Class
+
Attributes
+
Relations
+
State

因此:

DeviceModel⊂ObjectModelDeviceModel\subset ObjectModel

或者更准确地说:

Object Model
│
├── Physical Object Model
│
├── Device Model
│
├── Environment Object Model
│
└── Other Object Models

设备模型在对象模型的基础上增加:

Capability
+
Control Interface
+
Execution Parameters
+
Device Constraints
+
Runtime Status

因此Device Model既属于机器世界对象结构,又承担现实执行能力。


255.20 Device Model 与 Scene Model

设备也存在于场景中。

例如:

Scene Model
│
├── RobotArm_001
├── Gripper_001
├── Egg_001
├── Table_001
└── Camera_001

其中:

RobotArm
Gripper
Camera

都是设备模型。

因此:

DeviceModel⊂SceneModelDeviceModel\subset SceneModel

设备模型可以与普通对象产生关系:

Gripper
↓
Contact
↓
Egg

或者:

RobotArm
↓
Supports
↓
Gripper

这样设备不仅是执行工具,也是当前现实场景的一部分。


255.21 Device Model 与行为能力匹配

完整的设备匹配过程可以表示:

Behavior Requirement
↓
Action Requirement
↓
Capability Requirement
↓
Device Model Search
↓
Capability Matching
↓
Constraint Checking
↓
Device Selection
↓
Action Execution

数学形式:

D∗=arg⁡max⁡D∈DMatch(D,B)D^*= \arg\max_{D\in\mathcal{D}} Match(D,B)

其中:

  • D\mathcal{D}:当前可用设备集合;
  • D∗D^*:匹配结果;
  • BB:当前行为;
  • Match(D,B)Match(D,B):设备与行为需求之间的匹配度。

在最基本的离散系统中,也可以不使用复杂优化,而采用:

Capability Match
+
State Check
+
Constraint Check
+
Availability Check

得到:

Executable
/
Not Executable

这样设备选择也可以成为结构化认知过程。


255.22 Device Availability|设备可用性

拥有能力不代表当前可以执行。

例如:

Gripper
Capability = Grip

但是当前:

State = Error

那么:

Capability = Available
Device = Not Available

因此设备可执行性至少包括:

Executable=Capability∧Available∧StateValid∧ConstraintValidExecutable= Capability \land Available \land StateValid \land ConstraintValid

其中:

  • Capability:设备具备所需能力;
  • Available:设备当前可用;
  • StateValid:设备状态允许执行;
  • ConstraintValid:执行参数满足设备约束。

这使ICAI的设备控制从简单命令调用进入结构化判断。


255.23 Device Model 的动态运行

设备模型随时间变化:

DMt→DMt+1DM_t\rightarrow DM_{t+1}

例如:

t0
Device = Ready

执行:

Move

之后:

t1
Device = Running
Position = P1
Velocity = V1

完成后:

t2
Device = Completed
Position = P2
Velocity = 0

如果发生故障:

t2
Device = Error

因此Device Model同样属于ICAI的动态模型体系。


255.24 Device Model 的完整执行链

现在可以把第251章到第255章连接起来:

Real World
↓
Real-Time Data
↓
Element
↓
Object Instance
↓
Object Model
↓
Relation
↓
State
↓
Scene Model
↓
Cognitive Model
↓
Goal
↓
Method
↓
Behavior Model
↓
Action
↓
Device Model
↓
Device Capability
↓
Device Interface
↓
Physical Device
↓
World Change
↓
Feedback
↓
Object Model Update
↓
Scene Model Update
↓
Cognitive Model Update
↓
Behavior Update

这已经形成了一个完整的:

机器认知—行为—设备执行闭环。


255.25 Device Model 的核心工程原则

第一,设备对象化

设备必须进入软件对象体系:

Physical Device
↓
Device Instance
↓
Device Model

第二,能力显式化

设备能力不能隐藏在底层代码中:

Device
↓
Capability

必须可以被认知系统查询。

第三,状态动态化

设备状态必须实时更新:

Ready
→
Running
→
Completed

或者:

Running
→
Error

第四,参数化执行

设备动作必须支持动态参数:

Action
+
Parameters
↓
Device Execution

第五,约束化执行

所有设备动作必须受到设备能力和物理限制约束:

Action
↓
Constraint Check
↓
Execution

第六,接口解耦

认知逻辑不直接绑定具体硬件:

Behavior
↓
Action
↓
Device Interface
↓
Device

第七,反馈闭环

设备执行之后必须产生反馈:

Device
↓
Feedback
↓
Re-Cognition

255.26 本章总结

Device Model|设备模型 是ICAI机器认知工程从软件行为进入现实执行世界的关键模型。

它的核心结构为:

DMt=F(I,C,Cap,Pt,St,Int,Rt)DM_t=F(I,C,Cap,P_t,S_t,Int,R_t)

即:

Device Model
=
Identity
+
Class
+
Capability
+
Parameters
+
State
+
Interface
+
Constraints
+
Runtime Information

Device Model解决的核心问题是:

机器已经决定要执行某种行为之后,现实世界中哪个设备能够执行、设备当前是否可执行、需要什么参数、受到什么约束,以及执行后产生什么反馈。

因此形成:

Behavior Model
↓
Action
↓
Device Model
↓
Capability Matching
↓
Constraint Checking
↓
Device Interface
↓
Physical Device
↓
World Change
↓
Feedback

进一步与前面的模型连接:

ObjectModel→SceneModel→CognitiveModel→BehaviorModel→DeviceModelObjectModel \rightarrow SceneModel \rightarrow CognitiveModel \rightarrow BehaviorModel \rightarrow DeviceModel

再通过反馈形成:

DeviceModel→World→Feedback→ObjectModelDeviceModel \rightarrow World \rightarrow Feedback \rightarrow ObjectModel

最终形成完整闭环:

世界
→
对象
→
对象模型
→
场景模型
→
认知模型
→
方法
→
行为模型
→
动作
→
设备模型
→
设备
→
世界变化
→
反馈
→
对象更新
→
场景更新
→
再认知
→
行为调整
→
设备再次执行

因此,第255章完成了一个重要的工程转换:

Behavior Model描述“机器如何行动”,Device Model描述“机器通过什么现实执行能力把行动变成现实世界中的物理变化”。

至此,ICAI已经从:

对象建模
↓
场景建模
↓
认知建模
↓
行为建模

进一步进入:

设备建模
↓
设备执行
↓
现实世界反馈

这使“认知 → 行为 → 执行 → 反馈”真正成为一个可以继续向工程运行时扩展的完整结构。

Leave a Reply

Your email address will not be published. Required fields are marked *