当前位置:网站首页>[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
边栏推荐
- Executing two identical SQL statements in the same sqlsession will result in different total numbers
- Know MySQL database
- D22:indeterminate equation (indefinite equation, translation + problem solution)
- [depth first search notes] Abstract DFS
- SPI communication protocol
- Cadre du Paddle: aperçu du paddlelnp [bibliothèque de développement pour le traitement du langage naturel des rames volantes]
- [eight part essay] what is the difference between unrepeatable reading and unreal reading?
- PHP campus movie website system for computer graduation design
- How to upgrade kubernetes in place
- Card 4G industrial router charging pile intelligent cabinet private network video monitoring 4G to Ethernet to WiFi wired network speed test software and hardware customization
猜你喜欢
Know MySQL database
1. Introduction to basic functions of power query
NiO related knowledge (II)
Online reservation system of sports venues based on PHP
How does redis implement multiple zones?
Redis list
Computer graduation design PHP college student human resources job recruitment network
Kubernetes stateless application expansion and contraction capacity
It's wrong to install PHP zbarcode extension. I don't know if any God can help me solve it. 7.3 for PHP environment
leetcode-两数之和
随机推荐
Know MySQL database
Paddle框架:PaddleNLP概述【飛槳自然語言處理開發庫】
Using SA token to solve websocket handshake authentication
Flowable source code comments (36) process instance migration status job processor, BPMN history cleanup job processor, external worker task completion job processor
Social networking website for college students based on computer graduation design PHP
dried food! Accelerating sparse neural network through hardware and software co design
Computer graduation design PHP campus restaurant online ordering system
Have a look at this generation
论文笔记: 极限多标签学习 GalaXC (暂存, 还没学完)
2 power view
D22:indeterminate equation (indefinite equation, translation + problem solution)
It's wrong to install PHP zbarcode extension. I don't know if any God can help me solve it. 7.3 for PHP environment
leetcode3、实现 strStr()
Folio. Ink is a free, fast and easy-to-use image sharing tool
Regular expressions: examples (1)
How to use C to copy files on UNIX- How can I copy a file on Unix using C?
抓包整理外篇——————状态栏[ 四]
Apicloud openframe realizes the transfer and return of parameters to the previous page - basic improvement
Audio and video engineer YUV and RGB detailed explanation
vs code保存时 出现两次格式化