function sysCall_threadmain()
-- Put some initialization code here
-- Put your main loop here, e.g.:
--
-- while sim.getSimulationState()~=sim.simulation_advancing_abouttostop do
-- local p=sim.getObjectPosition(objHandle,-1)
-- p[1]=p[1]+0.001
-- sim.setObjectPosition(objHandle,-1,p)
-- sim.switchThread() -- resume in next simulation step
-- end
end
function sysCall_cleanup()
-- Put some clean-up code here
end
-- ADDITIONAL DETAILS:
-- -------------------------------------------------------------------------
-- If you wish to synchronize a threaded loop with each simulation pass,
-- enable the explicit thread switching with
--
-- sim.setThreadAutomaticSwitch(false)
--
-- then use
--
-- sim.switchThread()
--
-- When you want to resume execution in next simulation step (i.e. at t=t+dt)
--
-- sim.switchThread() can also be used normally, in order to not waste too much
-- computation time in a given simulation step
-- -------------------------------------------------------------------------
1.sim.getSimulationState()
1.1函数说明
Description | Retrieves current simulation state. See also the simulation state diagram. |
C synopsis | simInt simGetSimulationState() |
C parameters | None |
C return value | The current state of the simulation (sim_simulation_stopped, sim_simulation_paused, etc. (see the simulation state values)), or -1 in case of an error |
Lua synopsis | number simulationState=sim.getSimulationState() |
Lua parameters |
Same as C-function
|
Lua return values | Same as C-function |
sim.simulation_stopped
sim.simulation_paused
sim.simulation_advancing_firstafterstop
sim.simulation_advancing_running
sim.simulation_advancing_lastbeforepause
sim.simulation_advancing_firstafterpause
sim.simulation_advancing_abouttostop
sim.simulation_advancing_lastbeforestop
|
1.3 simulation state digram

2.1 sim.switchThread()
Description | Allows specifying the exact moment at which the current thread should switch to another thread. If the current script doesn't run in a thread (i.e. if it runs in the application main thread), this function has no effect. By default, V-REP doesn't use "regular" threads, but something similar to hybrid threads (which behave like coroutines, but can also behave like regular threads). This allows much more flexibility and execution control of the threads: each thread (except for the main or application thread) has a switch timing associated, which specifies how long the thread will run before switching to other threads. By default this value is 2 millisecond, but can be modified with sim.setThreadSwitchTiming. That timing can be shortened with sim.switchThread. Use with care when calling this function from a plugin. See alsothe sim.setThreadAutomaticSwitch, sim.setThreadResumeLocation and sim.setThreadIsFree functions. |
2.2 sim.setThreadAutomaticSwitch()
Description | Allows to temporarily forbid thread switches. If the current script doesn't run in a thread (i.e. if it runs in the application main thread), this function has no effect. By default, V-REP doesn't use "regular" threads, but something similar to hybrid threads (which behave like coroutines, but can also behave like regular threads). This allows much more flexibility and execution control of the threads. For complete control over the switching moment, see also sim.getThreadAutomaticSwitch, sim.setThreadSwitchTiming, sim.switchThread, sim.setThreadIsFree and sim.setThreadResumeLocation. |
参考来源:
此文中所有代码,文档摘自Vrep官方手册。