Vrep基础部分(三)

主要说一下两种子脚本的区别:多线程子脚本和单线程子脚本。

(1)单线程子脚本,它包含四部分:

 

the initialization function: sysCall_init. This part will be executed just one time (the first time the child script is called). This can be at the beginning of a simulation, but also in the middle of a simulation: remember that objects associated with child scripts can be copy/pasted into a scene at any time, also when a simulation is running. Usually you would put some initialization code as well as handle retrieval in this part.
the actuation function: sysCall_actuation. This part will be executed in each simulation step, during the actuation phase of a simulation step. Refer to the main script default code for more details about the actuation phase, but typically, you would do some actuation in this part (no sensing).
the sensing function: sysCall_sensing. This part will be executed in each simulation step, during the sensing phase of a simulation step. Refer to the main script default code for more details about the sensing phase, but typically, you would only do sensing in this part (no actuation).
the restoration function: sysCall_cleanup. This part will be executed one time just before a simulation ends, or before the script is destroyed.

即初始化函数、驱动函数、检测函数、恢复函数(恢复到初始状态)。仿真开始后,主脚本通过sim.handleChildScripts命令调用子脚本执行初始化函数,此函数在整个仿真过程中,只执行一次;然后,调用驱动函数和检测函数。每仿真一步,这两个函数会执行一次。恢复函数仅在仿真结束或者销毁前执行一次。

(2)多线程子脚本

多线程子脚本包含两部分:

 

the main part: this part will be executed when the thread starts, until shortly before the thread ends. This can be at the beginning of a simulation, but also in the middle of a simulation: remember that objects associated with child scripts can be copy/pasted into a scene at any time, also when a simulation is running. Usually you would put some initialization code as well as the main loop in this part: the code in the loop is in charge of handling a specific part of a simulation (e.g. handle the automatic sliding door). In above specific example, the loop is wasting precious computation time and is running asynchronously with the main simulation loop. See further down for a better example.
the restoration part: this part will be executed one time just before a simulation ends, or before the thread ends.

即主函数和恢复部分。仿真开始后,主脚本通过sim.launchThreadedChildScripts命令开启一个新的进程运行子脚本,当下一个采样周期到达时,当子脚本属性中未选择execute once且子脚本程序都运行完,才能再次启动该子脚本。

总结:在一般应用中,通常选单线程子脚本。

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值