Community Forum
ANVEL Licensing Options

Set sensor properties in vehicle definition file

  • Hi!
    Wondering if it's possible to set a sensor's property in the vehicle definition file. Specifically, interested in setting Enabled=False so that when the vehicle is instantiated, the sensor is disabled by default.


  • @rr,

    Does the documentation here help:

    This will allow you to actually create a new sensor definition that you can tweak to match your vehicle's configuration.

    Let us know how it goes!

    ANVEL Support

  • It looks like in the vehicle definition file you can only set sensor position and orientation, but not any other properties... Is this true?

  • @rr,

    You should be able to set up what is essentially a new sensor definition in the vehicle definition. If that's not working, let us know.

    ANVEL Support

  • I was not able to get it to work. Do you mind posting an example where you define a sensor within a vehicle definition file and then set its Enabled property to false? Thanks!

  • @rr,

    I just prototyped this out; hopefully the following helps! The following XML snippet in a vehicle definition file will add a new camera sensor definition and an instance of that camera to the vehicle:

        <sensor name="SampleCameraTest4x4"
            <lens ImageWidth="640"
                <position x="0.0" y="0.0" z="0.0"/>
                <orientation w="1.0" x="0.0" y="0.0" z="0.0"/>
    <sensor name="FrontCamera" parent="body" type="SampleCameraTest4x4">
    	<position x="1.0" y="0.0" z="4.0"/>

    The second part of your request is more tricky because you can't set the Enabled property through the XML definition right now. To do so, we recommend using a Python script component that will run when the vehicle is instantiated. If you add the following XML to your vehicle.xml's <body> tag, it will add a Python script component to your vehicle:

                <property name="ScriptFile" value=""/>

    Then create the script in the same directory as the vehicle.xml. Within the, add the following content, which will attempt to set the Enabled property to False on all sensors in the simulation:

    import Anvel
    import Anvel.Scripting
    sensors = Anvel.GetIdsByTypeName("Sensor")
    for sensor in sensors:
    	sensorInfo = Anvel.AnvelApi.GetObjectInfo(sensor)
    	keys = sensorInfo.InheritedObjectKeys
    	for key in keys:
    			print("Enabled property set on objectKey "+ str(key))
    			continue #handle exceptions thrown if the sensor component doens't have the Enabled property

    Of course, this is very crude. You could also run an External API script to set the property as well.

    ANVEL Support