Files
hm de3e233a98 refactor(layout): 对齐 T2000 布局 —— plant→model、assemblies→mainModels、工具 id 同步;清 BOM
命名与目录(对齐参考工程 D:\1_Project\t2000_proj 的约定)
- assemblies/ → mainModels/(壳模型 ap.slx / sil.slx / hil.slx)
- core/plant/ → core/model/;plant_* → model_*(model_aero / model_atmos / model_rotor /
  model_wind / model_ground_* / model_params* / model_quad_x)
- spec_plant→spec_model、build_plant→build_model、update_plant→update_model、
  compare_plant→compare_model、gencode_plant→gencode_model
- 工具 id:model_plant→build_model、model_autopilot→build_autopilot、verify_plant→verify_model
- mainModels / models / controllers/autopilot 加入 MATLAB 搜索路径:模型按**模型名**解析
  (sim('sil') / open_system('ap')),与 T2000"模型平铺在路径上"一致
- 跨仓 ABI 一律未动:pc_plant_params_s / pc_plant_step / pc_plant_busdef* / pc_autopilot_step / pc_hal_*

修复
- 清掉 145 个文件的 UTF-8 BOM(PowerShell Set-Content -Encoding UTF8 带入的):
  BOM 会让 pc_manifest 的 jsondecode 报 "需要值,但找到的是 ''",工具层全线失败

验证
- run_tests 56/56;build_all 5 个模型 + 编译校验;sim('ap'/'sil'/'hil') 4 s 通过
- layout_report 28/28;compare_model 12 路最大相对误差 8.6e-16;pc('plan') 1/21(仅 sync_downstream)
2026-10-15 20:04:42 +08:00

103 lines
3.9 KiB
Matlab
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
function L = shell_run(id, sc, N)
%SHELL_RUN 壳的统一运行入口:跑 N 拍,返回日志 —— 三壳**同一个内核、不同的对外接口**。
%
% 用途:
% ① 契约验证(test/t_shell_contract.m):三壳跑同一场景,断言"接口不同、内核相同";
% ② 桌面试验台(sim/sim_shells.m):不烧板子、不开 Simulink 也能跑通三壳闭环;
% ③ 交付前的快速对照:与 C 侧 SIL_PC.exe / HIL_PC.exe 用同一份内核、同一套边界换算
% (µs↔归一化常量取自 pc_iface.xlsx,见 shells/shell_sense.m)。
%
% 输入:
% id 壳 ID('ap' | 'hil' | 'sil')
% sc 场景(缺省 shell_scenario(id))
% N 拍数(缺省 400 = 2 s)
% 输出 L(日志结构体):
% L.id / L.N / L.dt / L.iface(= spec_shell,对外接口契约)
% L.t (N×1)、L.pwm (N×8) 内核输出(归一化电机指令)
% L.act_us (N×8 | []) AP/HIL:对外执行机构 µs;SIL:[]
% L.x (N×17 | []) 壳内对象状态(AP 壳为 []:没有飞行动力学模型)
% L.sns (N×16) 本拍"对外帧"(惯导估计 16 路)
% L.armed / L.fs / L.health (N×1)
% L.tx (N×4) 本拍出报意图 [int n0 n1 n2](字节级编码在 C 边界)
% L.wind (N×3) 本拍喂给对象的风(SIL = 环境模型;HIL = 场景常值风)
% L.pos (N×3) / L.vel (N×3) 位置/速度:有对象时是对象真值,AP 壳是外部惯导给的经纬高
% L.alt_rel (N×1) 相对高度(-pd)
%
% ★ 内核 pc_autopilot_step 用 persistent 保存内部状态,故本入口先 clear 它 ——
% "同场景 + 同拍数 ⇒ 同结果",也保证三壳对照时互不串状态。
%
% 用法:
% L = shell_run('sil', shell_scenario('sil'), 400);
% plot(L.t, -L.x(:,13)); % 相对高度(pd 向下为正)
r = shell_registry(id);
if nargin < 2 || isempty(sc)
sc = shell_scenario(id);
end
if nargin < 3 || isempty(N)
N = 400;
end
clear pc_autopilot_step % 内核 persistent 状态复位(见头注)
% 场景便捷项:arm = true 时第 1 拍注入 ARM 指令(解锁)
if isfield(sc, 'arm') && sc.arm
A = ap_types();
if isempty(sc.cmds), sc.cmds = zeros(N, 1); end
sc.cmds(1) = A.cmd.ARM;
end
s = struct();
s.k = 0; s.t = 0;
s.x = zeros(17, 1); s.x(4) = 1; % 对象状态(单位四元数)
s.b = struct('link_i', 0);
s.u = shell_u_init(id, sc);
s.pb = aircraft_params(sc.aircraft); % 对象参数总线(换飞机只改这里)
if r.has_env
s.windst = model_wind_init(sc.seed);
else
s.windst = [];
end
L = struct();
L.id = r.id;
L.N = N;
L.dt = s.u.dt;
L.ts = s.u.dt;
L.iface = spec_shell(id);
L.t = zeros(N, 1);
L.pwm = zeros(N, 8);
L.sns = zeros(N, 16);
L.armed = zeros(N, 1);
L.fs = zeros(N, 1);
L.health= zeros(N, 1);
if r.has_plant, L.x = zeros(N, 17); else, L.x = []; end
if strcmp(r.act_out, 'us'), L.act_us = zeros(N, 8); else, L.act_us = []; end
L.tx = zeros(N, 4);
L.wind = zeros(N, 3);
for k = 1:N
[s, rec] = shell_step(id, s, sc);
L.t(k) = s.t;
L.pwm(k, :) = rec.pwm;
L.sns(k, :) = rec.sns(:)';
L.armed(k) = rec.armed;
L.fs(k) = rec.fs;
L.health(k) = rec.health;
L.tx(k, :) = [rec.tx_int, rec.tx_n];
L.wind(k, :) = rec.wind(:)';
if r.has_plant, L.x(k, :) = rec.x(:)'; end
if ~isempty(L.act_us), L.act_us(k, :) = rec.act_us; end
end
% ---- 派生遥测(便于断言/画图)----
if r.has_plant
L.pos = L.x(:, 11:13); % 对象真值 NED 位置
L.vel = L.x(:, 8:10);
else
L.pos = [L.sns(:,13), L.sns(:,14), L.sns(:,15)]; % AP 壳:只有惯导给的经纬高
L.vel = L.sns(:, 8:10);
end
L.alt_rel = -L.pos(:, 3); % 相对高度(pd 向下为正)
end