Tutorial

Create a first Digital Twin with a conveyor, a source and a sensor

In this short tutorial we are creating a small Digital Twin model with a source, a conveyor and a light barrier.

The needed 3D components are already available. If you would like to use own 3D data, you would need to import the 3D data from your CAD system using CADLink (included in realvirtual.io) or another suitable solution like for example Unitys PIXYZ.

Create a new scene

You should always create your models outside the realvirtual folder. This is because if you import a new Version of realvirtual.io, you would not like to destroy what you did. If you keep your scripts outside the realvirtual.io folder this will enable you to update your model with new releases of realvirtual.io without problems.

First create a new folder. We will call this folder Tutorial. Select assets and right click Create > Folder. Select the folder, hit F2 and name it to Tutorial.

For creating a new scene, select realvirtual > Create new realvirtual scene

After the scene is created, please save it with File > SaveAs in your Tutorial folder with the name tutorialmodel:

You should now have an empty scene with a base plate and some lights:

You can hide the big lights and camera gizmos by setting the Gizmo size to 0 (see above picture).

You could also create a totally empty standard Unity scene and add the realvirutal component(before 2022 game4automation component) by realvirtual> Add Object > realvirtual in the Main menu.

The realvirtual component provides some basic lights, mouse navigation in the deployed Digital Twin (Game view) as well as all standard settings and the standard Runtime UI.

Starting your first scene

You can now start your first scene by pressing on Play in the top of the Unity UI.

Game view will automatically open and you can see the RuntimeUI as well as an empty model with just the base plate:

Insert the conveyor

Next we insert a 3D component. For the tutorial we use a prepared one, which is already used by the demo model. Select the conveyor under Assets > realvirtual> 3DPfefabs > ConveyorSmall and drag it into the scene. Place it somewhere in the middle of the base plate.

You can move the conveyor with the gizmo, which is visible as long as the conveyor is selected. Or you put in 0,0,0 into the Transform Position property. This will place the zero point of the conveyor onto the world zero point (which should be also the middle of the base plate):

Unpacking the Prefab

The conveyor belt that you have inserted into the scene is what is called a prefab. A prefab is a type of template and can be a very simple or a very complex component. A Prefab can be used multiple times in one or more scenes. As long as the embedded instances of the prefabs are not "unpacked" in the scene, they are still associated with the Prefab and inherit any changes to the prefab itself. For more information on the Unity Prefab System, see the Unity documentation here: https://docs.unity3d.com/Manual/Prefabs.html.

For the Tutorial, we should Unpack the Prefab instance completely and cut all dependencies to the original Prefab. Please select ConveyorSmall in the scene and with the context menu select Prefab > Unpack Completely:

Delete realvirtual.io components from conveyor

This step is optional. The conveyor prefab is already equipped with some realvirtual.io components. But we would like to show you in this tutorial the full workflow. Like it would be without anything prepared - based on imported 3D objects.

This is why we are deleting the components and add them later on again. You could also skip this step if wished and continue with Insert a source.

Remove the component Drive on the object ConveyorSmall and also remove afterwards the Rigidboy on the object ConveyorSmall:

Next delete Transport Surface, Box Collider and Rigidboy on ConveyorSmall.Conveyor.Conveyor.

You learned how to remove scripts from objects ;-). You now removed everything what is prepared and we will add these needed scripts again in this tutorial.

Define the transport surface

We now have an empty 3D component. No kinematic and physical behavior is defined yet. This is what a component would look like after the CAD import. CAD systems do not contain any information other than the structure and geometry. This means that we have to define all mechatronic behaviors like drives and sensors in realvirtual.io.

Unfortunately, until now there is no standard format for exporting extended information from the CAD system. However, our Open Digital Twin Interface allows you to develop your own exporter for the CAD system.t.

First we need to add a Transport Surface to the conveyor. For doing that we select the component ConveyorSmall.Conveyor.Conveyor. We select in the main menu realvirtual> Add Script > Transport Surface or we drag and drop the script TransportSurface under Assets>game4automation onto ConveyorSmall.Conveyor.Conveyor.

A very easy way is, to use the QuickEdit for adding the TransportSurface:

The Quick Edit overly buttons can be opened by pushing F1 inside the scene view.

Insert a Drive

We now insert a Drive on the Conveyor. We place it on the same component as the TransportSurface before.

Select the ConveyorSmall.Conveyor.Conveyor component in your Scene and select in the main menu realvirtual> Add Script > Drive :

Alternatively you can also drag and drop the Drive Script under Assets > realvirtual> Drive onto the Inspector window of ConveyorSmall.Conveyor.Conveyor.

Or as before you can also use the QuickEdit Overlay Window.

And as a 3rd option you could also use Add Component on the Inspector window and than type in Drive and select the filtered script to assign it to the 3D component.

Your model should now look like this:

Please remember. Most times you can add scripts on 3D components in 4 ways

  • With the main menu

  • By dragging and dropping it from the Assets folder Assets>game4automation

  • by using Add Component in the Inspector window

  • or by using the QuickEdit overlay

Defining the transport direction and turning the Drive on

Next we define some properties of the Drive within the Inspector window. Please also check if the Direction is set to Linear X (so that the shown transport direction is forward).

Please check, that the TransportSurface is assigned to the Drive, which usually is done automatically. Set JogForward to True and TargetSpeed to 300.

This settings will automatically start the Drive when the simulation is starting.

Insert a source

A Source is automatically creating new components based on itself (what is called "spawning" in Unity).

Please select Assets > realvirtual> 3DPrefabs > Can and drag and drop it into the scene. Place the can at the beginning and on top of the conveyor.

Another way for creating the "standard" can source is to select the TransportSurface within the scene and to press INS on the keypoard.

Your model now looks like this:

Please move the source to the beginning of the conveyor.

Test the conveyor

Now we can test the conveyor. Start the simulation with the Unity Play button.

You might see that the texture on the conveyor is not moving in the right relation and the right direction. You need to set the texture scale yourself. Please select the TransportSurface and enter a -2 into property Texture Scale.

Insert a Sensor

As a last step we would like to place a Sensor (light beam) at the end of the conveyor.

Next select realvirtual > Add Componet > Add Sensor or select Sensor on the QuickEdit overlay.

Last but not least you need to move the Sensor GameObject to the end of the TransportSurface.

Your model now looks like this:

Now you can start again the simulation and you will see, that the Sensor is getting occupied (red):

Don't forget to save your model by selecting File > Save

Summary and what's next

This is just a first quick starter. Please check the Demo model and learn how the functions are realized. Also check the section Physics to learn more about the physics simulations, collision detection and kinematic movements. Based on that you should check the whole section Components & Scripts to learn more about the details.

© 2022 in2Sight GmbH https://realvirtual.io - All rights reserved. No part of this publication may be reproduced, distributed, or transmitted in any form or by any means, including printing, saving, photocopying, recording, or other electronic or mechanical methods, without the prior written permission of the publisher.

Last updated