Accessing Raycast sensor properties

How can the properties of the raycast sensor be accessed and changed? Like the UpdateScene, DetectionThreshold, DetectionContainer, UseSampling etc etc

Hey haroon,

i don’t have your exact sensor, but it should work as with any other component via comp.getProperty(“xxxxx”)

If you have your script in another component you have to find the component first via:

app = getApplication()
raycast_comp = app.findComponent("RaycastSensor") 
property = raycast_comp.getProperty("thisexactProperty")
property.Value = False

 

@haroon the image you attached shows vcBehaviour, which is the base class for a raycast sensor . A raycast does not have its own class but it does have behavior specific properties, which you can access and are documented in the vcBehaviour topic in API reference.

This lesson in Academy is about the sensor and the last part shows you where it is in Help.

http://academy.visualcomponents.com/lessons/model-raycast-sensor/

@Dubs3pp & @zesty … Thank you both
but I am actually using a function to have the raycast sensor rather than using it from the tool
So I need to access things like the UpdateScene, SampleTime etc
I am still confused in it to access those parameters
The code is the following

def shootRay(mtx):
    rayLen = 3000 #mm
    hit = app.rayCast(mtx, rayLen, comp) #comp argument excludes the component itself from test
    if not hit:
      # nothing detected within range of 1000mm
      L = 3500 # let's use negative value to represent no hit case
    else:
      # something found within range 
      hitmtx = hit[2] # 3rd argument is the target matrix of the raycast hit
      L = (mtx.P-hitmtx.P).length() #dist between the startpoint of ray to the hit position
    return L

 

Ahhh, you are casting a ray in the 3D scene. Yes, that will definitely impact the simulation performance when there are multiple rays cast, which you mentioned in a previous post. It is not a raycast sensor, so it doesn’t have those properties. You can, however, create a new class and implement those types of properties for casting rays.

Been a while since I tested the performance, but I would suggest implementing it in an application script/add-on where while the simulation is running, the ray is cast based on a sample time. This way, you could tweak the command file as needed without having to restart the main application.

Like Zesty said, the python method rayCast and the RaySensorBehaviour are not the same thing. The behaviour has an imbuilt logic doing the ray casting in a certain way that can be controlled with those properties and can be triggered by a signal. In python you can create similar logic and call the rayCast when needed.

In order to update the scene in python you can call

sim = getSimulation()
sim.update()

In order to control the sampling you can script it like this

while True:
  delay(0.5) #20Hz
  hit = app.rayCast(mtx, rayLen, comp)