在PyFMI中将cartpole问题模拟为FMU时,根据使用“模型交换”或“联合模拟”,我会得到不同的结果,并给出相同的输入。ME结果是正确的,CS结果似乎完全不正确
模型交换结果
model = load_fmu(fmu='CartPole.fmu',
kind='ME')
model.set('theta_0', 0)
model.set('m_cart', 20)
model.set('m_pole', 5)
model.set('length', 2)
model.set('poleCartConnection.density', 0)
model.set('f', 0)
res = model.simulate(start_time=0, final_time=10)
plt.plot(res['f'])
plt.plot(res['x'])
plt.plot(res['x_dot'])
plt.plot(res['theta'])
plt.plot(res['theta_dot'])
plt.legend(['f', 'x', 'x_dot', 'theta', 'theta_dot'])
plt.show()
与相比(即完全相同,但使用CS而不是我)
model = load_fmu(fmu='CartPole.fmu',
kind='CS')
model.set('theta_0', 0)
model.set('m_cart', 20)
model.set('m_pole', 5)
model.set('length', 2)
model.set('poleCartConnection.density', 0)
model.set('f', 0)
res = model.simulate(start_time=0, final_time=10)
plt.plot(res['f'])
plt.plot(res['x'])
plt.plot(res['x_dot'])
plt.plot(res['theta'])
plt.plot(res['theta_dot'])
plt.legend(['f', 'x', 'x_dot', 'theta', 'theta_dot'])
plt.show()
具有默认ncp的联合仿真结果
我怀疑这是由于解算器设置,但在CS情况下无法设置这些设置?当我将“ncp”设置为一个非常高的数字时,错误会减少。 非常感谢您的回复
具有高ncp的联合仿真结果
干杯
在OpenModelica中,在导出联合仿真FMU的as stated here时,Euler是当前唯一受支持的解算器。OpenModelica的1.16版应该可以解决这个问题
相关问题 更多 >
编程相关推荐