how to restart the time recording when the model is simulating

Typically: "How do I... ", "How can I... " questions
Post Reply
lwang87
Posts: 41
Joined: 24 May 2021, 16:47

how to restart the time recording when the model is simulating

Post by lwang87 »

Hello, now I can reset my model to a new position. And I want to know is there a way to restart the timerecording(recording from 0) when my model get to a new position?

coppelia
Site Admin
Posts: 10364
Joined: 14 Dec 2012, 00:25

Re: how to restart the time recording when the model is simulating

Post by coppelia »

Please give us more information. what is the timerecording? Is it a graph? another model?

Cheers

lwang87
Posts: 41
Joined: 24 May 2021, 16:47

Re: how to restart the time recording when the model is simulating

Post by lwang87 »

coppelia wrote: 31 May 2021, 14:41 Please give us more information. what is the timerecording? Is it a graph? another model?

Cheers
it means the Simulation Time will restart from 0 when the model is simulating, rather than stop the simulation.

coppelia
Site Admin
Posts: 10364
Joined: 14 Dec 2012, 00:25

Re: how to restart the time recording when the model is simulating

Post by coppelia »

No, you can't reset the simulation time to zero while simulation is running. If this is related to a graph plotting the data, you can create two specific graph streams (sim.addGraphStream) , one for the time, the other for value you want to record, then create an x/y curve with them (sim.addGraphCurve). Then, in the sensing section of a simulation script, handle new values, e.g. maybe like:

Code: Select all

function sysCall_init()
    graphHandle=sim.getObjectHandle(sim.handle_self)
    sim.destroyGraphCurve(graphHandle,-1)
    timeStreamId=sim.addGraphStream(graphHandle,'time','s')
    valueStreamId=sim.addGraphStream(graphHandle,'value','m')
    sim.addGraphCurve(graphHandle,'value',2,{timeStreamId,valueStreamId},{0,0},'m vs s')
    theValue=0
    theOffset=0
end

function sysCall_actuation()
    theValue=theValue+0.001
    t=sim.getSimulationTime()
    if t>10 and theOffset==0 then
        theOffset=-t -- reset the time here
    end
end

function sysCall_sensing()
    local theTime=sim.getSimulationTime()+theOffset
    sim.setGraphStreamValue(graphHandle,timeStreamId,theTime)
    sim.setGraphStreamValue(graphHandle,valueStreamId,theValue)
end
Cheers

lwang87
Posts: 41
Joined: 24 May 2021, 16:47

Re: how to restart the time recording when the model is simulating

Post by lwang87 »

coppelia wrote: 01 Jun 2021, 12:17 No, you can't reset the simulation time to zero while simulation is running. If this is related to a graph plotting the data, you can create two specific graph streams (sim.addGraphStream) , one for the time, the other for value you want to record, then create an x/y curve with them (sim.addGraphCurve). Then, in the sensing section of a simulation script, handle new values, e.g. maybe like:

Code: Select all

function sysCall_init()
    graphHandle=sim.getObjectHandle(sim.handle_self)
    sim.destroyGraphCurve(graphHandle,-1)
    timeStreamId=sim.addGraphStream(graphHandle,'time','s')
    valueStreamId=sim.addGraphStream(graphHandle,'value','m')
    sim.addGraphCurve(graphHandle,'value',2,{timeStreamId,valueStreamId},{0,0},'m vs s')
    theValue=0
    theOffset=0
end

function sysCall_actuation()
    theValue=theValue+0.001
    t=sim.getSimulationTime()
    if t>10 and theOffset==0 then
        theOffset=-t -- reset the time here
    end
end

function sysCall_sensing()
    local theTime=sim.getSimulationTime()+theOffset
    sim.setGraphStreamValue(graphHandle,timeStreamId,theTime)
    sim.setGraphStreamValue(graphHandle,valueStreamId,theValue)
end
Cheers
Thank you so much!

Post Reply