UE/ROS 约定库
需要:uBotCore 0.1.x
用 UBot Conventions Library 在蓝图里转换 UE 和 ROS 之间的位置、旋转、角速度、时间,并净化(Sanitize)ROS 名称。
UE 的单位是厘米,ROS 的单位是米,两边的 Y 轴方向也相反(REP-103),所以数据在两边传递时都要换算。
下面把 Actor 的 UE 位置(厘米)换算成 ROS 位置(米),并打印到屏幕:
连线:
- Event Tick 的 执行,连到 Print String 的 执行
- Get Actor Location 的 Return Value,连到 UE To ROS Position 的 UECentimeters
- UE To ROS Position 的 Return Value,连到 To String (Vector) 的 In Vec
- To String (Vector) 的 Return Value,连到 Print String 的 In String
- 反方向用
ROS To UE Position。
Event Tick
UE 引擎 · 中文界面:事件Tick
Event called every frame, if ticking is enabled
输出
- 执行
- Delta Seconds
Float
查看参考AActor.ReceiveTick
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
UE To ROS Position
UBot Conventions Library · UBotCore
位置,UE 的厘米转 ROS 的米:(x, -y, z) / 100。
输入
- UECentimeters
Vector
输出
- Return Value
Vector
查看参考UUBotConventionsLibrary.PositionUEToROS
To String (Vector)
UE 引擎 · 中文界面:到字符串(向量)
Converts a vector value to a string, in the form 'X= Y= Z='
输入
- In Vec
Vector
输出
- Return Value
String
查看参考UKismetStringLibrary.Conv_VectorToString
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
-
找到数据对应的节点
在节点菜单里搜索
UE To ROS或ROS To UE,按数据的种类选节点,对应关系见“关键属性”。 -
选对方向
把 UE 里的数据交给 ROS 一侧用
UE To ROS …,从 ROS 一侧收到的数据用ROS To UE …。 -
检查输入的单位
位置和变换会换算单位。线性量、角速度和航向角不换算,输入必须已经是 m/s、rad/s 或弧度。
ROS 的时间戳(builtin_interfaces/Time)由整数秒 Sec 和纳秒 Nanosec 两部分组成。Seconds To ROS Time 把秒拆成这两个字段,ROS Time To Seconds 再合回去。
连线:
- Event Tick 的 执行,连到 Print String 的 执行
- UBot Clock Subsystem 的 Return Value,连到 Get Sim Time Seconds 的 Target
- Get Sim Time Seconds 的 Return Value,连到 Seconds To ROS Time 的 Seconds
- Seconds To ROS Time 的 Sec,连到 To String (Integer) 的 In Int
- To String (Integer) 的 Return Value,连到 Print String 的 In String
- 搜索
Get UBotClockSubsystem取到它,用法见“仿真时钟”页。 Nanosec是秒的小数部分,单位 ns,这里没有接线。
Event Tick
UE 引擎 · 中文界面:事件Tick
Event called every frame, if ticking is enabled
输出
- 执行
- Delta Seconds
Float
查看参考AActor.ReceiveTick
UBot Clock Subsystem
这个节点没有登记在 API 数据里(inline 节点),引脚未经校验。
输入
无
输出
- Return Value
UBot Clock Subsystem对象引用
inline 节点:未在 data/api 中登记
Get Sim Time Seconds
Target is UBot Clock Subsystem · UBotCore
当前 World 的 uBot 仿真时间(秒)。所有 uBot 时间戳都用这个时间。
输入
- Target
UBot Clock Subsystem对象引用
输出
- Return Value
Float (double)
查看参考UUBotClockSubsystem.GetSimTimeSeconds
Seconds To ROS Time
UBot Conventions Library · UBotCore
把秒换成 builtin_interfaces/Time 的 sec 和 nanosec。负数或非有限值得到 (0, 0)。
输入
- Seconds
Float (double)
输出
- Sec
Integer - Nanosec
Integer
查看参考UUBotConventionsLibrary.SecondsToRosTime
To String (Integer)
UE 引擎 · 中文界面:转换为字符串(整型)
Converts an integer value to a string
输入
- In Int
Integer
输出
- Return Value
String
查看参考UKismetStringLibrary.Conv_IntToString
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
例如 12.5 s 拆成 Sec 为 12、Nanosec 为 500000000。
Sanitize ROS Name 把任意文字变成合法的 ROS 名字片段,用来拼话题、命名空间和 frame id:
| 输入 | 输出 |
|---|---|
My Robot 01 |
My_Robot_01 |
4WD Rover #1 |
_4WD_Rover_1 |
| 空字符串 | ubot |
机器人 |
_ |
规则:只保留 A-Z、a-z、0-9 和下划线,其余字符(包括中文)换成下划线;连续的下划线合并为一个;首字符是数字时前面加一个下划线;只有输入为空时才返回 ubot,全是中文这类非 ASCII 字符的输入会变成 _。
这个库没有可设置的属性,下表是节点和转换规则。ROS 转 UE 的公式与 UE 转 ROS 相同,只是位置的单位反过来换算(米到厘米,乘 100)。
| 数据 | 节点 | UE 转 ROS |
|---|---|---|
| 位置(cm 到 m) | UE To ROS Position、ROS To UE Position |
(x, -y, z) / 100 |
| 线性量(线速度、加速度、已是米的点) | UE To ROS Vector、ROS To UE Vector |
(x, -y, z) |
| 角速度、力矩(rad/s) | UE To ROS Angular Velocity、ROS To UE Angular Velocity |
(-x, y, -z) |
| 旋转四元数 | UE To ROS Rotation、ROS To UE Rotation |
(x, y, z, w) 变为归一化的 (-x, y, -z, w) |
| 刚体变换 | UE To ROS Transform、ROS To UE Transform |
旋转同上,平移从 cm 换成 m,缩放丢弃 |
| 航向角、扫描角、偏航角速度(rad、rad/s) | UE To ROS Yaw、ROS To UE Yaw |
ROS = -UE |
| 相机光学系 | Camera Link To Optical Rotation、Get Optical Frame Suffix |
光学系相对 link 系的旋转为 (x=-0.5, y=0.5, z=-0.5, w=0.5),frame id 后缀为 _optical |
| 时间 | Seconds To ROS Time、ROS Time To Seconds |
秒与 (Sec, Nanosec) 互转 |
| 名称 | Sanitize ROS Name |
见上一节 |
所有节点都是纯函数,没有执行引脚,也没有事件。接上输入就能得到输出,位置和变换的输出单位是米(UE 转 ROS)或厘米(ROS 转 UE)。
- 变换的缩放被丢弃,输出的缩放恒为 1。
- 四元数转换后会归一化;退化的输入(零长度)得到单位四元数。
Seconds To ROS Time遇到负数或非有限值,输出(0, 0);秒数超出 int32 范围时,Sec取 2147483647,Nanosec取 999999999。ROS Time To Seconds把负的Nanosec当作 0。Nanosec在蓝图里是 Integer(int32),取值在 0 到 999999999 之间。
- UBot Conventions Library:全部节点和引脚。
- 坐标系与单位:UE 和 ROS 坐标系的区别,以及 uBot 输出用的单位。
- TF 与 /clock:uBotROS 发布 TF 和时间的方式。