reset time

SCONE is a software tool for predictive simulations of biomechanical movement. It uses OpenSim for modeling and simulation, and performs optimization using various control strategies, including feed-forward control, proprioceptic feedback control, and bal
POST REPLY
User avatar
Samane Amini
Posts: 100
Joined: Sun Jan 12, 2020 3:48 am

reset time

Post by Samane Amini » Thu Jul 14, 2022 4:09 am

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?

User avatar
Thomas Geijtenbeek
Posts: 432
Joined: Wed Mar 12, 2014 8:08 am

Re: reset time

Post by Thomas Geijtenbeek » Thu Jul 14, 2022 12:15 pm

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.

User avatar
Samane Amini
Posts: 100
Joined: Sun Jan 12, 2020 3:48 am

Re: reset time

Post by Samane Amini » Fri Jul 15, 2022 3:59 am

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?

User avatar
Thomas Geijtenbeek
Posts: 432
Joined: Wed Mar 12, 2014 8:08 am

Re: reset time

Post by Thomas Geijtenbeek » Fri Jul 15, 2022 1:28 pm

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

User avatar
Samane Amini
Posts: 100
Joined: Sun Jan 12, 2020 3:48 am

Re: reset time

Post by Samane Amini » Fri Dec 29, 2023 11:55 pm

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

User avatar
Thomas Geijtenbeek
Posts: 432
Joined: Wed Mar 12, 2014 8:08 am

Re: reset time

Post by Thomas Geijtenbeek » Mon Jan 15, 2024 11:36 am

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.

POST REPLY