当前位置:网站首页>[coppeliasim] efficient conveyor belt
[coppeliasim] efficient conveyor belt
2022-07-06 02:12:00 【Ten year dream laboratory】
-- Efficient conveyor model script
function sysCall_init()
config={}
-- Modify following to customize your conveyor:
-----------------------------------------------
config.size={1,0.2,0.1} -- LWH
config.col1={0.2,0.2,0.2}-- Belt color
config.col2={0.5,0.5,0.5}-- Solid color
config.initPos=0-- initial position 0
config.initVel=0.1-- Initial speed 0.1
config.accel=1.5-- Initial acceleration 1.5
-----------------------------------------------
-- To command the conveyor externally or from another script, simply do:
--
-- sim.writeCustomDataBlock(conveyorHandle,'CONVMOV',sim.packTable({vel=0.1})) -- vel. ctrl
--
-- or:
--
-- sim.writeCustomDataBlock(conveyorHandle,'CONVMOV',sim.packTable({pos=0.1})) -- pos. ctrl
--
-- Its current position can be read with:
-- local data=sim.readCustomDataBlock(model,'CONVMOV')
--
-- if data then
-- local currentPos=data.currentPos
-- end
model=sim.getObjectHandle(sim.handle_self)-- Conveyor belt Model handle
visible1=sim.getObjectHandle('efficientConveyor_visible1')-- Visible models 1 Handle
visible2=sim.getObjectHandle('efficientConveyor_visible2')-- Visible models 2 Handle
forwarder=sim.getObjectHandle('efficientConveyor_forwarder')-- Forward handle
sim.setShapeColor(visible1,'',sim.colorcomponent_ambient_diffuse,config.col1)-- Set the color
sim.setShapeColor(visible2,'',sim.colorcomponent_ambient_diffuse,config.col2)-- Set the color
sim.setShapeBB(visible1,config.size)-- Set shape
sim.setShapeBB(visible2,{config.size[1]+0.005,config.size[2]+0.005,config.size[3]})-- Set shape x,y The direction is slightly larger
sim.setShapeBB(forwarder,config.size)-- Set shape size
sim.setObjectPosition(visible1,model,{0,0,-config.size[3]/2})-- Set the model location
sim.setObjectPosition(visible2,model,{0,0,-config.size[3]/2-0.0025})-- A little lower
sim.setObjectPosition(forwarder,model,{0,0,-config.size[3]/2})-- Model location
pos=config.initPos-- initial position
prevPos=pos-- Record the last position
targetVel=config.initVel-- Target speed : Initial speed
vel=0-- Last speed
accel=config.accel-- The acceleration
sim.writeCustomDataBlock(model,'CONVMOV',sim.packTable({currentPos=pos}))-- Set the conveyor position
end
function sysCall_afterSimulation()
pos=config.initPos -- After the simulation , Set location
prevPos=pos-- Update the previous location
targetVel=config.initVel-- Set to initial speed
vel=0-- Update the last speed
accel=config.accel-- Set to initial acceleration
sim.writeCustomDataBlock(model,'CONVMOV',sim.packTable({currentPos=pos}))-- Set the conveyor belt back to its initial position
end
function sysCall_actuation()
local dat=sim.readCustomDataBlock(model,'CONVMOV')-- Read belt data
local off
if dat then
dat=sim.unpackTable(dat)
if dat.offset then
off=dat.offset-- The offset of the conveyor belt required
end
if dat.vel then
targetVel=dat.vel-- Belt speed
end
if dat.accel then
accel=dat.accel-- Belt acceleration
end
end
local velErr=targetVel-vel-- Calculate the speed adjustment
local velErrAbs=math.abs(velErr)
local velErrSign=velErrAbs>1e-4 and velErr/velErrAbs or 1-- Direction of movement
if velErrAbs>1e-6 then
vel=vel+math.min(velErrAbs,accel*velErrSign*sim.getSimulationTimeStep())-- Update speed
end
if off or vel~=0 then-- Offset and speed is non-zero
if off then
pos=off-- Set the conveyor position to offset
else-- When there is no set offset, the position is calculated
pos=pos+vel*sim.getSimulationTimeStep()-- Calculate the conveyor position
end
setPos(pos)-- Update the conveyor position
end
if not dat then-- Data is empty
dat={}
end
dat.currentPos=pos-- Record the current position of the conveyor
sim.writeCustomDataBlock(model,'CONVMOV',sim.packTable(dat))-- Write data block Belt data
end
function setPos(p)
-- Here we "fake" the transportation pads with a single static rectangle that we dynamically reset
-- at each simulation pass (while not forgetting to set its initial velocity vector) :
-- ad locum , We use a single static rectangle that we reset dynamically “ forge ” Transport mat
-- During each simulation ( At the same time, don't forget to set its initial speed vector ):
local relativeLinearVelocity={(p-prevPos)/sim.getSimulationTimeStep(),0,0}-- Along x Direction relative to linear velocity
prevPos=pos-- Record the initial position
-- Reset the dynamic rectangle from the simulation (it will be removed and added again)
-- Reset the dynamic rectangle from the simulation ( It will be deleted and added again )
sim.resetDynamicObject(forwarder)
-- Compute the absolute velocity vector: Calculate the absolute velocity vector :
local m=sim.getObjectMatrix(forwarder,-1)-- Get the pose matrix of the forward rectangle , And set the position to 0
m[4]=0 -- Make sure the translation component is discarded
m[8]=0 -- Make sure the translation component is discarded
m[12]=0 -- Make sure the translation component is discarded
local absoluteLinearVelocity=sim.multiplyVector(m,relativeLinearVelocity)-- Absolute speed : From relative linear velocity to Move forward under the rectangular coordinate system .
-- Now set the initial velocity of the dynamic rectangle: Now set the initial speed of the dynamic rectangle :
sim.setObjectFloatParam(forwarder,sim.shapefloatparam_init_velocity_x,absoluteLinearVelocity[1])
sim.setObjectFloatParam(forwarder,sim.shapefloatparam_init_velocity_y,absoluteLinearVelocity[2])
sim.setObjectFloatParam(forwarder,sim.shapefloatparam_init_velocity_z,absoluteLinearVelocity[3])
end
边栏推荐
- Leetcode3. Implement strstr()
- Virtual machine network, networking settings, interconnection with host computer, network configuration
- Install redis
- Computer graduation design PHP college classroom application management system
- [width first search] Ji Suan Ke: Suan tou Jun goes home (BFS with conditions)
- Dynamics 365 开发协作最佳实践思考
- Campus second-hand transaction based on wechat applet
- 2022年PMP项目管理考试敏捷知识点(8)
- Know MySQL database
- Blue Bridge Cup embedded_ STM32 learning_ Key_ Explain in detail
猜你喜欢
Alibaba canal usage details (pit draining version)_ MySQL and ES data synchronization
02.Go语言开发环境配置
2 power view
Derivation of Biot Savart law in College Physics
Computer graduation design PHP college classroom application management system
Online reservation system of sports venues based on PHP
Leetcode3. Implement strstr()
插卡4G工业路由器充电桩智能柜专网视频监控4G转以太网转WiFi有线网速测试 软硬件定制
论文笔记: 图神经网络 GAT
安装php-zbarcode扩展时报错,不知道有没有哪位大神帮我解决一下呀 php 环境用的7.3
随机推荐
This time, thoroughly understand the deep copy
Install redis
Computer graduation design PHP campus restaurant online ordering system
插卡4G工业路由器充电桩智能柜专网视频监控4G转以太网转WiFi有线网速测试 软硬件定制
同一个 SqlSession 中执行两条一模一样的SQL语句查询得到的 total 数量不一样
论文笔记: 图神经网络 GAT
Flutter Doctor:Xcode 安装不完整
500 lines of code to understand the principle of mecached cache client driver
02. Go language development environment configuration
Redis key operation
Reasonable and sensible
Regular expressions: examples (1)
Use image components to slide through photo albums and mobile phone photo album pages
【机器人手眼标定】eye in hand
Redis如何实现多可用区?
Unreal browser plug-in
[eight part essay] what is the difference between unrepeatable reading and unreal reading?
竞赛题 2022-6-26
NumPy 数组索引 切片
Exness: Mercedes Benz's profits exceed expectations, and it is predicted that there will be a supply chain shortage in 2022