Commit b302d712 authored by Developer's avatar Developer

fix(hil): 修复实物电阻参数不影响仿真的问题

- modelicaExporter: gain 字段从 paramValues 读取实际参数值 (R/C/L/V0),
  而非仅对 switch 类型生效
- useProjectStore: FMU 缓存根据 .mo 代码变化智能失效,
  避免参数修改后仍复用旧 FMU
parent acdc636e
......@@ -31,6 +31,7 @@ function persistProjects(projects) {
if (clean.hilResult) {
clean.hilResult = { ...clean.hilResult };
delete clean.hilResult.csvData;
delete clean.hilResult.moCode;
}
return clean;
});
......@@ -324,8 +325,10 @@ const useProjectStore = create((set, get) => ({
return;
}
// 调用后端启动 HIL(复用已有 FMU 跳过编译)
const cachedFmu = project.hilResult?.fmuPath || '';
// 仅当 .mo 代码未变时复用已有 FMU,否则重新编译
const prevCode = project.hilResult?.moCode || '';
const codeChanged = exported.code !== prevCode;
const cachedFmu = (!codeChanged && project.hilResult?.fmuPath) ? project.hilResult.fmuPath : '';
const resp = await startHilSession({
moCode: exported.code,
modelName,
......@@ -342,6 +345,7 @@ const useProjectStore = create((set, get) => ({
message: resp.message,
sessionId: resp.data?.session_id,
fmuPath: resp.data?.fmu_path,
moCode: exported.code, // 记录当前 .mo 代码,用于下次判断是否需要重新编译
ports: resp.data?.ports,
status: resp.data?.status,
errorDetail: resp.data?.error_detail,
......
......@@ -410,9 +410,22 @@ export function exportToModelicaHIL(data, modelName = 'Circuit') {
fmuVarPrefix: instanceName,
controlVar: mapping?.controlVar ? `${instanceName}.${mapping.controlVar}` : '',
topic: `/${toMoId(modelName)}/${instanceName}`,
gain: simModeMap[type] === 'switch'
? ((() => { const v = node.data?.paramValues?.closed; return v === true || v === 'true' ? 1 : 0; })())
: undefined,
gain: (() => {
if (simModeMap[type] === 'switch') {
const v = node.data?.paramValues?.closed;
return v === true || v === 'true' ? 1 : 0;
}
// 非 switch: 从 paramValues 读取主要参数值 (R/C/L/V0)
const primaryKey = { resistor: 'R', capacitor: 'C', inductor: 'L', voltage_source: 'V0' }[type];
if (primaryKey) {
const raw = node.data?.paramValues?.[primaryKey];
if (raw != null && raw !== '') {
const num = parseEngValue(raw);
return num != null ? num : 1.0;
}
}
return 1.0;
})(),
});
}
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment