## Efficient curved conveyor using angular velocity instead of path

Typically: "How do I... ", "How can I... " questions
Justus
Posts: 42
Joined: 24 Jan 2017, 07:37

### Efficient curved conveyor using angular velocity instead of path

Hi,

The circular conveyor in the example model browser (equipment->conveyor belts->"circular conveyor belt.ttm") uses a path. This works, but is not very efficient. So I tried to create a more efficient one using the same method as used with the "conveyor belt (very efficient).ttm", but using sim_shapefloatparam_init_velocity_g instead of sim_shapefloatparam_init_velocity_x/y/z:

Code: Select all

if (sim_call_type==sim_childscriptcall_initialization) then
forwarder=simGetObjectAssociatedWithScript(sim_handle_self)
speed=0.1
end

if (sim_call_type==sim_childscriptcall_actuation) then
simResetDynamicObject(forwarder)
simSetObjectFloatParameter(forwarder,sim_shapefloatparam_init_velocity_g,speed)
end

This works but rotation is relative to the geometric centre of the shape. Fine when creating 360 degree conveyors, but not for 90 degree conveyors. I can move the centre by grouping a extra shape to the plane, like so: http://imgur.com/ewUpSX4

But now I have a extra shape responding to the environment. Is there any other way to change the geometric centre, or a different way to create a very efficient angular conveyor?

Regards,
Justus

coppelia
Posts: 8730
Joined: 14 Dec 2012, 00:25

### Re: Efficient curved conveyor using angular velocity instead of path

Hello Justus,

ok, if I understood you correctly, you have other ways, next to what you did. For example:
• If the rotation center is not where the shape center is, then you will have to add an initial rotation and an initial translation
• Use a combination of two shapes and two joints, and move the first joint by a few degrees, while the other shape is non-respondable. Then reset the first joint, make its shape non-respondable. And make the second shape respondable, then move the joint of the second shape. Once you have moved the second joint by a few degrees, reset it, set the second shape to non-respondable, and start all over with the first joint and its shape.
Cheers

Justus
Posts: 42
Joined: 24 Jan 2017, 07:37

### Re: Efficient curved conveyor using angular velocity instead of path

The 2nd option works (thanks!) but adds some extra shapes and joints, so I'm trying to work out your first suggestion.

I can rotate the shape around the correct axis (using simRotateAroundAxis), like so:

Code: Select all

m=simRotateAroundAxis(m,{0,0,1},{-2,0,0},math.rad(speed))
simSetObjectMatrix(forwarder,-1,m)
Should I use this matrix to calculate a combination of linear and angular velocities? Maybe you can explain a bit more about adding initial rotation and an initial translation?

coppelia
Posts: 8730
Joined: 14 Dec 2012, 00:25

### Re: Efficient curved conveyor using angular velocity instead of path

The initial rotation velocity component (i.e. G) would be the same as you did previously. But in addition, you need to figure out an initial linear velocity. That velocity is basically: R*G, where R is the distance to the rotation center.

Probably you have to transform that velocity into an X and Y velocity component, depending on the bounding box of your shape. And for that, you can use the shape matrix.

Cheers

Justus
Posts: 42
Joined: 24 Jan 2017, 07:37

### Re: Efficient curved conveyor using angular velocity instead of path

Works like a charm:

Code: Select all

simSetObjectFloatParameter(forwarder,sim_shapefloatparam_init_velocity_g,speed)
simSetObjectFloatParameter(forwarder,sim_shapefloatparam_init_velocity_x,speed*-factor)
simSetObjectFloatParameter(forwarder,sim_shapefloatparam_init_velocity_y,speed*factor)

Where factor=outer radius of the conveyor/2 (in case of a 90 degree angular conveyor). When creating a 45 degree conveyor, calculations are a bit more complex.

Thanks!

Justus
Posts: 42
Joined: 24 Jan 2017, 07:37

### Re: Efficient curved conveyor using angular velocity instead of path

I've been working with using the above velocity tricks, but I'm getting unpredictable behaviour when running conveyors on slow speeds.

Link to sample scene: https://www.dropbox.com/s/0posq8dzc0t4w ... m.ttt?dl=0

The code is (hopefully) self-explanatory:

Code: Select all

if (sim_call_type==sim_childscriptcall_initialization) then

-- fill a table with conveyor shape handles
tblHnd={}
for i=1,4,1 do
tblHnd[i]=simGetObjectHandle("conv"..i)
end

-- Get Y size of (any) conveyor shape bouding box
local r,mmin=simGetObjectFloatParameter(tblHnd[1],sim_objfloatparam_objbbox_min_y)
local r,mmax=simGetObjectFloatParameter(tblHnd[1],sim_objfloatparam_objbbox_max_y)
local sy=mmax-mmin

-- Calculate distance of boundig box center to circle center

numAngularVel=2*math.pi/30 -- angular velocity set so that we travel the full circle in 30 seconds
end

if (sim_call_type==sim_childscriptcall_actuation) then

for i=1,4,1 do

simResetDynamicObject(tblHnd[i])

-- Set angular velocity
simSetObjectFloatParameter(tblHnd[i],sim_shapefloatparam_init_velocity_g,numAngularVel)

-- Move angular velocity axis by applying linear velocity, based on the speed and distance calculated before
local m=simGetObjectMatrix(tblHnd[i],-1)
m[4]=0
m[8]=0
m[12]=0

local tblAbsLinearVelocity=simMultiplyVector(m,{numDistance*numAngularVel,0,0})
simSetObjectFloatParameter(tblHnd[i],sim_shapefloatparam_init_velocity_x,tblAbsLinearVelocity[1])
simSetObjectFloatParameter(tblHnd[i],sim_shapefloatparam_init_velocity_y,tblAbsLinearVelocity[2])
simSetObjectFloatParameter(tblHnd[i],sim_shapefloatparam_init_velocity_z,tblAbsLinearVelocity[3])

end

end

if (sim_call_type==sim_childscriptcall_sensing) then
end

if (sim_call_type==sim_childscriptcall_cleanup) then
end

When running this at the above settings (travel the complete circle in 30 seconds), it looks OK. Not perfect, but fit for purpose. However, when I change it to travel in 60 seconds, behaviour is getting strange.

Been banging my head against a wall on this problem for a while now... Can anybody tell me what I'm doing wrong here?
Thanks!

coppelia
Posts: 8730
Joined: 14 Dec 2012, 00:25

### Re: Efficient curved conveyor using angular velocity instead of path

Hello,

it seems the problem is linked to some kind of threshold in the Bullet engine. I can't figure out where that setting would be (if it really is that). The reason that makes me think it is a threshold of the physics engine, is because all other engines handle the task quite fine (ODE, Vortex and Newton). Vortex became available for free (given that you register with them), I highly recommend using it.

Cheers

Justus
Posts: 42
Joined: 24 Jan 2017, 07:37

### Re: Efficient curved conveyor using angular velocity instead of path

Hi,

Thanks for looking into it, now I know the code is ok and the problem is most likely with the bullet engine.
I do prefer working with the Vortex engine, but it is much slower than bullet (which has an overall best performance).

Maybe we can think of a way to fool bullet (a work around).
For instance increasing the velocity and adding another shape with opposed velocity so the sum of velocities ends up being the original target velocity. No idea if the engine will handle it well, will give it a try. If you have any suggestions please let me know,

Thanks again &
Cheers
Justus

coppelia
Posts: 8730
Joined: 14 Dec 2012, 00:25

### Re: Efficient curved conveyor using angular velocity instead of path

By setting the dynamics step from 5ms to 10ms, you can obtain better results. But this is kind of artificially increasing the engine's internal threshold, does not scale much further, and is not such a good idea.
If you have a cylinder rotating with an item on top of it, you also have that kind of strange behaviour with small velocities.

Or you could use a proximity sensor to detect if the item is on the conveyor, make it static and programmatically handle its motion. But that brings other problems by not being able to grasp the object anymore, the object not falling, etc, unless you make it dynamic again in certain conditions.

Not sure if I find time to look into the Bullet engine to find out about this threshold... but that would be the best solution.

Cheers

Justus
Posts: 42
Joined: 24 Jan 2017, 07:37

### Re: Efficient curved conveyor using angular velocity instead of path

Yes I noticed that effect on cylinders as well, and have been using the static method on straight conveyors. But especially the behaviour in corners is useful to simulate (for instance when using multiple tracks with different speeds to manipulate the angle of objects coming out of a corner). Anyways, I hope you can find the threshold setting, if I can help in any way (browsing the bullet forums?) let me know!

And thanks for the quick replies!