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

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

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

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.

Cheers! :)

coppelia
Posts: 8611
Joined: 14 Dec 2012, 00:25

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

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