how to build a counter for the laser pointer when the laser pointer was triggered ?

Typically: "How do I... ", "How can I... " questions
Post Reply
jianye
Posts: 45
Joined: 16 Oct 2019, 13:58

how to build a counter for the laser pointer when the laser pointer was triggered ?

Post by jianye »

hello,

i have built a safety light curtain and i want to build a counter to store the times that the laser pointer was triggered.

how can I realize this function ?

any advice ?

Jian

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

Re: how to build a counter for the laser pointer when the laser pointer was triggered ?

Post by coppelia »

The simplest is to use a non-threaded child script for that. In the sensing section, read your proximity sensor with sim.readProximitySensor. Compare the detection value with the value read in previous simulation step. If the value goes from no detection to detection, then increment your counter.

Cheers

jianye
Posts: 45
Joined: 16 Oct 2019, 13:58

Re: how to build a counter for the laser pointer when the laser pointer was triggered ?

Post by jianye »

hello,

how can I know the detection status of no detection and detection?

and can i read the value of the previous simulation step?

thank you in advance.

Jian

fferri
Posts: 671
Joined: 09 Sep 2013, 19:28

Re: how to build a counter for the laser pointer when the laser pointer was triggered ?

Post by fferri »

jianye wrote:
28 Nov 2019, 21:42
hello,

how can I know the detection status of no detection and detection?
sim.readProximitySensor
jianye wrote:
28 Nov 2019, 21:42
and can i read the value of the previous simulation step?
Before storing the result in a variable, that variable will contain the result of the previous simulation step.

E.g.:

Code: Select all

function sysCall_sensing()
    result,d,p,h,n=sim.readProximitySensor(sensorHandle)
    if oldresult==0 and result==1 then
        -- do something
    end
    oldresult=result
end

jianye
Posts: 45
Joined: 16 Oct 2019, 13:58

Re: how to build a counter for the laser pointer when the laser pointer was triggered ?

Post by jianye »

I understand, thank you so much.

Post Reply