1

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 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 (i.e. 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

co-simulation results with default 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

co-simulation with high ncp

Cheers

Glenn C.
  • 119
  • 7
  • 1
    What ist the generating tool? Which solver is included in the CS FMU? Can you share the original model and the FMU? – Christian Bertsch Jan 11 '20 at 16:59
  • I've been able to reproduce the error in OpenModelica as well and it is indeed due to the solver settings and chosen integration method - checking them now. – Glenn C. Jan 12 '20 at 11:34
  • 2
    As [stated here](https://trac.openmodelica.org/OpenModelica/ticket/4273) Euler is currently the only solver supported when exporting FMU's in OpenModelica (haven't tested the nightly 1.16 build) which is probably just to simple of a method (i.e. first-order). When using dassl in OpenModelica, the results are fine. – Glenn C. Jan 12 '20 at 12:15

1 Answers1

3

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.

Glenn C.
  • 119
  • 7