Vrep脚本的执行顺序

本文介绍了V-REP仿真软件中脚本的执行顺序及其控制方式。具体包括使用Script toolbar button Execution order来设置非线程子脚本的执行顺序,以及通过sim.switchThread()函数来精确控制当前线程何时切换到另一个线程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

具体情况看这个答案:

 Problems about simulation loop - V-REP Forum 

 http://www.forum.coppeliarobotics.com/viewtopic.php?f=9&t=5856&p=23502&hilit=cascaded+order#p23502

Vrep 中non-threaded child scripts的执行顺序是未知的但是可以人为指定。

1.使用Scirpt toolbar button


Execution order: specifies the execution order for a scripts. The execution order only has an effect on scripts located on similar hierarchy level. You can set the  execution  priority or  order  for child script in the  script dialog . This will however have an effect only if the two scripts are either both threaded or both non-threaded. On top  of  that, if your first script is built on the hierarchy  of  the second script, then will will not work either, because scripts are executed in a cascaded fashion (i.e. cascaded  order : first  the main script  will execute. The main script will then first launch the threaded child scripts in a cascaded fashion (with  simLaunchThreadedChildScripts ), then the non-threaded child scripts (also in a cascaded fashion, with  simHandleChildScripts ).

2.使用sim.switchThread()                                                                                                                                                                          

DescriptionAllows 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 also the sim.setThreadAutomaticSwitchsim.setThreadResumeLocation and sim.setThreadIsFree functions.
Lua return values
result: 1 if the thread was switched (the current thread gave control to other threads until the next calculation pass), 0 if it was not switched (e.g. because the function was called from the main or application thread), or -1 in case of an error.



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值