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.

    Thanks!



  • @rr,

    Does the documentation here help: https://wiki.anvelsim.com/3/index.php/Vehicle_Definition#Sensor_Definitions?

    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!

    Regards,
    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.

    Regards,
    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:

    <sensorDefinitions>
        <sensor name="SampleCameraTest4x4"
    		sensorType="CameraSensor"
    	        preview="CameraBig.png" 
    		objectAsset="CameraObject"
    		tags="ANVEL_Common"
    		sampleRate="30"
    		requires="rendering">
            <lens ImageWidth="640"
    		     ImageHeight="480"
    		     HorizontalFOV="80"
    		     VerticalFOV="60">
                <position x="0.0" y="0.0" z="0.0"/>
                <orientation w="1.0" x="0.0" y="0.0" z="0.0"/>
        </lens>
        </sensor>
    </sensorDefinitions>
    
    <sensor name="FrontCamera" parent="body" type="SampleCameraTest4x4">
    	<position x="1.0" y="0.0" z="4.0"/>
    </sensor>
    

    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:

    <body>
        <Components>
            <PythonScript>
                <property name="ScriptFile" value="TestSensorDisableScript.py"/>
            </PythonScript>
        </Components>
    </body>
    

    Then create the script in the same directory as the vehicle.xml. Within the TestSensorDisableScript.py, 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:
    		try:
    			Anvel.SetPropertyByName(key,"Enabled",False)
    			print("Enabled property set on objectKey "+ str(key))
    		except:
    			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.

    Regards,
    ANVEL Support