machines-in-motion / kino_dynamic_opt

Kino-dynamic optimization algorithm for multiped robots
BSD 3-Clause "New" or "Revised" License
39 stars 9 forks source link

Formulating a problem from the Python API #21

Closed pFernbach closed 4 years ago

pFernbach commented 4 years ago

Hello, is there any examples or tutorial where I can see how to formulate a momentumopt problem from the Python API.

eg. I want to define the contact sequence, initial and final state, time horizon and other such variables from python, call the dynamic solver and retrieve the various trajectories (c, dc, ddc, L, dL) from Python. Without having to write/parse a yaml config file.

Is it currently possible ? The python bindings in https://github.com/machines-in-motion/kino_dynamic_opt/tree/master/momentumopt/srcpy/momentumopt seems to indicate that it is.

EDIT: To elaborate a little more what I am trying to achieve, I want to integrate properly momentumopt in the framework https://github.com/loco-3d/multicontact-locomotion-planning . In a first step, only as a "centroidal dynamic solver".

In order to do this I need to write a generic wrapper that formulate a problem for momentumopt for any given contact sequence and initial and final state, solve it and store the results in our dedicated data structure.

jviereck commented 4 years ago

Hi @pFernbach , thanks for opening this issue.

I am looking into this for a similar problem you describe. The way I imagine it is to load a yaml config file. Then, there should be a new python API to change the start/end/contact/... configuration. Not sure when this will be done though.

Would this be useful for you?

pFernbach commented 4 years ago

Yes it would be ideal, using a yaml with default values for all the settings and being able to define everything specific to my current problem in Python.

But by browsing the python bindings (eg. https://github.com/machines-in-motion/kino_dynamic_opt/blob/master/momentumopt/srcpy/momentumopt/cntopt/PyContacts.cpp and https://github.com/machines-in-motion/kino_dynamic_opt/blob/master/momentumopt/srcpy/momentumopt/dynopt/PyDynamics.cpp) It looks like we can already achieve that with the current bindings ? If I am wrong, what is missing ?

jviereck commented 4 years ago

Some of the properties you can update from python already. However, for instance, there are no setters yet to update the main optimizer settings like the time_horizon etc. We also miss certain functionality like specyfing the initial robot configuration in more detail.

My current plan is to add a few new settings for the initial configuration. To modify the settings from python, it seems faster right now to load an existing yaml file in python, adjust the desired settings from there, write out a new yaml config file and use it for optimization. That's a bit of a hack but things done quicker.

pFernbach commented 4 years ago

Ok I understand better now. I will try with loading a yaml, modifying it and exporting it.

If I can achieve what I want I will add it as example in this repo.

pFernbach commented 4 years ago

I have started to add python bindings for the methods that I need and that aren't binded yet, see my branch https://github.com/pFernbach/kino_dynamic_opt/tree/topic/python_api

I will make a PR once I'm done.

pFernbach commented 4 years ago

Solved by https://github.com/machines-in-motion/kino_dynamic_opt/pull/23