Page 1 of 1

reset time

Posted: Thu Jul 14, 2022 4:09 am
by amini_opensim
Hello guys

I was wondering how can reset time at each subphase like swing or stance?

I defined a scriptcontroller that works with time. Due to time getting up, I want to apply it from t =0 at each swing or stance.

Do you know how to do it?

Re: reset time

Posted: Thu Jul 14, 2022 12:15 pm
by tgeijten
Unfortunately, the ScriptController does not restart time each time the controller gets reactivated. However, you can still detect this by keeping track of the previous model:time(), and checking if the difference is larger than the normal controller step size. If this is the case, you can set a t0 variable to the current time, which you can then subtract from model:time() in order to get the time since swing initiation in subsequent update() calls.

Re: reset time

Posted: Fri Jul 15, 2022 3:59 am
by amini_opensim
Thanks Thomas

for current simulation time, I used t=model:time() in update function. But How to get the pervious time or initializing time in int function? it doesn't work with t0 = model:time() in int function.

Would you please tell me how to script the update function to restart the time from zero?

Re: reset time

Posted: Fri Jul 15, 2022 1:28 pm
by tgeijten
In init(), add:

Code: Select all

prev_time = 0.0
t0 = 0.0
In update, do:

Code: Select all

local t = model:time()
if t - prev_time > 0.01 then
	t0 = t
end
prev_time = t
t = t - t0

Re: reset time

Posted: Fri Dec 29, 2023 11:55 pm
by amini_opensim
Hello Thomas

I have a specific question, and am appreciate to help me. I want to reset time my controller at each gait cycle meaning at the beginning EarlyStance. in fact, my controller runs for these states: "EarlyStance LateStance Liftoff Swing Landing".

if I use the reset time code you mentioned in previous message for only subphases like EarlyStance or others, time resets at each subphase. But If I use it for whole gait cycle, time goes up and don't reset at the beginning of EarlyStance. Could you tell me how I can fix it?

Best

Re: reset time

Posted: Mon Jan 15, 2024 11:36 am
by tgeijten
If your controller is active during all states of the GaitStateController, then indeed the time reset won't work. In your case, it is probably better to simply look at the calcn GRF to detect the start of each new gait cycle.