save/restore states

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

save/restore states

Postby blackbird_dream » Wed Jan 06, 2021 8:11 am

Hi all and Happy New Year !!
Is there a way to save a state so that we can restore it later. With
state
I mean all body/joint positions and velocities.
Practically, imagine running a robot demo, make a pause, save the final state in a file, exit the program. Then launch the program again, load the file and carry on the simulation.
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: save/restore states

Postby Julio Jerez » Wed Jan 06, 2021 12:14 pm

There is a serialize funtionality, but that was never ported to unity pluggin.

if you run the demos the file menu, there is a serialize option, you can serialize a scene then re load it.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: save/restore states

Postby blackbird_dream » Wed Jan 06, 2021 12:42 pm

I don't use Unity for my biped project but C++

Thks

I'd like to try 2 ways of optimization:
One is to find the optimal control optimizing the cost function (based on muscle energy) over series of complete gait cycle.
and a second one is using Q learning, so determining the best control at each time step. That means trying different control increments from the current state and sort them to find the best using neural network algos.
hope it's not confusing 2 much.
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: save/restore states

Postby Julio Jerez » Thu Jan 07, 2021 8:09 am

Run the sdk sand box demo. And try the serialize scene menu option. Then see if you can load a serialized save that you prepared.

Basically, I think, you are trying to make some unsupervised learning algorithm to optimize a function using some fitness.
Something like


While not good enought
Restart simulation
RunSimulation
CompareResults

I would think you would do not need to save, onless the fitness function changes the actual joints configuration. But if you knew the initial parameters, in fact you can even start multiple simulations at once each with different variance of the fitness function in different newon woulds.



I
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: save/restore states

Postby blackbird_dream » Thu Jan 07, 2021 10:28 am

While not good enought
Restart simulation
RunSimulation
CompareResults


That's my initial goal.
Now I'd like to try something different in addition. In a few words, this is like :

At time step t0, try different choices of actuations to compute best fit for t0+dt. This is the reason why I must reload the configuration @ time t0 for each try.
This is achieved by using all time history of actuations and tries for t<t0 in a neural network approach.
This is the learning phase.
At the end we come with a stat database for each state of the biped that is used to compute the best actuation at the current time step.
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: save/restore states

Postby Julio Jerez » Thu Jan 07, 2021 11:31 am

blackbird_dream wrote:...
At time step t0, try different choices of actuations to compute best fit for t0+dt. This is the reason why I must reload the configuration @ time t0 for each try.



in that case all you need to do is implement the serialization.
the function is
void NewtonSerializeToFile (const NewtonWorld* const newtonWorld, const char* const filename, NewtonOnBodySerializationCallback bodyCallback, void* const bodyUserData)
there is also serialization to memory, you can look it up, serialization to file is just an implementation to serialize to a buffer.

it takes a callback to the body because bodies are C objects, you can simple ignores if you do not want to save anything. but in general people want to save the geometry or some custom info.

since the joints are classes, they have their own methods
virtual void Deserialize (NewtonDeserializeCallback callback, void* const userData);
virtual void Serialize (NewtonSerializeCallback callback, void* const userData) const;

if you are not overloading any of them it should just work, is no then you implement that callback and there you save whatever you need.

I just try in the SDK with the demo we made to test the springs and it worked.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: save/restore states

Postby blackbird_dream » Thu Jan 07, 2021 12:13 pm

thks a lot.
Can you upload the demo on the github pls ?
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: save/restore states

Postby Julio Jerez » Thu Jan 07, 2021 1:47 pm

The demo in in the sandbox.
You just select the last from the drop down menu.
Not all demo serialize because some use dedicate joint that I neve implement serialization. But the one that test the springs works.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 48 guests