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?
reset time
- Thomas Geijtenbeek
- Posts: 450
- Joined: Wed Mar 12, 2014 8:08 am
Re: reset time
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.
- Samane Amini
- Posts: 101
- Joined: Sun Jan 12, 2020 3:48 am
Re: reset time
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?
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?
- Thomas Geijtenbeek
- Posts: 450
- Joined: Wed Mar 12, 2014 8:08 am
Re: reset time
In init(), add:
In update, do:
Code: Select all
prev_time = 0.0
t0 = 0.0
Code: Select all
local t = model:time()
if t - prev_time > 0.01 then
t0 = t
end
prev_time = t
t = t - t0
- Samane Amini
- Posts: 101
- Joined: Sun Jan 12, 2020 3:48 am
Re: reset time
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
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
- Thomas Geijtenbeek
- Posts: 450
- Joined: Wed Mar 12, 2014 8:08 am
Re: reset time
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.