This article illustrates how Speos and optiSLang can be used to analyse and validate cameras under different car configurations. For increasing the usability for non-simulation experts, we set up and publish the Ansys tools via webservice. The application is based on the camera standard: Federal Motor Vehicle Safety Standard (FMVSS) No. 111, Rear Visibility.
Software Prerequisites:
To be able to use this Example, the following tools and assets needs to be installed on your computer:
- Ansys Speos 2022 R2 or later
- Ansys optiSLang 2022 R2 or later
- optiSLang Speos Integration 22 R2.1 (Installer “optiSLang_Speos_22R2.1.exe” located in “.webapp_data\integration\”.
Overview
Today, most of automotive tier one suppliers and manufacturers are doing their camera placement thanks to some pre-parametrized models. In some situations, like camera placement studies, the process required a lot of iterations between several teams and leads to a huge number of manual operations.
To ease this iteration loop and reduce the human time spent on unnecessary operations, Ansys solution helps you to automatize this workflow and ease end user's life. This illustration helps to move actions from human time to machine time by handling input parameters in a lite optiSLang app interface and directly see the final behavior. This interface is accessible from every computer at any time (no need to have the full simulation software setup installed).
Step 1: Speos Set up
Set up a Speos model by importing a car geometry in a standardized test scene. Parametrize the workflow through a Python script.
Speos is, here, the solver. It means the front face Graphical User Interface (GUI) will not be used in the targeted workflow. As end-user is editing his model through a minimalist and customizable optisSLang app, there is no need for him to access directly to Speos GUI. Parametrized elements are embedded in a .py file which is directly driven by optiSLang. With this workflow, Speos can be installed on one computer dedicated to calculation with restricted access.
Step 2: Run optiSLang Web Application
Use the already generated web based application and learn how to publish a new workflow, with automated data transfer, as web application with registering all needed placeholders. Further customization is enabled through adjusting the Python scripts.
The background for publishing a workflow as web based application is, that in some situations, and for specific usage, restricting GUI to a limited amount of input parameters eases the process reproducibility and reduces the amount of human error. It also permits to standardize a workflow: two users with different skills, but same working environment can get the same quality level of results. Therefore, a workflow for automated data transfer has been set up, so that no manual interim work is necessary when starting the optical simulation.
Optional: Taking the model further
In this step we are explaining in a generic way on how to generate a basic optiSLang App from the example.
Run and results
Step 1: Speos Model
The following section is describing how Speos set up has been built. It is composed of three main parts:
- scene model
- cars model
- python script
The procedure is to simply import a car on a predefined position and then position it inside a predefined scene. Finally parameterize a camera sensor, feed a simulation and run the calculation.
Scene Setup
- Open the Ansys Speos model Scene_22R2.scdocx located at ".\speos_data\01_reference\"
- Make sure to not save any modification in the file
Speos set up is a typical Camera simulation scene. As we are looking for rear camera placement validation here, FMVSS111 NHTSA standard cylinders and grid had been placed on a concrete ground surrounded by a brick wall. A “STOP” surface is also position to visually control if the car is well placed or not.
Two texture images are placed on top of CAD geometries for a better-looking scene, but the behavior of simulated light rays is managed by spectral BSDF and BRDF files.
Light aspect is managed by an Environment source based on a HDRi Map and controlled by a luminance value and a spectrum.
Camera Sensor and Simulation
In this workflow, we have chosen to create an “empty” camera sensor. To keep model and update simple, we decided to not use any creation/suppression action. Of course, such kind of actions are perfectly feasible in a workflow like this.
The same idea has been applied to simulation. To run a Camera sensor, an empty Inverse Simulation is predefined in the scene model. Only Simulation options and simulations parameters (like number of passes) have been defined.
The rest of input data, required to correctly setup a Camera Sensor and an Inverse simulation, will be done through a Python script.
Cars model and their placement in the scene
- Open SUV_2022.scdocx located in ".\speos_data\01_reference\ANSYS_SUV\"
- Open Berline_2022.scdocx located in ".\speos_data\01_reference\ANSYS_Berline\"
- Review the added placement axis system position
- Close SUV_2022.scdocx and Berline_2022.scdocx
- Make sure to not save any modifications
Two car models can be used in this article: an SUV and a Berline one. These two cars are predefined with optical properties applied. Each car also has several axis systems with standardized names. The “placement axis system” is used to position car automatically at the right position and orientation in the scene. The second one is used to automatically place the camera sensor.
The scene also has its own placement axis system. This one has a driving dimension controlling its height position. SUV and Berline cars have a proper placement axis system placed at a certain height value from the ground. This is the value which is applied on scene axis system height. It allows to place the car correctly with the right orientation and the right height.
Automation script
- Run the batch-script “get_optical_automation_repo.bat” located in “.\Data\01_reference\” to download the Speos scripts from the Optical Automation GitHub.
- Open with Speos the script “camera_nhtsa_test.py” located in “.\speos_data\01_reference\repo_path\ansys_optical_automation\application\” with Speos
-
Uncomment line 4, 5 and 6.
import sys
repo_path=r"your repository location"
sys.path.append(repo_path) -
Add your repository location in line 5, e.g.
repo_path = r"E:\camera_webapp\speos_data\01_reference\repo_path"
- Make sure Scene_22R2.scdocx is still opened.
-
Run the script by clicking on Run button in Speos interpreter window
- Choose Camera Model, 1 or 2
- Select one of the two available car model e.g. ".\speos_data\01_reference\ANSYS_Berline\Berline_22R2.scdocx"
-
Enter the placement height of the car model in the scene
- Berline: 682.2 mm
- SUV: 546.123 mm
- wait for the script to finish
- Close .py script interpreter
- Check simulation result
- Close Speos
- Click “No” on saving message pop up, to Make sure to not save work done on scene_2022.scdocx or do a "save as" with a different name
The key point of this workflow is to execute a succession of actions automatically, with very limited manual operations for the user. To run all the actions automatically, we use a Python script.
It is doing these actions sequentially:
- Define the camera based on given parameters
- Select and import a car model
- Place at the given position car model in the scene
- Place camera model on given position
- Feed predefined simulation with scene geometries
- Run simulation
Step 2: Run optiSLang Web App
-
Please note all scripts of this section were done, assuming you have installed the software under the default path: “C:\Program Files\ANSYS Inc\v222\*". If this is not the case please reach out to your Ansys support to help you in adjusting it.
-
Edit the script file “camera_nhtsa_test.py” located in “.\speos_data\01_reference\repo_path\ansys_optical_automation\application\”
-
Adjust line 5 as follows:
repo_path = os.path.join(os.path.split(os.getcwd())[0], "01_reference", "repo_path")
- Create a zipfile of the "01_reference" located in " .\speos_data\" and name it 01_reference.zip
- Copy 01_reference.zip into the folder " .\webapp_data\custom_data\"
-
Copy the downloaded folder “Camera” into the optiSLang installation directory to access the content of the web application “Rear Visibility Standard Validation”:
For unified Ansys installer: C:\Program Files\ANSYS Inc\v222\optiSLang
For optiSLang installer: C:\Program Files\Dynardo\ANSYS optiSLang\2022 R2 - Run the “start_web_service.bat” in in the optiSLang installation directory as an admin.
- Login to http://localhost:8080/ and register for Webservice.
- Check if the application “Rear Visibility Standard Validation” appears in the list of wizards.
-
To start the simulation via browser you only have to browse for the transmittance file from
“.\webapp_data\custom_data\01_reference\SPEOS input files\”
, define the model parameters and give your project a proper name. Then click the play button to start the camera analysis.
- Check the analysis status during the run. After the Start you will automatically switch to the Projects tab. This may take up to 2 min.
- Select your project by clicking on the Project ID
- After the Completion (may take up to 10 minutes depending on your Hardware), the results will be displayed. You can download the camera simulations irradiance map as *.xmp and *.png file and the Speos Simulation Report (*.html).
-
Optional:
Open the “Camera.opf” located in “.\Camera\custom_data\”.
Double-click on each node to see the defined settings. For more details, please see description below. - Optional: To re-generate a web application for an adjusted workflow click “File” in “Camera.opf” and then “Saving the current project as…” – “Generate optiSLang App…”. The corresponding application directory is created in the before-mentioned installation directory. For more details, please see section "Taking the model further."
The workflow running in the background for the simulation is created in the optiSLang project file “Camera.opf” located in “.\Camera\custom_data\”. Open it and double-click on each node to see the defined settings. The workflow currently only performs simulation automation of the following steps:
Parametrization: In the parametrization part the input parameters, like camera type and car model, are defined. In this example, choosing between camera type 1 and 2 and SUV_22R2 and Berline_22R2 is enabled through definition in the main.py script. As parameters camera model number 1 (in line 26) and the SUV_22R2 (in line 34) are defined. |
|
Geometry Creation: In the second step a Batch Script node is used for geometry creation. The batch commands are defined within “Start_AnsysSPEOS_Geometry.bat” to copy the files to the correct location into the working directory. Afterwards, Speos application is started to run the “main.py” with predefined camera and car model. As result the Speos solver file “Cam_Sim.speos” is exported. In case of this node fails, please see section Troubleshooting . |
|
SpeosCore: The exported Speos solver file is solved from the SpeosCore node. Further information about how to set up the SpeosCore node can be found here . |
|
CleanUp: When the simulation has been successfully performed, as a result, the Speos Simulation Report (.html) and the cameras simulation as .png and .xmp file, are archived. Not required files are deleted to save disc space. |
Important model settings
Meshing
No particular need to have a detailed meshing for the scene. As it is relatively big, and mostly composed of flat surfaces, having a huge number of triangles doesn’t really make sense.
SUV car is a meshed body (coming from an .obj file). In this case, Speos meshing properties are not applied and Speos is using facets present in the obj.
Berline car is a NURBs body. Here, Speos mesh parameters are taken into account. As rear parts of the car can be viewed in a Camera simulation, a local meshing can be done on these geometries to get a better precision on the ray trace.
Geometry quality
As mentioned in the section just above, geometry can be managed in two ways: by mesh corps or by a NURBs geometry (conventional CAD file format: typically .step file). Ansys recommends, in general, to have a good geometry quality as input in Speos model. Speos raytracing is relaying on a surface triangular mesh. If, for any reason, the meshed corps has missing facets or overlapping ones; it can cause troubles on mesh generation. A bad meshing can lead to a consequent amount of error during simulation phase (an error is returned when a ray is considered as lost). Above 5% of error, it's better to understand error root cause and rework the model.
How to position car/ camera settings
Car position and Camera settings are, mostly, hard coded into the script for this example. It means, end user has no access to these parameters and only chose a pre-defined camera model and a distortion curve. Note that distortion curve can be provided by OpticStudio by using Export to Speos Lens System function .
The script main function is working with a principle of "mode". Three modes are defined into main function:
- Mode 0: is linked to an execution of the script into Speos (through script editor or script shortcut into Tools ribbon). Inputs are managed by input helper interface. This is the most direct way to execute the script.
- Mode 1: The script execution is also done into Speos but through a customized ribbon. This kind of ribbon is built through the built-in add-in API. It means .py script is called by the add-in and the inputs are also managed by it.
- Mode 2: This is the mode used in this example. The script is launched into batch mode following the previously described steps .
def main():
try:
argsDict
mode = 1
except Exception:
if len(args) == 0:
mode = 0
else:
mode = 2
For Mode 0 & 1, car position is given by the user. The value required is the vertical distance between the Car instance referent axis system and the scene floor. In the image below, we call this distance position_value .
Mode 2 is based on the same principle but the position_value value for SUV and Berline cars are directly hard coded into the script.
elif mode == 2:
repo_path = os.path.join(os.getcwd(), r"Reference\optical-automation-main")
sys.path.append(repo_path)
camera_model = 1
car_model = "SUV_22R2"
Ansys_SPEOS_file = os.path.join(os.getcwd(), "Scene_22R2.scdocx")
if "Berline_22R2" in car_model:
position_value = 682.2 # Berline =682.2mm
car_path = os.path.join(os.getcwd(), "ANSYS_Berline\Berline_22R2.scdocx")
if "SUV_22R2" in car_model:
position_value = 546.123 # SUV=546.123mm
car_path = os.path.join(os.getcwd(), "ANSYS_SUV\SUV_22R2.scdocx")
Camera model parameters are always hard coded for the three modes. These parameters are defined into a script function called prepare_sim_setup. This function fulfils a pre created Camera object is Scene model. It is called in the script main part.
Updating the model with your parameters
As explained in the section just above, .py script is working following 3 modes. Nevertheless, these 3 modes are relaying on the same mechanics for Car and Camera definition. If you want to add your own car, it's recommended to follow the same mechanics as described previously.
Add a new car
Car placement and import is driven by one function called import_car.
def import_car(path, position_value):
param = GetActiveWindow().Groups[0]
param.SetDimensionValue(MM(position_value))
name = "Placement_position"
target = Selection.CreateByNames(name).Filter[ICoordinateSystem]()
target.SetActive()
DocumentInsert.Execute(path)
If you want to respect the placement mechanics described into previous part, this function doesn't have to be changed. Car referent axis has also to be the .scdocx project World Origin. Also, make sure World Origin axis system is placed at the extreme point of rear bumper, like following.
The adding operation needs to be done into main by adding a new "if" condition like following:
elif mode == 2:
repo_path = os.path.join(os.getcwd(), r"Reference\optical-automation-main")
sys.path.append(repo_path)
camera_model = 1
car_model = "SUV_22R2"
Ansys_SPEOS_file = os.path.join(os.getcwd(), "Scene_22R2.scdocx")
if "New_Car" in car_model:
position_value = XXXX #Enter the position_value value corresponding to the car you want to add
car_path = "your_path\your_file.scdocx" #Enter your car file location path
Regarding file management, we recommend you keep your new car folder at same level as Scene.scdocx. Otherwise, car might not be well imported as script is looking for a file around its position. In addition, we recommend adjusting the batch script used to prepare the geometry to also copy your car part into the working directory.
Add a new camera model
Better option here is to duplicate an already-built cam_model definition into prepare_sim_setup function.
def prepare_sim_setup(cam_name, sim_name, part_names, cam_model):
name = "Cam_pos_1" # Axis system in Berline and in SUV
target = Selection.CreateByNames(name).Filter[ICoordinateSystem]()
Cam_1 = Camera(cam_name, SpeosSim, SpaceClaim)
if cam_model == 3: # Can be based on Camera model V1 or V2
parameters = [
XX, # focal length
XX, # Imager distance
XX, # F number
"your_file.OPTDistortion", # distortion file
"your_file.spectrum", # transmittance file
XXXX, # horizontal pixels
XXXX, # vertical pixels
XX, # width
XX, # height
[
"your_file_R.spectrum", # Red sensitivity spectrum
"your_file_G.spectrum", # Green sensitivity spectrum
"your_file_B.spectrum", # Blue sensitivity spectrum
],
]
define_camera(
Cam_1,
target,
parameters[0],
parameters[1],
parameters[2],
parameters[3],
parameters[4],
parameters[5],
parameters[6],
parameters[7],
parameters[8],
parameters[9],
)
Camera model "V2" means the distortion file is generated from OpticStudio side . In this situation, all parameters in the array become obsolete, except .OPTDistortion file.
Taking the model further
The previously described workflow only focuses on automation. If variation analysis should be performed, for example through Sensitivity Analysis with running a DoE or optimization to find the right camera model to pass the regulation, the corresponding systems have to be inserted to the *.opf. With creating the web application (*.owa), all included systems are transferred for solving them from web. Please be aware that individual adjustments need to be taken. In the following, you'll find a generalized description of how to create and publish a new application.
First step is to create a successfully running workflow.
Afterwards, to publish the optiSLang workflow as web application, the input parameters and the parameter manager needs to be defined as placeholders in the optiSLang project overview.
Furthermore, all input and output files need to be defined as registered files. In that way, they are directly archived to the optiSLang project and are unpacked when optiSLang is started from web service.
As a next step, run the “start_web_service.bat“ in the optiSLang installation directory
(for unified Ansys installer: C:\Program Files\ANSYS Inc\v222\optiSLang ; For optiSLang installer: C:\Program Files\Dynardo\ANSYS optiSLang\2022 R2)
as admin to start the webservice. This is only required once, becuase if the webservice is already running with admin rights, e.g., on a remote machine, every further user has access to web service.
If you don’t have any admin rights, copy the docroot and config.ini from the optiSLang installation directory to a location with admin rights. Set an environment variable named “CONFIG_FILE” to the path of the new location. For details check the
Help
. Then restart the Web Service.
Please note:
With the environment variable set to the new path, the wizard's files will not be located in the optiSLang installation directory, but in the folder the variable points to, e.g.
E:\username\web_service\docroot\wizards\Camera
Then you can generate the web application (*.owa) from inside the *.opd via “Saving the current project as…” and then “Generate optiSLang App…”.
Login to http://localhost:8080/ to access the webservice. To add the generated wizard to the list, click on the “Administration” tab. The tab is only visible for OWS-admins. Per default, this is the first person who starts the web service on the machine and logged in. This OWS account is automatically appointed as admin and is enabled to add standard users to admins.
In the Administration tab, go to wizards and add the *.owa. The corresponding application directory is created:
For unified Ansys installer: C:\Program Files\ANSYS Inc\v222\optiSLang\web_service\docroot\wizards
For optiSLang installer: C:\Program Files\Dynardo\ANSYS optiSLang\2022 R2\web_service\docroot\wizards
The generated Python files located in " .\webapp_data\custom_data\" can be adjusted as necessary to enable generating an individual web application wizard, e.g., with tables, defined font sizes and inserted pictures. Additionally, defining some further settings regarding running the project, etc. is enabled. You will find more information at the web service page in the wizards tab. The pyowa Overview gives documentation and playground for the pyowa module.
Troubleshooting
-
In case the GeometryCreation node fails, please check if:
- All reference folder names and directions are unchanged
- Ansys Speos 22R2 is installed at the default directory. In case the paths differ please contact your Ansys support .
- The “camera_nhtsa_test.py” is executed properly. If not, debugging the script would be the next step.
- Verify that lines 4-6, where adjusted correctly, please see Step 2
- For debugging purpose of the optical simulation add “args=[1]” in line 9 of “camera_nhtsa_test.py”.
-
In case the SpeosCore node fails, please check if:
- The installer “optiSLang_Speos_22R2.1.exe” located in “.\webapp_data\integration\” has been correctly executed. Recommendation is to install it to the default path. Restart optiSLang after the installation
- The SpeosCore path is set correctly. Further information about how to set up the SpeosCore node can be found here .
- A .speos file was generated in the “SPEOS isolated files” folder to be executed
Additional resources
Add link to video snippet
Related Ansys Learning Hub Courses:
- Connect | Ansys optiSLang - Ansys optiSLang Apps and Automation (sapjam.com)