架构(模型名不带 pc_ 前缀,共 5 个产物)
- autopilot(模块):指令 + 参数 + 导航 + 控制律 + 通讯(NAV/CTL 为其内部子系统),可独立出码
- model(模块):飞行动力学(Aerospace 6DoF + 本工程推进/气动),结构真源 models/model.xml
- ap(壳):HAL + Autopilot(**无对象** —— AP 壳的对象是真实飞机)
- sil / hil(壳):HAL + Autopilot + MODEL
- 新增 assemblies/ap.slx 与 tasks/build/build_ap.m(mbd.assembly 的 'ap' 分支)+ 工具 asm_ap;
shell_registry 的 ap 行现在有装配模型
- HAL 一律用 C Caller(接口真源 data/bus_define/pc_iface.xlsx 的 hal/sim 域 →
controllers/autopilot/pc_hal.{h,c} / pc_sim.c),模型与底层驱动/固件共用同一份代码;
换平台只换该域 SourceC,接口本身不动
- C 侧 ABI 一律未动:pc_autopilot_step(MATLAB 函数名)/ pc_hal_* / pc_plant_params_s /
pc_params_s.inc / pc_sns_s / pc_act_s 等跨仓符号保持原样;pc_ctl / pc_nav 仍带 pc_ 前缀
目录
- lib/ → core/(11 个内核域);lib/shell/ → shells/;utilities/spec_shell.m → shells/
- libraries/mbd-tools 由 git 子模块并入本仓(删 .gitmodules 与 gitlink,文件转为普通文件),
历史另存 work/archive/mbd-tools-history.bundle(已 git bundle verify)
- 精简:删除 heavy 机型实例(12 件)与 pc_plant_prop 演示模型;XML 夹具移至 test/assets/
修复
- close_system('all', 0) 不是合法的“全关”形式(空操作)→ 生成器与建模型改用 bdclose
- SaveModelNameInUse:Model Reference 宿主会把被引用模型立刻重载回来,导致重建对象模型
保存失败 → xml2mdl_v2 生成前先关宿主、mbd.new_model 同处理、build_plant 显式关壳 + 兜底重试
验证
- run_tests 56/56;build_all 重建 5 个模型(含编译校验);sim('ap'/'sil'/'hil') 各 8 s 通过
- layout_report 28/28 系统零重叠;compare_plant 12 路最大相对误差 8.6e-16
- pc('plan') 1/21 待跑(仅 sync_downstream:写 auxpilot/gcs-ng,本次未跑)
48 lines
2.0 KiB
Matlab
48 lines
2.0 KiB
Matlab
function [ac, b] = shell_act(id, b, y, sc) %#ok<INUSD>
|
||
%SHELL_ACT 壳的**执行机构侧边界**:把内核输出折成"对外接口"的量。
|
||
%
|
||
% ap / hil —— 归一化 pwm → 执行机构 **µs**(pc_hal_act_us 语义),对外是硬件/硬件帧;
|
||
% sil —— 归一化 pwm **直接闭环**(无 µs 换算;µs 只出现在 AP/HIL 边界)。
|
||
%
|
||
% 换算常量取自接口真源(pc_iface.xlsx 的 iface_const → pc_iface_gen),与 pc_hal.c 同一批宏。
|
||
%
|
||
% 输入:id 壳 ID;b 边界状态;y 内核输出(pc_autopilot_step 的返回);sc 场景
|
||
% 输出:
|
||
% ac.pwm 归一化电机指令 1×8(**三壳都有**:壳内对象/设备模型用它闭环)
|
||
% ac.act_us 执行机构 µs 1×8(AP/HIL;SIL 为 [])
|
||
% ac.unit 'us'(AP/HIL)| 'norm'(SIL)—— 即 spec_shell 的 act_out
|
||
% ac.tx_int / ac.tx_n0..n2 本拍**出报意图**(ap_comm_types.tx + 3 个数值字段)
|
||
% ※ 字节级编码(JSON 下行帧)由 C 边界 pc_ap_comm_downlink 完成 —— 它是唯一
|
||
% 真源,MATLAB 壳运行器只到"意图"这一层,不复制一份编码(避免两处各写一份)。
|
||
% b 更新后的边界状态(记录上一拍输出,便于观测)
|
||
%
|
||
% 用法:[ac, b] = shell_act('hil', b, y, sc);
|
||
|
||
r = shell_registry(id);
|
||
G = pc_iface_gen();
|
||
amin = str2double(G.const.PC_HAL_ACT_MIN_US.value);
|
||
aspan = str2double(G.const.PC_HAL_ACT_SPAN_US.value);
|
||
|
||
pwm = y.pwm(:)';
|
||
pwm = min(max(pwm, 0), 1);
|
||
|
||
ac = struct();
|
||
ac.pwm = pwm;
|
||
ac.unit = r.act_out;
|
||
ac.tx_int = y.comm_tx_int;
|
||
ac.tx_n0 = y.comm_tx_n0;
|
||
ac.tx_n1 = y.comm_tx_n1;
|
||
ac.tx_n2 = y.comm_tx_n2;
|
||
|
||
if strcmp(r.act_out, 'us')
|
||
ac.act_us = amin + aspan * pwm; % 1000..2000 µs
|
||
else
|
||
ac.act_us = [];
|
||
end
|
||
|
||
% 边界状态只记"上一拍输出"(定长,便于观测/断言);不在这里累积历史 ——
|
||
% 历史由 shell_run 的日志负责(N 拍一次性预分配),否则每拍动态增长会变成 O(N^2)。
|
||
b.last_pwm = pwm;
|
||
b.last_unit = r.act_out;
|
||
end
|