GraphWorX64 contains a powerful feature that detects the collision of two or more objects in a 3D view. The detected collision can trigger a variety of actions:
Log a TraceWorX message
Generate a GenEvent
Trigger a script
Change an object’s Color
These actions can be triggered either when the collision occurred (On collision start), and/or when the collision has finished (On collision end).
This topic covers the basic concepts of collision detection of two objects in a 3D view. It is a brief introduction to collision detection in GraphWorX64 that shows you how to set up your display to trigger a GenEvent. If at any point in this example you need additional information, refer to the topics about 3D in GraphWorX64, and the other available topics about collision detection. Note that in addition to this example, you can also combine the collision with triggering a script to pop up a message about the collision. For scripting capabilities, refer to the scripting topics, such as the Scripting - Quick Start topic.
GraphWorX64 does not need any special configuration in order to detect a collision. You create the objects in the 3D view and select the objects you want to be enabled for collision detection. As such, you can finish your display and then decide which objects to be used for detecting collisions. Or you can do collision detection whenever you like while creating your display.
In this example, you will use two simple primitive objects: a sphere (a ball) and a cube (a wall). When these two collide, both will change colors and generate a GenEvent, which will be listed in the AlarmWorX64 Viewer.
First, start GraphWorX64. Once loaded, a new display will be ready to work with. If you already had GraphWorX64 running, make sure that you create a new blank display.
Create a 3D view and under this view add an AlarmWorX64 viewer, as shown in Figure 1. For additional help, refer to the 3D Viewport Overview topic.
Figure 1 - Display with a 3D View and an AlarmworX64 Viewer
Double-click inside the 3D view. Notice that the ribbon changes. From the Primitives section on the ribbon's Home tab, select “Create a cube” and transform it into a wall like shape. Place it a little bit to the left so it is out of the center, as shown in Figure 2.
Figure 2 - Create a Wall out of a Cube
Now create a sphere. From the Primitives section select “Create a sphere”. Place the sphere a little bit to the right, so that you can clearly see it separately from the wall.
Figure 3 - Create a Sphere
Now you are going to let the sphere hit the wall using a simulated sine OPC Tag.
Select the sphere and then select “Location” animation from the Dynamics. For additional help, refer to the Add a 3D Location Dynamic and Set Properties topic.
Figure 4 - Location Dynamic
For the dynamic's DataSource, select “localsim:sine” from the Simulation tab inside the Data Browser.
Figure 5 - Select a Simulated OPC Tag
Notice that the animation is set to move into the positive X axis. In your case, you want the sphere to move toward the wall, to the left. Thus you need to adapt the animation to move toward negative X axis. The simplest way to do this is to change the coordinates in the 3D path, shown in Figure 6.
Figure 6 - Change the Path3D
NOTE: Depending on your regional settings, you might find the coordinates separated by semi colon ( ; ). When you change values in this field, the coordinates must be separated by commas ( , ). If you need fractions, use point ( . ) as a decimal separator.
Change the views so you can be sure the ball will hit the wall or go through it. For a quick check, use the View tools on the Home ribbon. For more information, refer to the View Section of the 3D Home Ribbon topic.
Figure 7 - View tools to quickly check our settings
To be sure you are on the right track, go into runtime and see the ball moving so that it collides with the wall. Modify the location of the ball or its location path as you wish.
Exit runtime.
If you did the runtime test, you will need to double-click inside the 3D view to continue editing.
Go to the Collision Detection section on the Workbench ribbon's Advanced tab. You can use these tools to include, exclude, or restrict objects for the collision detection. For more information, refer to the Collision Detection Section of the 3D Dynamics Ribbon topic.
Figure 8 - The Collision Detection tools
You can select each object and include it, or select several and then click Include.
Later you will take a closer look at the “Settings” tool.
Select the ball and the wall. To do this, click on the ball and then hold down the Shift key and click the wall.
Select “Include” from the Collision Detection tools.
Select the “Settings” tool. In the dialog that pops up you can see the two objects in the Registered Bodies list. If any is missing, repeat steps 1 and 2 selecting the missing object (either the ball or the wall).
Figure 9 - Collision Detection Settings
Either select the bodies you want to have included and click “Include”, or simply click “Include All” so the collision detection knows which pairs to monitor.
Figure 10 - Include Bodies to be Pairs
In the lower part of the dialog, you will define what will happen when the pair collides. In this case, you are going to change the color of both objects and generate a GenEvent. You want to trigger at collision start and collision end. When the objects collide, you want the color to change to red; and at the collision's end, you want the color to return to its original color.
Figure 11 - Define the Rules
Make sure the “Enable collision detection” option is checked. Then you can close the dialog.
Figure 12 - Enable collision detection & close
In order to see the events posted by the collision detection, you need to configure the AlarmWorX64 Viewer.
Double-click outside the 3D view to exit it.
Select the AlarmWorX64 viewer you added earlier. If you did not see one on your display, you can add it now. You will see the ribbon change accordingly. Either select “Configure Viewer” from the Workbench ribbon's AlarmWorX Configuration tab, or double-click on the viewer to bring up the configuration.
Figure 13 - Access the control configuration
In the Grid's Source tab, select “Event Subscription” as the source as shown below.
Figure 14 - Selecting the Event Subscription
Close the dialog.
Now is a perfect time to save your work. Next go into runtime and see what happens. You should see the ball move and collide with the wall. As soon as they collide, both objects turn red. And when the collision ends, they return to their original colors.
Figure 15 - Before Colliding
Figure 16 - Colliding
See in the AlarmWorX64 viewer the messages “Collision state set between Ball and Wall” and “Collision state cleared between Ball and Wall” alternate accordingly.
You can set up other scenarios for collisions, too. For example, you can add a new sphere and animate it to collide with the wall, but do not do anything when the balls collide with each other.
Try different settings in the Collision detection settings to become familiar with what it can do.
Figure 17 - Settings for More Pairs
Figure 18 - Balls Colliding from Top View
See Also:
Collision Detection TraceWorX Trace Log