Unable to disable autosleep

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Unable to disable autosleep

Postby JoeJ » Sat Aug 03, 2013 6:17 am

I have 2 bodies connected by a powered joint.
If they get to rest, it seems they get to sleep mode and don't wake up if i change the powering target so they should start to move.

I call this for both bodies each timestep:
Code: Select all
base_debug::logF->Print ("Autosleep State: ", (float)NewtonBodyGetAutoSleep (balBl));
base_debug::logF->Print ("Freeze State: ", (float)NewtonBodyGetFreezeState (balBl));

NewtonBodySetAutoSleep (balBl, 0);
NewtonBodySetAutoSleep (balBu, 0);
NewtonBodySetFreezeState (balBl, 0);
NewtonBodySetFreezeState (balBu, 0);


...but it does not help.
The logging output is always 0 for both states, but they seem to be sleeping.

The only thing that helps is adding another joint to one of the bodies.
This joint does nothing (submit function returns immideatly), but it seems the creation of that joint wakes up the bodies successfully.

What do i miss here?
User avatar
JoeJ
 
Posts: 1494
Joined: Tue Dec 21, 2010 6:18 pm

Re: Unable to disable autosleep

Postby Julio Jerez » Sat Aug 03, 2013 10:27 am

wouldn't these

NewtonBodySetAutoSleep (balBl, 0);
NewtonBodySetAutoSleep (balBu, 0);

do it?
Julio Jerez
Moderator
Moderator
 
Posts: 12478
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Unable to disable autosleep

Postby JoeJ » Sat Aug 03, 2013 11:29 am

No, that's what i initially did once at body creation.
Then i've added setting freeze state too, then i did all that once per step - but no effect.

I've also added some logging to the powered hinge joint itself:

Code: Select all
base_debug::logF->Print ("Hinge: relAccel = ", relAccel);
                  NewtonUserJointAddAngularRow (joint, 0.0f, &axis[0]); rowIndex++;
                  NewtonUserJointSetRowAcceleration (joint, relAccel);
                  NewtonUserJointSetRowMinimumFriction (joint, -m_maxAngularFriction);
                  NewtonUserJointSetRowMaximumFriction (joint,  m_maxAngularFriction);
                  NewtonUserJointSetRowStiffness (joint,  propsPhysics::f[propsPhysics::rjStiffness]);

                  torqueMag = NewtonUserJointGetRowForce( joint, rowIndex-1);
                  torque = axis * torqueMag;
base_debug::logF->Print ("Hinge: torqueMag = ", torqueMag);


Here i see that the relAccel ouput is changing all the time,
but the torqueMag output stays constant when the bodies fall asleep.

I've also tried to change the hinge angle limits at runtime, so that the sleeping state violates them.
But this also does not wake up the system, so it's not related to powering rows alone. *)

I'm not sure, but maybe this is in newton since i use it.
Because the ragdall is so complex it happened so rarely i did not worry.
But with the simple two-body setup it happens always.

As a work around i create a temporary joint attached to one of the bodies, and delete it immideatly before doing the simulation step.
All fine with this.

*) EDIT:
Note that i also do the hinge angle limits with angular rows, so the problem may be related to only angular rows.
I did not check linear rows.
Maybe you forgot to add a wake up check with the user joint rows?
User avatar
JoeJ
 
Posts: 1494
Joined: Tue Dec 21, 2010 6:18 pm

Re: Unable to disable autosleep

Postby Julio Jerez » Sat Aug 03, 2013 12:44 pm

are you try to wake up two sleep bodies form a joint callback?
by design that's not going to work. in Newton 300 the only call back the gets call for all bodies is Force an true call back.

The force and toque callback is like eh hard beat of a body,
you can do something like

Code: Select all
// add force and torque to rigid body
void  PhysicsApplyGravityForce (const NewtonBody* body, dFloat timestep, int threadIndex)
{
   dFloat Ixx;
   dFloat Iyy;
   dFloat Izz;
   dFloat mass;

   NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz);
   dVector force (0.0f, mass * DEMO_GRAVITY, 0.0f);
   NewtonBodySetForce (body, &force.m_x);

...
         // check soemn logic
         NewtonBodySetSleepState(body, state ? 1 : 0);
}


A more elegant way to do that is using the new functionality of core 300, by can add a CustomControllerManager
in core 300 these are sub system that control how sub grop of object that share the same proprety are manipulated

basicall you make a class derived from CustomControllerBase
and you add a Manager of type

Code: Select all
MyWakeController: public CustomControllerBase
{
   virtual void PreUpdate (dFloat timestep, int threadIndex)
                {
                        NewtonBodySetSleepState(m_body, 1);
                }

   virtual void PostUpdate (dFloat timestep, int threadIndex) {}
}

class MyWakupManager: public CustomControllerManager<CustomTriggerController>
{
   public:
   NEWTON_API MyWakupManager(NewtonWorld* const world);
   NEWTON_API virtual ~MyWakupManagerr();

                virtual void PostUpdate(dFloat timestep)
   {
      // bypass the entire Post Update call by not calling the base class
   }

   virtual void Debug () const {};
   NEWTON_API virtual CustomWakeController* CreateTrigger (NetwonBodyt* body);

};



then by adding the bodies that you want to be in no sleeping state to the manager then the will be wake up on the pre Update call
I like the Controller mangers new functionality of Newton because it offer an nom intrusive way to costomize object functionality.

by making multiple controller, for example trigger managarer, rag doll manager, player manager, mouse picked manager, etc bodies can have multiply functionalities

for example a body, can be on a Trigger Volume, and Vortex Volume, being picked, and under Gravity all at the same time
and the manage will handle the transparently, by operating on those bodes as there are part the mamanger with having to code that fuintionality on the body or on the user date that own that controller.
Julio Jerez
Moderator
Moderator
 
Posts: 12478
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Unable to disable autosleep

Postby JoeJ » Sat Aug 03, 2013 1:22 pm

are you try to wake up two sleep bodies form a joint callback?


No, i did outside any callback.
I will try to use CustomController to see if it works from there.

Thanks for explantation on that, i'll take a closer look...
I already planned to do that for another purpose:
I want something like ForceTorqueCallback, but it should get called at substep level.
Also i'would need access to all ragdoll bodies at that point, so there's some need to sync physics state and threading an that point.
Is that possible?

What i do is: Unify velocities of all ragdoll bodies a little bit to remove oszillations and add 'joint friction'.
It works very well and i take care that momentum is conserved, simulation is much more realistic with it.
It should be useable to assist powering as well, if i can run that at substep level.
User avatar
JoeJ
 
Posts: 1494
Joined: Tue Dec 21, 2010 6:18 pm

Re: Unable to disable autosleep

Postby JoeJ » Sat Aug 03, 2013 1:56 pm

Ah sorry, missed that.
Yes - if i set Sleep State in F/T Callback, it works like expected :)
User avatar
JoeJ
 
Posts: 1494
Joined: Tue Dec 21, 2010 6:18 pm

Re: Unable to disable autosleep

Postby Julio Jerez » Sat Aug 03, 2013 2:22 pm

Ha good,
try the controller manager, it is a very powerful feature for that kind of stuff

they have pre and post update method that can be call to post proses objects.
Julio Jerez
Moderator
Moderator
 
Posts: 12478
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 1 guest