简体   繁体   中英

PyFMI different results between model exchange and co-simulation?

When simulating the cartpole problem as an FMU in PyFMI I get different results giving the same input depending on if I use "model exchange" or "co-simulation". The ME results are correct, the CS results seem completely off.

Model exchange results

模型交换结果

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() 

compared to (ie exactly the same but using CS instead of ME)

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()

co-simulation results with default ncp

与默认 ncp 的联合仿真结果

I suspect its due to the solver settings, but these cannot be set in the CS case? When I set the 'ncp' to a very high number, the error gets reduced. Many thanks in advance for your replies!

co-simulation results with high ncp

与高 ncp 联合仿真

Cheers

In OpenModelica, Euler is currently the only supported solver when exporting co-simulation FMU's as stated here . Version 1.16 of OpenModelica should solve this issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM