fastest way to check for occupancy

Typically: "How do I... ", "How can I... " questions
Post Reply
fferri
Posts: 679
Joined: 09 Sep 2013, 19:28

fastest way to check for occupancy

Post by fferri »

What's the fastest way of checking occupancy of a box region which is aligned with the world axes?

If I create a pure cuboid shape, scale it, and move it, then use simCheckCollision(cuboid, sim_handle_all) it would partially work, i.e. it would detect the occupancy if the face of the cube collides with some other mesh, but it would not detect if a collidable mesh is completely inside the test cube.

Moreover, what's the performance of this approach?

Is there something more efficient?

Simulation libraries should have efficient data structure for doing such fast queries, but are those data structures accessible by V-REP?

coppelia
Site Admin
Posts: 8107
Joined: 14 Dec 2012, 00:25

Re: fastest way to check for occupancy

Post by coppelia »

Hello,

in that case you should use a pyramid-type proximity sensor. In the detection parameters, check Fast detection (approximate) : what will be approximate is not the detection, but the returned detection distance (which will not be the smallest distance to the object).

Only with proximity sensors will you have the guarantee that shapes will be detected always. Using collision detection this does not always work as you mentioned it.

Cheers

fferri
Posts: 679
Joined: 09 Sep 2013, 19:28

Re: fastest way to check for occupancy

Post by fferri »

I didn't mention that I want to build an occupancy grid.

So imagine that you subdivide the 3D space into little cubes.

Each cube has to be tested for occupancy:
- some cubes are in the free space (indeed they don't collide)
- some cubes intersect the meshes of collidable objects (and they collide)
- some cubes are completely *inside* collidable objects (BUT they don't collide with the object)

EDIT: it works, but as with collision checking, the surface of the objects is detected.

I can probably live with that, after all also with real sensors we can only measure objects' surfaces.

The point is that meshes describe surfaces, so in general it's difficult (unless they are convex, or they are known shapes, like pure shapes).

If anyone's interested in the script, here it is (works with a pyramid proximity sensor with all sizes set to 0.05):

Code: Select all

function occ(p)
    simSetObjectPosition(sens,-1,p)
    r,d,p1=simCheckProximitySensor(sens,sim_handle_all)
    return r==1
end

if (sim_call_type==sim_childscriptcall_initialization) then
    sens = simGetObjectHandle('Proximity_sensor')
    res=0.05
    i=0
    j=0
    k=0
    col={{1,0,0},{0,1,0},{0,0.4,1},{1,1,0}}
    for x=-1,1,res do
        i=(i+1)%4
        for y=-1,1,res do
            j=(j+1)%4
            for z=-1,1,res do
                k=(k+1)%4
                h=(i+j+k)%4
                if occ({x,y,z}) then
                    c=simCreatePureShape(0,16,{res,res,res},0)
                    simSetObjectPosition(c,-1,{x,y,z})
                    simSetShapeColor(c,nil,sim_colorcomponent_ambient_diffuse,col[h+1])
                end
            end
        end
    end
end
Image

Post Reply