Page 1 of 1

How can I read the minimum value of the distance calculated with sim.checkDistance?

Posted: 17 May 2021, 22:01
by elizakh
Hi everyone,

During my simulation I'm reading the distance between a dummy and a ball in each step with sim.checkDistance.
After 20 seconds of simulation I want to send the minimum value of all those distances that I've read during the simulation.
So I want to know if there's some function to obtain the minimum value of all the distances that I've calculated in the simulation.

Thanks in advance

Cheers! :)

Re: How can I read the minimum value of the distance calculated with sim.checkDistance?

Posted: 18 May 2021, 14:10
by coppelia
Hello,

from within a non-threaded child script, maybe something like:

Code: Select all

function sysCall_init()
end

function sysCall_sensing()
    local threshold=smallestDistance
    if threshold==nil then
        threshold=0
    end
    local r,dist=sim.checkDistance(dummyHandle,ballHandle,threshold)
    if r>0 then
        smallestDistance=dist[7]
    end
    if sim.getSimulationTime()>20 and smallestDistance then
        -- send smallestDistance
    end
end
Cheers