fly_ruler_proto_python.client
本页由
fr-docs-dev gen-api从源码 docstring 生成,请勿手工编辑;重新生成执行just api。
基于 Rust PyClient 的面向飞机生命周期的 Python 封装。
公开成员
| 名称 | 类型 | 定义位置 |
|---|---|---|
FlyRulerClient | 类 | 本页 |
create_aircraft_state | 函数 | 本页 |
定义
FlyRulerClient
python
class FlyRulerClient(address: str, aircraft_name: str, initial_state: AircraftState | None = None, toml_config: str = '', heartbeat_interval_secs: float = 1.0, telemetry_schemas: Sequence[TelemetryStreamSchema] = (), spawn_timestamp: float | None = None)绑定单个飞机生命周期的客户端。
构造函数内自动连接、握手并生成一架飞机;close() 或上下文退出时自动销毁飞机并关闭网络连接。
属性
| 名称 | 类型 | 说明 |
|---|---|---|
client_uuid | str | 客户端 UUID 字符串。 |
aircraft_uuid | str | 已生成飞机的 UUID 字符串。 |
NOTE
连接、握手与生成飞机都在构造函数内完成,失败时直接抛出异常,不会返回半初始化的实例。
python
with FlyRulerClient("127.0.0.1:18002", "F-16") as aircraft:
state = create_aircraft_state(position=(100.0, 0.0, -1000.0))
aircraft.update_state(state)
aircraft.create_event("missile_launch")运算符
| 运算符 | 方法 | 说明 |
|---|---|---|
with 进入 | __enter__ | 进入上下文并返回自身。 |
with 退出 | __exit__ | 退出上下文并关闭连接。 |
__init__
python
def __init__(address: str, aircraft_name: str, initial_state: AircraftState | None = None, toml_config: str = '', heartbeat_interval_secs: float = 1.0, telemetry_schemas: Sequence[TelemetryStreamSchema] = (), spawn_timestamp: float | None = None) -> None初始化客户端并生成一架飞机。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
address | str | — | 服务端 host:port 地址。 |
aircraft_name | str | — | 飞机型号名称。 |
initial_state | AircraftState | None | None | 初始状态,None 时使用默认状态的副本。 |
toml_config | str | '' | 飞机 TOML 配置文本,默认空串。 |
heartbeat_interval_secs | float | 1.0 | 心跳周期 [s],默认 1.0。 |
telemetry_schemas | Sequence[TelemetryStreamSchema] | () | 遥测流声明序列,默认空。 |
spawn_timestamp | float | None | None | 生成时刻时间戳 [s],None 表示由核心决定。 |
异常
| 类型 | 说明 |
|---|---|
ValueError | 心跳周期不是有限正数,或生成时间戳不是有限值。 |
实现位置:packages/fly_ruler_proto/bindings/python/src/fly_ruler_proto_python/client.py:99
client_uuid
python
client_uuid: str返回客户端 UUID。
返回
| 类型 | 说明 |
|---|---|
str | UUID 字符串。 |
实现位置:packages/fly_ruler_proto/bindings/python/src/fly_ruler_proto_python/client.py:140
aircraft_uuid
python
aircraft_uuid: str返回已生成飞机的 UUID。
返回
| 类型 | 说明 |
|---|---|
str | UUID 字符串。 |
实现位置:packages/fly_ruler_proto/bindings/python/src/fly_ruler_proto_python/client.py:149
update_state
python
def update_state(state: AircraftState, timestamp: float | None = None) -> None上报一次飞机状态。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
state | AircraftState | — | 新的飞机状态快照。 |
timestamp | float | None | None | 时间戳 [s],None 表示由核心决定。 |
异常
| 类型 | 说明 |
|---|---|
ValueError | 时间戳不是有限值。 |
实现位置:packages/fly_ruler_proto/bindings/python/src/fly_ruler_proto_python/client.py:157
create_event
python
def create_event(event_name: str, timestamp: float | None = None) -> None创建一个命名事件。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
event_name | str | — | 事件名称。 |
timestamp | float | None | None | 时间戳 [s],None 表示由核心决定。 |
异常
| 类型 | 说明 |
|---|---|
ValueError | 时间戳不是有限值。 |
实现位置:packages/fly_ruler_proto/bindings/python/src/fly_ruler_proto_python/client.py:174
publish_telemetry
python
def publish_telemetry(stream_id: str, values: Sequence[float | int | bool], timestamp: float | None = None) -> None按流声明的字段顺序发布一帧遥测数据。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
stream_id | str | — | 目标遥测流标识。 |
values | Sequence[float | int | bool] | — | 与流字段顺序一一对应的取值。 |
timestamp | float | None | None | 时间戳 [s],None 表示由核心决定。 |
异常
| 类型 | 说明 |
|---|---|
ValueError | 时间戳不是有限值。 |
实现位置:packages/fly_ruler_proto/bindings/python/src/fly_ruler_proto_python/client.py:191
despawn
python
def despawn(reason: str | None = None, timestamp: float | None = None) -> None销毁当前客户端持有的飞机。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
reason | str | None | None | 销毁原因,None 表示不附带原因。 |
timestamp | float | None | None | 时间戳 [s],None 表示由核心决定。 |
异常
| 类型 | 说明 |
|---|---|
ValueError | 时间戳不是有限值。 |
实现位置:packages/fly_ruler_proto/bindings/python/src/fly_ruler_proto_python/client.py:210
close
python
def close() -> None关闭网络连接,重复调用不会产生额外效果。
实现位置:packages/fly_ruler_proto/bindings/python/src/fly_ruler_proto_python/client.py:225
实现位置:packages/fly_ruler_proto/bindings/python/src/fly_ruler_proto_python/client.py:76
create_aircraft_state
python
def create_aircraft_state(position: tuple[float, float, float] = (0.0, 0.0, 0.0), velocity: tuple[float, float, float] = (0.0, 0.0, 0.0), attitude: Attitude | None = None, angular_velocity: tuple[float, float, float] = (0.0, 0.0, 0.0), derived: DerivedState | None = None, control_surfaces: ControlSurfaceState | None = None, linear_acceleration_body: tuple[float, float, float] | None = None, propulsors: list[PropulsorState] | None = None) -> AircraftState创建带默认值的 AircraftState,便于脚本化构造。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
position | tuple[float, float, float] | (0.0, 0.0, 0.0) | NED 位置 (x, y, z),单位 [m]。 |
velocity | tuple[float, float, float] | (0.0, 0.0, 0.0) | 机体系 BODY-FRD 速度 (vx, vy, vz),单位 [m/s](x 前、y 右、z 下)。 |
attitude | Attitude | None | None | 姿态;None 时使用 Attitude.identity()。 |
angular_velocity | tuple[float, float, float] | (0.0, 0.0, 0.0) | 机体系角速度 (p, q, r),单位 [rad/s]。 |
derived | DerivedState | None | None | 可选的派生状态。 |
control_surfaces | ControlSurfaceState | None | None | 可选的控制面状态。 |
linear_acceleration_body | tuple[float, float, float] | None | None | 可选的机体系线加速度 [m/s^2]。 |
propulsors | list[PropulsorState] | None | None | 可选的推进器状态列表。 |
返回
| 类型 | 说明 |
|---|---|
AircraftState | 构造完成的 AircraftState 实例。 |
实现位置:packages/fly_ruler_proto/bindings/python/src/fly_ruler_proto_python/client.py:35