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

Typically: "How do I... ", "How can I... " questions
Post Reply
elizakh
Posts: 29
Joined: 20 Feb 2021, 13:27

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

Post 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! :)

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

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

Post 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

Post Reply