fly_ruler_std.runtime.trim
本页由
fr-docs-dev gen-api从源码 docstring 生成,请勿手工编辑;重新生成执行just api。
配平模块。
定点配平工具:
- TrimSpec: 配平目标配置
- TrimSolver: 配平求解器
- TrimResult: 配平结果
公开成员
| 名称 | 类型 | 定义位置 |
|---|---|---|
BoundValue | 类型别名 | 本页 |
ConstraintValue | 类型别名 | 本页 |
OptionalConstraintValue | 类型别名 | 本页 |
TrimSpec | 类 | 本页 |
TrimSolver | 类 | 本页 |
TrimResult | 类 | 本页 |
定义
BoundValue
python
type BoundValue = float | np.ndarray | None实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/spec.py:13
ConstraintValue
python
type ConstraintValue = float | np.ndarray实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/spec.py:11
OptionalConstraintValue
python
type OptionalConstraintValue = ConstraintValue | None实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/spec.py:12
TrimSpec
python
class TrimSpec(BaseModel)配平目标规格,类似 Simulink 的 trim tool。
通过 RuntimeInstance 的 x.keys / u.keys / y.keys 完整路径精确引用任意 block 的任意端口,不接受短名称。
python
spec = TrimSpec(
state_derivative={"Root.rigid_body::vel_body": [0, 0, 0]},
input_bounds={"Root::command": (-20, 20)},
state_value={"Root.rigid_body::pos_ned": [0, 0, -1000]},
)model_config
python
model_config = ConfigDict(arbitrary_types_allowed=True)pydantic 模型配置,允许约束值使用任意数组类型。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/spec.py:33
state_value
python
state_value: Mapping[str, OptionalConstraintValue] = {}状态固定值约束 {完整状态路径: 值};值为 None 表示该状态完全自由。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/spec.py:36
input_value
python
input_value: Mapping[str, OptionalConstraintValue] = {}输入固定值约束 {完整输入路径: 值};值为 None 表示该输入完全自由。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/spec.py:43
output_value
python
output_value: Mapping[str, OptionalConstraintValue] = {}输出固定值约束 {完整输出路径: 值};值为 None 表示该输出完全自由。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/spec.py:49
param_value
python
param_value: Mapping[str, ConstraintValue] = {}固定参数值 {完整参数路径: 值};未指定的参数使用编译时的默认值。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/spec.py:55
state_derivative
python
state_derivative: Mapping[str, ConstraintValue] = {}状态导数目标 {完整状态路径: 目标值},只有出现的路径才会被约束。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/spec.py:62
state_bounds
python
state_bounds: Mapping[str, tuple[BoundValue, BoundValue]] = {}状态范围约束 {完整状态路径: (下界, 上界)},None 表示该侧无界。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/spec.py:72
input_bounds
python
input_bounds: Mapping[str, tuple[BoundValue, BoundValue]] = {}输入范围约束 {完整输入路径: (下界, 上界)},None 表示该侧无界。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/spec.py:78
output_bounds
python
output_bounds: Mapping[str, tuple[BoundValue, BoundValue]] = {}输出范围约束 {完整输出路径: (下界, 上界)},None 表示该侧无界。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/spec.py:84
initial_guess
python
initial_guess: Mapping[str, ConstraintValue | list[float]] = {}初始猜测 {完整路径: 值},格式同 state_value;未指定的 Euclidean 维度零初始化,SO3 状态使用 identity。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/spec.py:91
objective_weights
python
objective_weights: Mapping[Literal['u', 'x_dot'], float] = {'u': 0.01, 'x_dot': 0.01}目标函数权重,键 u 对应输入项、x_dot 对应未约束导数项。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/spec.py:103
solver_name
python
solver_name: str = 'ipopt'CasADi NLP 求解器名称,例如 ipopt、sqpmethod。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/spec.py:110
solver_opts
python
solver_opts: Mapping[str, object] = {}求解器选项,与默认选项合并后传给 CasADi。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/spec.py:115
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/spec.py:16
TrimSolver
python
class TrimSolver(model: CasadiModel, spec: TrimSpec)基于 CasADi 与 IPOPT 的配平求解器。
为 SO3 状态自动添加与表示方式对应的流形约束,未显式给出的四元数与旋转矩阵初始猜测使用单位存储。
python
solver = TrimSolver(compiled_model, trim_spec)
result = solver.solve(verbose=True)__init__
python
def __init__(model: CasadiModel, spec: TrimSpec) -> None保存模型与规格并校验后端、键名与变量尺寸。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
model | CasadiModel | — | 以 providers.casadi 后端编译的模型。 |
spec | TrimSpec | — | 配平规格,定义约束、边界、目标权重与求解器选项。 |
异常
| 类型 | 说明 |
|---|---|
TypeError | 模型不是用 CasADi 后端编译的。 |
KeyError | 规格中的键不在模型对应的变量键集合中。 |
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/solver.py:42
model
python
model = model以 CasADi 后端编译的模型。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/solver.py:53
spec
python
spec = spec配平规格。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/solver.py:55
solve
python
def solve(verbose: bool = False) -> TrimResult构建并求解配平 NLP 问题。
约束来自状态、输入与输出的取值和边界、状态导数目标以及 SO3 流形;目标函数最小化输入平方与未约束状态导数的平方和。
参数
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
verbose | bool | False | 是否打印 IPOPT 求解过程与计时信息。 |
返回
| 类型 | 说明 |
|---|---|
TrimResult | 配平结果,含最优状态、输入、数值评估得到的输出与状态导数及求解统计。 |
异常
| 类型 | 说明 |
|---|---|
ValueError | 模型缺少向量布局、SO3 表示不受支持、SO3 初始值非法, 或初始猜测在目标、约束或雅可比上产生非有限值。 |
KeyError | 约束中引用了不在任何变量切片中的键。 |
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/solver.py:124
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/solver.py:29
TrimResult
python
class TrimResult(NamedTuple)配平求解结果,含最优状态、输入、输出与求解统计。
运算符
| 运算符 | 方法 | 说明 |
|---|---|---|
repr() | __repr__ | 显示收敛状态、最优变量维数、代价与求解器状态摘要。 |
success
python
success: bool求解器是否收敛。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/result.py:13
x_opt
python
x_opt: NumpyArray最优连续状态向量,一维扁平数组,顺序与 x_keys 一致。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/result.py:16
u_opt
python
u_opt: NumpyArray最优输入向量,一维扁平数组,顺序与 u_keys 一致。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/result.py:19
y_opt
python
y_opt: NumpyArray最优输出向量,一维扁平数组,顺序与 y_keys 一致。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/result.py:22
x_dot_opt
python
x_dot_opt: NumpyArray最优点的连续状态导数,一维扁平数组。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/result.py:25
stats
python
stats: dict[str, object]求解器返回的原始统计信息。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/result.py:28
x_keys
python
x_keys: list[str]连续状态的完整路径列表。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/result.py:31
u_keys
python
u_keys: list[str]输入的完整路径列表。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/result.py:34
y_keys
python
y_keys: list[str]输出的完整路径列表。
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/result.py:37
实现位置:packages/fly_ruler/python/fly_ruler_std/runtime/trim/result.py:10