感知介质(烟雾干扰)
需要:uBotSensor 0.1.x(含依赖 uBotCore)
了解烟雾等感知介质(Perception Medium)怎样影响激光雷达和相机,并在蓝图里把自己的 Actor 做成一个介质。
连线:
- Get Medium Snapshot 的 执行,连到 Return Node 的 执行
- Get Actor Location 的 Return Value,连到 Make UBot Medium Cell 的 World Position Centimeters
- Make UBot Medium Cell 的 UBot Medium Cell,连到 Make Array 的 [0]
- Make Array 的 Array,连到 Make UBot Medium Snapshot 的 Cells
- Make UBot Medium Snapshot 的 UBot Medium Snapshot,连到 Return Node 的 Out Snapshot
- 一个单元是一个球:球心在 Actor 的位置,半径 300 cm,密度 0.8。
Return Value为 true 表示这个介质有快照可以给传感器。
Get Medium Snapshot
这个节点没有登记在 API 数据里(inline 节点),引脚未经校验。
输入
无
输出
- 执行
inline 节点:未在 data/api 中登记
Get Actor Location
Target is Actor · UE 引擎 · 中文界面:获取Actor位置
Returns the location of the RootComponent of this Actor
输入
- Target
Actor对象引用
输出
- Return Value
Vector
查看参考AActor.K2_GetActorLocation
Make UBot Medium Cell
UBotCore
用世界位置、半径、密度和边缘系数构造一个 UBot Medium Cell。
输入
- World Position Centimeters
Vector - Radius Centimeters
Float - Density
Float - Edge Factor
Float
输出
- UBot Medium Cell
UBot Medium Cell结构体
查看参考Make:FUBotMediumCell
Make Array
这个节点没有登记在 API 数据里(inline 节点),引脚未经校验。
输入
- [0]
UBot Medium Cell结构体
输出
- Array
UBot Medium Cell结构体数组
inline 节点:未在 data/api 中登记
Make UBot Medium Snapshot
UBotCore
用介质类型、是否有效、颜色和单元列表构造一个 UBot Medium Snapshot。
输入
- Medium Type
Name - Active
Boolean - Tint
Linear Color结构体 - Cells
UBot Medium Cell结构体数组
输出
- UBot Medium Snapshot
UBot Medium Snapshot结构体
查看参考Make:FUBotMediumSnapshot
Return Node
这个节点没有登记在 API 数据里(inline 节点),引脚未经校验。
输入
- 执行
- Out Snapshot
UBot Medium Snapshot结构体 - Return Value
Boolean
输出
无
inline 节点:未在 data/api 中登记
-
新建 Actor 蓝图
新建一个 Actor 蓝图,例如
BP_SmokeCloud。介质的位置就是这个 Actor 的位置。 -
实现接口
打开「Class Settings」,在「Interfaces」里点「Add」,选
UBot Perception Medium。 -
实现
Get Medium Snapshot在「My Blueprint」面板的「Interfaces」下双击
Get Medium Snapshot,照上图连线。 -
放进关卡
把 Actor 放进关卡即可,不需要注册。传感器每次采样都会重新取一次快照,位置和密度的变化在下一次采样生效。
-
验证
把 Actor 放在
Lidar2D正前方 800 cm 处,再接下面这张图。
连线:
- On 2DLidar Frame Ready (Lidar2D) 的 执行,连到 Print String 的 执行
- On 2DLidar Frame Ready (Lidar2D) 的 Frame,连到 Get Range by Index 的 Target
- Get Range by Index 的 Range Meters,连到 To String (Float) 的 In Double
- To String (Float) 的 Return Value,连到 Print String 的 In String
- 射线在烟雾球的入口处被截断,距离是 8 - 3 = 5 m,而不是后面墙的距离。
On 2DLidar Frame Ready (Lidar2D)
uBot 2D LiDAR Sensor · UBotSensor
每次产生有效帧后触发,Frame 是这一帧。
输出
- 执行
- Frame
UBot 2DLidar Frame对象引用
查看参考UUBot2DLidarSensorComponent.On2DLidarFrameReady
Get Range by Index
Target is UBot 2DLidar Frame · UBotSensor
读取一束射线的距离(单位 m)和是否命中。索引越界时返回 false,距离为 0。
输入
- Target
UBot 2DLidar Frame对象引用 - Index
Integer
输出
- Range Meters
Float - Hit
Boolean - Return Value
Boolean
查看参考UUBot2DLidarFrame.GetRangeByIndex
To String (Float)
UE 引擎 · 中文界面:转换为字符串(浮点)
Converts a double value to a string
输入
- In Double
Float (double)
输出
- Return Value
String
查看参考UKismetStringLibrary.Conv_DoubleToString
Print String
UE 引擎 · 中文界面:打印字符串
Prints a string to the log, and optionally, to the screen If Print To Log is true, it will be visible in the Output Log window. Otherwise it will be logged only as 'Verbose', so it generally won't show up.
输入
- 执行
- In String
String - Print to Screen
Boolean - Print to Log
Boolean - Text Color
Linear Color结构体 - Duration
Float - Key
Name
输出
- 执行
查看参考UKismetSystemLibrary.PrintString
快照 UBot Medium Snapshot 由若干个球形单元 UBot Medium Cell 组成。
| 字段 | 默认值 | 作用 |
|---|---|---|
World Position Centimeters |
(0, 0, 0) | 单元的球心,世界坐标,单位 cm |
Radius Centimeters |
150 | 单元的半径,单位 cm,小于 1 cm 按 1 cm 算 |
Density |
0 | 密度,范围 0 到 1 |
Edge Factor |
1 | 范围 0 到 1,用来把密度向介质边缘衰减。有效密度等于 Density 乘以 Edge Factor |
Medium Type |
Smoke | 介质类型名。传感器不读取它,所有介质的效果相同 |
Active |
true | 为 false 时整个快照被忽略 |
Tint |
灰色 (0.55, 0.55, 0.55) | 介质的颜色,RGB 相机用它给像素着色 |
Cells |
空 | 单元数组。没有单元的快照被忽略 |
传感器上的属性
Section titled “传感器上的属性”2D / 3D 激光雷达、RGB 相机和深度相机都有下面这几个属性,名称和默认值相同。
| 属性 | 默认值 | 作用 |
|---|---|---|
Enable Smoke Interference |
true | 总开关。为 false 时传感器不受任何介质影响 |
Smoke Density Threshold |
0.05 | 有效密度低于它的单元被忽略 |
Smoke Cell Radius Scale |
1 | 所有单元半径的缩放倍数,至少 0.01 |
Smoke Volume Actor Tag |
AgentSensor.SmokeVolume |
旧版标签路径用的 Actor 标签,见下方注意事项 |
RGB 相机另有三个属性,深度相机不使用:
| 属性 | 默认值 | 作用 |
|---|---|---|
Smoke Interference Tint |
(0.48, 0.50, 0.52) | 旧版标签路径的介质颜色 |
Smoke Interference Opacity Scale |
0.75 | 有效密度乘以它得到不透明度 |
Maximum Smoke Interference Opacity |
0.85 | 不透明度的上限 |
介质没有自己的事件,它改变的是各传感器的输出。
| 传感器 | 影响 |
|---|---|
| 2D 激光雷达 | 射线进入有效密度不低于阈值的单元时,在入口处被截断:按命中处理(Hit 为 true),距离是入口距离,强度为 0 |
| 3D 激光雷达 | 同样在入口处截断。入口距离在量程内时,这束射线在入口距离处产生一个点,强度为 0 |
| RGB 相机 | 读回像素时,像素射线(最远 Preview Distance Meters)遇到介质,像素向介质颜色混合,原来的 alpha 保留。不透明度是有效密度乘以 Smoke Interference Opacity Scale,上限为 Maximum Smoke Interference Opacity。不检查射线前面有没有表面挡住,墙后面的介质也会给这个像素染色 |
| 深度相机 | 读回深度时,射线在到达表面之前进入介质,这个像素的深度改为入口距离。入口距离超出 [Minimum Depth Meters, Maximum Depth Meters] 时记为 0 |
RGB 相机的颜色:来自 UBot Perception Medium 接口的快照用它自己的 Tint,其他来源用相机上的 Smoke Interference Tint。
- 传感器从两条路径发现介质,最后都变成快照。推荐的是接口路径:实现
UBot Perception Medium的 Actor。 - 旧版标签路径靠 Actor 标签
AgentSensor.SmokeVolume和名字反射工作,只为旧版 AgentCombatCore 的烟雾 Actor 保留,不要改这个标签。把Smoke Volume Actor Tag设为None只会关掉旧版路径,接口路径不受影响。 - 同时实现了接口的 Actor 不会被收集两次。
Return Value为 false、Active为 false,或者Cells为空时,这个 Actor 在本次采样里被忽略。 - 相机在读回像素时才取介质快照,不是在采集时。Render Target 本身不受影响,所以预览画面里看不到烟雾。
- 单元只能是球。形状复杂的烟雾用多个单元拼出来。
- 每次采样都会遍历世界里的 Actor 来收集介质。场景里没有介质时,可以关掉
Enable Smoke Interference。 - 烟雾、雾等环境效果计划由 uBotEnvironment 提供,它还在规划中,尚未发布。介质接口在 uBotCore 里,不依赖 uBotEnvironment,现在就可以用本页的方法自己做介质。
- UBot Perception Medium:接口和
Get Medium Snapshot。 - UBot Medium Snapshot和 UBot Medium Cell:快照和单元的字段。
- 2D 激光雷达、3D 激光雷达、RGB 相机和深度相机:各传感器的输出。
- 插件之间怎么对接:uBot 的四个接口。