csu-hmc / opty

A library for using direct collocation in the optimization of dynamic systems.
http://opty.readthedocs.io
Other
86 stars 20 forks source link

Errort message #127

Closed Peter230655 closed 4 months ago

Peter230655 commented 4 months ago

I am trying to run a simulation with opzy, and I get this error message:

ValueError Traceback (most recent call last) Cell In[9], line 24 22 prob.add_option('max_iter', 3000) # defaul is 3000 23 # Find the optimal solution. ---> 24 solution, info = prob.solve(initial_guess) 25 print('message from optimizer:', info['status_msg']) 26 initial_guess = solution

File c:\Users\Peter\anaconda3\envs\sympy-dev\Lib\site-packages\cyipopt\cython\ipopt_wrapper.pyx:621, in ipopt_wrapper.Problem.solve()

ValueError: Wrong length of x0.

There is no variable x0 im my simulation. What am I doing wrong?

Thanks!!

moorepants commented 4 months ago

I guess your initial guess has the wrong length.

Peter230655 commented 4 months ago

Thanks! I I understood from the inverted pendulum exampe, it should be: len(initial_guess) = len(state_symbols) * num_nodes + len(specified_symbols) * num_nodes. If this is correct, then my initial guess seems to have the correct length. stat_symbols = generalized coordinates + generalized speeds specified_symbols = external forces, external torques. Should attach my program here / send it to you?

tjstienstra commented 4 months ago

Are you sure that you specified all constant symbols? It is one of my frequent errors.

Peter230655 commented 4 months ago

My equation of motion has these free symbols: EOM free symbold: {t, g, l, reibung, m} I specified all, except of course the time t:

state_symbols = tuple((*q_ind, *u_ind))
laenge = len(state_symbols)
print(state_symbols, len(state_symbols))
_constant_symbols = (l, m, g, reibung)_
specified_symbols = (Tx, Ty)

and I gave then values:

par_map = OrderedDict()
par_map[l]       = 2.0
par_map[m]       = 1.0
par_map[g]       = 9.81
par_map[reibung] = 0.

I can send the program. Thanks!

tjstienstra commented 4 months ago

Hmmm, that sounds good.

Peter230655 commented 4 months ago

But does not work! :-(

Peter230655 commented 4 months ago

Maybe I found the problem: My EOMs contain derivatives, which should not be there, maybe my kinematic equations are wrong. Actually, my OEMs also contain accelerations, so something must be dead wrong with my Kane's equations!

Peter230655 commented 4 months ago

I found the problem: I specified the specified_symbols as sm.symbols, and not as me.dynamicsymbols