Collision Only With the Floor: Revisited

Typically: "How do I... ", "How can I... " questions
Post Reply
Sniggyfigbat
Posts: 7
Joined: 18 Nov 2019, 15:32

Collision Only With the Floor: Revisited

Post by Sniggyfigbat » 21 Nov 2019, 18:44

Very similarly to this thread, I am attempting to run multiple robots in the same space, without mutual collision. Essentially, I'm trying to simulate generations of evolutionarily-tweaked robots running a course, 100 robots (1 generation) at a time.

Unfortunately, that thread is now outdated, and it is recommended to use a contact callback function instead. That's fine, but I can't get it to work. I set ignoreContact to true and collisionResponse to false, but, while the function is definitely being called, the robot stubbornly refuses to phase through the wall.

Code: Select all

function sysCall_contactCallback(inData)
    sim.addStatusbarMessage("Collision callback triggered.")

    local retData={}
    retData.ignoreContact=true -- handle contact here
    retData.collisionResponse=false
    return retData
end
I'm fairly certain I'm putting it on the right sub-object (it's the one with the 'Collidable' property), so I'm a bit confused as to what I'm doing wrong. In addition, I'd rather not have to put a script on every collidable part of the robot, if that's something I can avoid.

What's the best solution to this in the current version of V-REP?

Sniggyfigbat
Posts: 7
Joined: 18 Nov 2019, 15:32

Re: Collision Only With the Floor: Revisited

Post by Sniggyfigbat » 21 Nov 2019, 19:06

After some fiddling, I have arrived at a terrible and inefficient solution:

Code: Select all

function sysCall_init()
    collection = sim.getCollectionHandle("EverythingButRobot")
    collidables = {}
end

function sysCall_contactCallback(inData)
    sim.addStatusbarMessage("Collision callback running.")

    local retData={}
    retData.ignoreContact=false -- handle contact here
    retData.collisionResponse=false

    collidables = sim.getCollectionObjects(collection)
    for key, handle in pairs(collidables) do
        if handle == inData.handle1 or handle == inData.handle2 then
        retData.ignoreContact=true
        end
    end

    return retData
end
This works, but barely runs. There must be a better solution. Please help.

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

Re: Collision Only With the Floor: Revisited

Post by coppelia » 27 Nov 2019, 14:23

There is probably a better solution:

Create a robot model like:

Code: Select all

floor --> robot
when you spawn a new robot, simply spawn the floor and the robot. Make sure that the floor is static and the robot is attached to that floor. Also make sure that in the robot, all respondable shapes have their global respondable masks cleared.

This way, the robot will only respond to collision with objects in its hierarchy, and robot-robot collisions won't be noticed.

Cheers

Post Reply