Timesteps, control system integration

82 views
Skip to first unread message

Dave Grant

unread,
Feb 25, 2020, 10:11:05 PM2/25/20
to ProjectChrono
Hi all,

I'm just starting out with pychrono and trying to understand where to fit my control system into the code.


I see there is 
my_system.SetSolverMaxIterations(70)
and
myapplication.SetTimestep(0.001)
and a while loop with
myapplication.DoStep()

Wh
First off, what's the difference between iterations and timesteps? Are iterations subdivisions of timesteps? If I have a link acting on a body with a ChFunction, is that ChFunction called 70 or one time for each timestep?

If I put all my control system code (reading body positions,speeds,accelerations, PID calculations, setting body forces,positions,etc) in the loop with DoStep is there potentially things happening at a higher temporal frequency that my system is missing? Should I instead be putting all my control system code in a series of ChFunctions that act on various links?

Lastly, are timesteps in Irrlicht the same as timesteps in ChSystemNSC? Worded another way, is myapplication.DoStep() advancing the timestep in the system the same as one would if they ran a headless simulation without Irrlicht?

Thanks!


Radu Serban

unread,
Feb 26, 2020, 4:19:53 AM2/26/20
to projec...@googlegroups.com

Hi Dave,

Iterations relate to an underlying (linear, possibly with constrain projection) iterative solver that is used at every time step to solve for state corrections.  This is for the default settings for an NSC system (EulerImplicitLinearized timestepper (integrator) and the PSOR solver (iterative).   You can have other combinations, but to answer your first question: no such calls to physics items are made during the solve phase.

You should indeed put your control code in the simulation loop.  But you must be careful with using myapplication.DoStep, especially if you set it to enforce soft real-time (which is done in the example you linked to, see the call to myapplication.SetTryRealtime(True) before the loop).  Indeed, the way this is implemented, it may dynamically change the step size to a value below what you specify with myapplication.SetTimestep.  Having said that, with or without soft real-time enabled, myapplication.DoStep will only advance the system state once per execution of the simulation while loop. 

But when coupling a control system, you may want to just disable soft real-time and maybe even just replace the call to myapplication.DoStep with a call my_system.DoStepDynamics(step_size).  In that case, you can still enforce soft real-time, but with an alternate mechanism (which does not change the step size);  see my answer to Lucas's question here: https://groups.google.com/forum/#!topic/projectchrono/6x2R4-H_NHA. Note that you can still have the Irrlicht visualization, even if you don't let the Irrlicht app manage your time stepping; in other words, you can simply do:

while(myapplication.GetDevice().run()):
myapplication.BeginScene()
myapplication.DrawAll()
for substep in range(0,5):
my_system.DoStepDynamics(0.001)
myapplication.EndScene()

--Radu

--
You received this message because you are subscribed to the Google Groups "ProjectChrono" group.
To unsubscribe from this group and stop receiving emails from it, send an email to projectchron...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/projectchrono/ae906f14-2f05-4ae9-990f-0e8eef1aea35%40googlegroups.com.

Dave Grant

unread,
Feb 26, 2020, 12:24:34 PM2/26/20
to ProjectChrono
Excellent, thanks for the clear explanation. It looks like the code you posted is a good way to perform simulation / control system calcs at high frequency without tasking the CPU/GPU with lots of Irrlicht-related work. 
To unsubscribe from this group and stop receiving emails from it, send an email to projec...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages