how to restart the time recording when the model is simulating
how to restart the time recording when the model is simulating
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?
Re: how to restart the time recording when the model is simulating
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 (
Cheers
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
Re: how to restart the time recording when the model is simulating
Thank you so much!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:
CheersCode: 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