Page 1 of 1

frequency of different sensor

Posted: 11 Oct 2021, 10:30
by panecho
Do coppeliasim execute different child scripts at the same rate that specfied at the top of UI?

For if i have IMU and laser work in the same scene, Is it possible to execute the child scripts associated to corresponding sensor object at it's own rate independently?

Re: frequency of different sensor

Posted: 13 Oct 2021, 09:06
by coppelia
Hello,

yes, you are in full control about at which rate you want to execute and/or read things. First of all, during a simulation, there are two callback functions of particular interest:
  • sysCall_actuation()
  • sysCall_sensing()
Both are called in each simulation step. By default, this is every 50 ms. First, then actuation callback is called by the system, then the sensing callback.

For instance, if you want to check for collision between two objects in every simulation step, you'd simply do:

Code: Select all

function sysCall_init()
    object1=sim.getObjectHandle("shape1")
    object2=sim.getObjectHandle("shape2")
end

function sysCall_sensing()
    local result=sim.checkCollision(object1,object2)
    print(result)
end
If however you want to check for collision in every other simulation step (i.e. half of the time only), you could do:

Code: Select all

function sysCall_init()
    object1=sim.getObjectHandle("shape1")
    object2=sim.getObjectHandle("shape2")
    cnt=0
end

function sysCall_sensing()
    cnt=cnt+1
    if cnt==2 then
        cnt=0
        local result=sim.checkCollision(object1,object2)
        print(result)
    end
end
Proximity sensors are implicitly handled in each simulation step by default. But you can also explicitly handle them by checking their Explicit handling checkbox. Then, you can also do something like:

Code: Select all

function sysCall_init()
    sensorHandle=sim.getObjectHandle('myProxSensor')
    objectTodetect=sim.getObjectHandle('aRandomShape')
    -- sim.setExplicitHandling(sensorHandle,1) -- here via API, but via GUI also possible
    cnt=0
end

function sysCall_sensing()
    cnt=cnt+1
    if cnt==2 then
        cnt=0
        local result=sim.checkProximitySensor(sensorHandle,objectTodetect)
        print(result)
    end
end
Cheers