Ray cast sensor ComponentSignal.Value is None?

Hi there people. I want to model a Ray Cast sensor, that simply reads the value while the simulation is running.

So I followed this video: https://www.youtube.com/watch?v=3iVxRe73PNQ but the video was configured the sensor mounted on a conveyor belt and reading values while moving objects was passing by.

What I would like to achieve is to measure static objects in my 3D world, by moving my sensor. In other words, I want to mount this OD2000 sensor on a robot tool, and then when the tool of the robot move towards a given static object, I hope I could get the distance as read from RealSignal.

However right now I get the return value from sensor.ComponentSignal.Value to be equal to None.

The configured the RaycastSensor to have a range of 470 and a detection threshold of 70 mm. The block in the 3D world example is about 300 mm away from the sensorFrame.

The Python code is pretty simple, perhaps too simple?

from vcScript import *

comp = getComponent()
sensor = comp.findBehaviour("RaycastSensor")

def OnSignal( signal ):
  pass
  
def OnRun():
  app = getApplication()
  while app.Simulation.IsRunning == True:
    print "Reading of sensor values is:" 
    print sensor.ComponentSignal.Value
    delay(1)

Please check and correct me why my Ray Cast sensor do not work. Thanks in advance :slight_smile:
OD2000-2452T15.vcmx (243.6 KB)

Hello.
It looks like your DetectionThreshold value is too small, the MaxRange property value is for the range of the test distance, while the DetectionThreshold property value is for the range of the test component. :melting_face:

Hi @BAD. Thanks for pointing me in the right direction. However, when I have tried to set my DetectionThreshold to the same distance of the MaxRange, i.e. 420 mm, I now get an object printed in my output panel.

image

Is it not possible to read the distance, only by having code in my OnRun() function, or should I somehow make a trigger signal, such that the OnSignal(signal) function can output the distance?

from vcScript import *

comp = getComponent()
sensor = comp.findBehaviour("RaycastSensor")

def OnSignal( signal ):
  pass
  
def OnRun():
  app = getApplication()
  while app.Simulation.IsRunning == True:
    print "Reading of sensor values is:" 
    print sensor.ComponentSignal.Value
    delay(1)

I have updated the .VCMX file here
OD2000-2452T15 (1).vcmx (250.3 KB)

You get the distance from the Range Signal, like this:
sensor.RangeSignal.Value

1 Like

Thanks @Este. That solved my problem. Now the code is much more simple and nice :slight_smile:

from vcScript import *

comp = getComponent()
sensor = comp.findBehaviour("RaycastSensor")

def OnSignal( signal ):
  pass
  
def OnRun():
  app = getApplication()
  while app.Simulation.IsRunning == True:
    print sensor.RangeSignal.Value
    delay(0.1)

5 stars from here. Thanks a lot :slight_smile: