3D twin scene construction: simulation

The previous articles introduced how to use the NSDT editor to build 3D application scenes. This issue introduces one by one very important functions in the twin scene: simulation.

1. What is simulation

SimulationSimulation is a type of computer models and programs used to describe, analyze, and simulate real-world systems, processes, or events. Simulation generates a series of simulation results by inputting various parameters and conditions to help users understand the behavior of the system, evaluate the effect of the plan, and make predictions and decisions. Simulation can be applied in many fields, such as engineering, medicine, transportation, etc. Different from digital twins, simulation focuses more on the description, analysis, and prediction of system behavior and places less emphasis on real-time monitoring and optimized decision support.

2. The purpose of simulation

Simulation is used to predict the performance of new products, verify design solutions, optimize production processes, train personnel, etc. It can also be used for medical simulation, simulating surgical operations and disease propagation processes to provide better medical decision support. In the field of transportation, simulation can simulate urban traffic flow, optimize traffic light systems, and reduce traffic jams and emissions. In the aerospace field, simulation can be used to test the flight performance and safety of aircraft and optimize flight routes and resource allocation. In addition, simulation technology is also widely used in social and economic fields, such as simulating market competition, the impact of monetary policy, and the evaluation of the effectiveness of public policies. In summary, while digital twins focus more on the modeling and monitoring of physical entities, simulation technology is more widely used to simulate various systems and environments and provide support for decision-making.

3. How to implement simulation in NSDT editor

As a practical 3D scene editing tool, the NSDT editor of course also integrates simulation functions. Simulation supports two ways of accessing IoT device data: one is to manually set simulation data on the twin service platform; One is to directly call the http-related API interface to send IoT device data. Below we describe the two data access methods in detail.

3.1 New twins

Register a user account

Visit the NSDT.TWIN twin management platform and register a user account. The operation is as shown in the figure below:

Register account

Create a new twin

If you have registered account: test, password: test, log in to the NSDT.TWIN twin management platform and create a new twin. The operation is as shown in the figure below:

New twin

Special Instructions

Project name: Specify a meaningful namespace string, such as a company’s URL, com.ww.cn; or any meaningful string you want to give

Device name: The unique identifier string of the IoT device. It is very important. The data of the IoT device can be pushed based on this field in the future

Version: No need to fill in

Attributes (static): Describe some static attributes of IoT devices, key-value format strings, which can be customized, such as name: lmd001, place: Sangong District, etc.

Feature attribute (dynamic) – Feature key: describes some components on the IoT device, such as the gantry crane with crane and boom rope, which are named topcar, rope, etc.

Characteristic attributes (dynamic) – Feature parameter set: describes some physical parameters of a component on the IoT device, such as the horizontal distance between the gantry crane and the crane, and the lifting height of the boom rope. They are named horizontal_distance and rise_height respectively. The default value type is Numbers or decimals, default to 0.

After creating it, check the [Definition] column of the list, which is the thingId of the twin, which is com.ww.cn:lmd008

Twin list

3.2 Binding twins in the scene

Log in to the NSDT editor with a registered user account, switch to the specific scene, select the model to be connected to the data drive, switch to the [Model Information] tab in the lower right corner, and bind the parameters of the new twin to the model attributes, as shown in the figure below Show

Configure twin parameter mapping

Special instructions:

Select the twin you just created, such as “Gantry Crane No. 008”, and bind a parameter of one of its features to an attribute of the selected model to complete the binding. It should be noted that any characteristic parameter of any twin can be bound to any model attribute.

3.3 Methods of accessing IoT device data

Simulation (test use)

Select [Simulation] to enter the simulation page, as shown in the figure below

Simulation-Entrance

Switch to the [Simulation Configuration] tab and configure simulation-related parameters, as shown in the following figure:

Special Instructions

Frequency: Set the interval for sending data in seconds

Simulation mode:

–Full simulation: simulate all parameters of all characteristics of the twin

–Single feature: simulate all parameters of one feature of the twin

–Single physical quantity: a parameter that simulates one characteristic of the twin

Configuration:

–Fixed value: The generated parameter value is a fixed value.

–Interval random value: The maximum and minimum values need to be set, and parameter values are randomly generated between this range.

–Cyclic increment: It is necessary to set the maximum and minimum values and the minimum unit amount of increment. Within this range, according to the increment step, the parameter value is generated incrementally, and then the cycle repeats.

Simulation-Configuration

After configuring the simulation strategy, click Start Simulation and switch to [Message Log] to view the data received by the twin.

Simulation log and button

Directly call http related api interface to send IoT device data

This method requires some coding development.

Step 1: Call the [1.2.1.1, Obtain User Access Token] interface to obtain the token. There are two tokens, access_token and refresh_token. Access_token is used to call the API related to sending device data. It should be noted that the access_token token It will expire and is valid for one year. refresh_token is an offline refresh token and will not expire. Therefore, it is recommended that before the access_token token expires, or when the API for sending IoT device data is called and the request returns a 401 status code, you can use the [1.2.1.1, Obtain user access token] interface to pass in the refresh_token and exchange it for a new access_token. Token.

Step 2: Call the relevant API [1.2.2, Send device data]. We provide three interfaces for sending device data. Please choose an appropriate interface according to the data format of the IoT device you obtained, and pass in access_token to Request header, call the interface to send data.

For details, please refer to the reference document [Twin Management API Interface Description].

Calling SDK to send IoT device data

This method requires some coding development.

Step 1: Configure maven dependencies

org.eclipse.ditto ditto-client 3.1.1

Step 2: Instantiate and configure a new twin client

Add the configuration file src/main/resources/config.properties to the directory with the following content:

### Required configuration properties
namespace=com.ww.cn
endpoint=wss://twin.nsdt.cloud:8081/ws/2
### password credentials
clientId=TED
scopes=offline_access
tokenEndpoint=https://nsdt.cloud/auth/realms/nsdt/protocol/openid-connect/token
pwUsername=test ### Replace with your NSDT account and password
pwPassword=123 ### Replace with your NSDT account number and password

To configure the twin client instance:

  • Need to create instances of AuthenticationProvider and MessagingProvider
  • Create DisconnectedDittoClient instance
  • Get the DittoClient instance asynchronously by calling client.connect()
//Create AuthenticationProvider instance
 final AuthenticationProvider<WebSocket> authenticationProvider = AuthenticationProviders.accessToken(
 AccessTokenAuthenticationConfiguration.newBuilder()
 // getJsonWebToken() is a method to obtain jwt token, see demo code for details
         .accessTokenSupplier(() -> getJsonWebToken())
         .identifier("ditto")
         .expiryGracePeriod(DEFAULT_EXPIRY_GRACE_PERIOD);
 );
 
 //Create an instance of MessagingProvider
 final MessagingConfiguration.Builder messagingConfigurationBuilder =
     WebSocketMessagingConfiguration.newBuilder()
         .jsonSchemaVersion(JsonSchemaVersion.V_2)
         .reconnectEnabled(false)
         // tokenEndpoint in config.properties
         .endpoint(CONFIG_PROPERTIES.getEndpointOrThrow())
 ;
 final MessagingProvider messagingProvider =
     MessagingProviders.webSocket(messagingConfigurationBuilder.build(), authenticationProvider);
 
 // Create DisconnectedDittoClient instance
 DisconnectedDittoClient disconnectedDittoClient = DittoClients.newInstance(messagingProvider);
 
 //Create twin client
 DittoClient client = disconnectedDittoClient.connect().toCompletableFuture().get(10, TimeUnit.SECONDS);

Step 3: Use client to send IoT device data to the Twin platform. Refer to the main function in the example SendTwinDataDemo.java file. There are three ways to send data:

// Demonstrates sending all feature data to the specified twin updateFeatures(); // Demonstrates sending data of all parameters of a feature to the specified twin updateFeature(); // Demonstrates sending data of one parameter of a feature to the specified twin updateFeatureProperty();

For the above details, please refer to the reference document [Twin Management API Interface Description], java-sdk uses the demo download link java-sdk-demo

3.4 Browse model-driven effects

Browse effect 1

Browsing effect 1-2

Browse effect 2

You can see that the gantry crane model is constantly moving, and the model attribute [Position-X] data has changed significantly.

Original link: 3D twin scene construction: simulation (mvrlink.com)