Advanced Tutorial - Conveyor Belt
- 1 Project goal
- 2 Project overview
- 3 Step 1. Create a Kinematic Controller
- 4 Step 2. Add a Belt System to the Belt.
- 5 Step 3. Generate a belt circumference Spline with a Belt Renderer.
- 6 Step 4. Create a belt surface Spline.
- 7 Step 5. Generate a Loft Mesh with the Belt System.
- 8 Step 6. Add a DC Motor to the DriverRoll and assign its Wheel Joint to the Belt System.
- 9 Step 7. Create a Logic Simulator.
- 10 Step 8. Create a DC Motor Logic component and assign it to the Logic Simulator.
- 11 Step 9. Connect the Logic Simulator to the Twincat project and have Twincat control the DC motor.
To get started, first download the Tutorial Project
This is what you will learn to make in this tutorial
Project goal
The goal of this advanced tutorial is to rig a Conveyor Belt with a kinematic setup and control it using an external Twincat PLC.
Create a Kinematic Controller.
Add a Belt System to the Belt.
Generate a belt circumference Spline with a Belt Renderer.
Create a belt surface Spline.
Generate a Loft Mesh with the Belt System.
Add a DC Motor to the DriverRoll and assign its Wheel Joint to the Belt System.
Create a Logic Simulator.
Create a DC Motor Logic component and assign it to the Logic Simulator.
Connect the Logic Simulator to the Twincat project and have Twincat control the DC motor.
Project overview
The project consists of a predesigned model that has been optimized and correctly put into the Hierarchy. Textual reference has been added to each of the steps, please find these under the Conveyor Belt Tutorial. The textual reference is displayed in the Inspector.
You can find the correct scene in the Tutorial Project under
Assets > 2 - Advanced Tutorials > 2 - Conveyor Belt Tutorial > 1 - Exercise - Conveyor Belt Tutorial
3d-model of the conveyor belt (included with the tutorial)
Hierarchy setup
For reference, the finished setup has also been provided. Open the scene: 2 - Finished - Conveyor Belt Tutorial under Assets > 2 - Advanced Tutorials > 2 - Conveyor Belt Tutorial.
Step 1. Create a Kinematic Controller
If you want to use Kinematics, you will firstly need a https://unit040.atlassian.net/wiki/spaces/PUD/pages/280954380 .This component controls all Kinematic Transforms in the scene.
To create a Kinematics Controller, go to Mechanics > Add Kinematics
The Kinematics Controller will be automatically assigned to the selected GameObject, or when there is no GameObject selected, a new one will be automatically created.
For now, deselect everything and add a Kinematics Controller.
Make sure to place the Kinematic Controller above the parts you want to control, in this case the Conveyor Belt. Drag the Conveyor Belt onto the NEW_KINEMATICSCONTROLLER.
Step 2. Add a Belt System to the Belt.
To create a https://unit040.atlassian.net/wiki/spaces/PUD/pages/280953719 and assign it to a GameObject, select the GameObject and go to Standard Components > Belt System > Add Physical Component.
The Belt System requires a circumference Spline, a surface Spline and a Wheel Joint. The splines will be used to generate a Loft Mesh. The Wheel Joint will be used to determine the velocity with which objects will be moving over de Loft Mesh surface.
Step 3. Generate a belt circumference Spline with a Belt Renderer.
A Loft Mesh needs a circumference Spline and a surface Spline. We recommend you generating a circumference Spline for the Belt System using the V2020.1.56.3_ Belt Renderer .
First add the Belt Renderer to the Belt. To add the Belt Render, go to Standard Components > Belt System > Belt Renderer.
The Belt Renderer requires Belt Rolls to generate a Spline. For this Belt System setup, we need two Belt Rolls. We can use the Driver Roll and the Passive Roll as Belt Rolls. Add a https://unit040.atlassian.net/wiki/pages/createpage.action?spaceKey=PUD&title=Belt%20Roll&linkCreation=true&fromPageId=280987658 to both of these GameObjects.
When you create a Belt Roll it will try to find a https://unit040.atlassian.net/wiki/spaces/PUD/pages/281673729 on the same GameObject. If it cannot find one, it will automatically create one.
Set the axis direction for both Wheel Joints, on the Driver Roll and the Passive Roll, to Left. This way the Wheel Joints are orientated in the proper direction.
Next, set the radius of the both Wheel Joints so that they match the thickness of the Belt. In this case, we set the radius to 0.06 for both.
We can now assign the Belt Rolls to the Belt Renderer. If all Belt Rolls share the same Axis Direction and their Wheel Joints share the same plane, the Belt Render will automatically generate a Spline.
Drag the Driver Roll and the Passive Roll in the Belt Rolls list in the Belt Renderer.
A spline “GeneratedSpline” should now have automatically been generated. This spline will be the circumference spline for the Belt System. Rename it to “CircumferenceSpline” for clarity.
Step 4. Create a belt surface Spline.
To describe the surface of the Loft Mesh, we need to create a surface spline. To add a https://unit040.atlassian.net/wiki/pages/createpage.action?spaceKey=PUD&title=Spline&linkCreation=true&fromPageId=280987658 to the scene, go the Utilities > Create > Spline. Make sure you have no GameObjects selected while you do this so that the Spline will be created on a new GameObject.
Rename the new Spline to “SurfaceSpline” for clarity and parent it under the same GameObject as the Circumference Spline.
Next we need to position the Surface Spline properly. The Spline needs to be positioned on and perpendicular to the Circumference Spline. Use the https://unit040.atlassian.net/wiki/spaces/PUD/pages/281051436 to position the Spline on one of the Spline Control Points of the Circumference Spline. For this example we used Point[1] of the Circumference Spline.
In the Aligment Tool, select Surface Spline to be Part A. Select Point[1] of the Circumference Spline to be Part B. As the Alignment Tool Type, use Transform Pivot for both. For Affected Fields select Position and click Apply Alignments.
The first Spline Control Point is now in proper position. To set the second Spline Control Point in position, drag Point[2] to match the belt width.
Make sure Point[1] is on the Circumference spline and make sure that the Surface Spline has no rotation to it. Otherwise the Loft Mesh generation may go wrong.
Step 5. Generate a Loft Mesh with the Belt System.
The Belt System needs a Loft Mesh to transport objects. You can generate one in the Belt System.
To do so, assign the Circumference Spline and the Surface Spline.
Depending on your setup you can change additional setting to refine the generation. For this setup you only need to set the Circumference Max Length Deviation to 0.05. Then click Generate Surface. The Belt System will now start generating Guide Splines as a description for the Loft Mesh. This may take a few seconds, depending on you workstation.
The Guide Splines should now be visible in the scene. These give an indication of how the Loft Mesh will be generated. If the Splines did not generate in the right position, retrace your steps in this tutorial to check whether you have created the Splines in the exact same way.
If the guide splines are correctly generated, next thing is generating the Loft Mesh itself. For this setup, enable Invert Surface Normals. The normals of the Loft Mesh determine which side is the outside of the Loft Mesh. If you ever encounter objects falling through to top of the Loft Mesh, but remaining on the bottom, invert the Surface Normals and generate the Loft Mesh again.
To generate the Loft Mesh, click Generate Loft Mesh. Again, this may take a few seconds, depending on your workstation.
A Mesh Collider should now have been generated. Lastly, set the Mesh Collider to be Convex.
Step 6. Add a DC Motor to the DriverRoll and assign its Wheel Joint to the Belt System.
To transport objects over the belt, it needs a velocity. It determines its velocity through the rotation of a Wheel Joint. We need to add a https://unit040.atlassian.net/wiki/spaces/PUD/pages/280986424 to the DriverRoll to have the Wheel Joint rotate and move objects over the belt.
To add the DC Motor, select Driver Roll in the hierarchy and go to Standard Components > Motors > DC Motor > Add Physical Component.
This will add the DC motor to the Driver Roll object. Since there already was a Wheel Joint present on DriverRoll, the DC Motor will automatically assign that Wheel Joint to itself. Make sure check this in its Properties tab.
If you would like to check whether the DC Motor works, enter PlayMode. Then https://unit040.atlassian.net/wiki/spaces/PUD/pages/280855228 for the DC motor from its Control Panel tab. This will generate a new Control Panel on the same GameObject. Set the Preferred Velocity to any value except 0 and check whether Wheel Joint starts rotating.
After you have created the DC Motor, assign the Wheel Joint on DriverRoll as the Wheel Joint for the Belt System. For this setup we need to enable Invert Axis on the Belt System. This makes sure the belts velocity aligns with the rotation of the Wheel Joint.
Step 7. Create a Logic Simulator.
For a guide on how to install Beckhoff Twincat ADS, please watch this Twincat ADS Tutorial.
To be able to control the Conveyor Belt through an external controller, in this case a Twincat PLC, you will need to create a https://unit040.atlassian.net/wiki/pages/createpage.action?spaceKey=PUD&title=Logic%20Simulator&linkCreation=true&fromPageId=280987658 . A Logic Simulator will control each Logic component that is parented under it. To add a Logic Simulator, make sure that nothing is selected in the hierarchy and go to Logic > Add Logic Simulator. This will create a Logic Simulator on a new GameObject.
Step 8. Create a DC Motor Logic component and assign it to the Logic Simulator.
A DC Motor Logic component is a component that connects the physical DC Motor component to an external controller through the Logic Simulator. To create a DC Motor Logic component, make sure you have nothing selected in the hierarchy and go to Standard Components > Motors > DC Motor > Add Logic Component. Parent the newly create GameObject under the Logic Simulator.
To have the DC Motor Logic component connect the physical DC Motor, assign the physical component to the Logic component. In the Properties tab of the DC Motor Logic component, assign the Driver Roll as the DC Motor.
Then in the PLC settings tab of the DC Motor Logic, make sure you have the settings setup as in the image below.
These settings define how the external controller needs to address the Logic component.
Step 9. Connect the Logic Simulator to the Twincat project and have Twincat control the DC motor.
To have the Logic Simulator connect to an external controller, you need to have the proper settings. In this tutorial we will be connecting to a Twincat PLC. To successfully connect to the Twincat PLC, make sure to set the following settings:
Set the Adapter Target to TWINCAT_ADS.
Several adapter are available to connect to through the Logic Simulator. Each of them will have their own settings. We will be using TWINCAT_ADS.
Set the Simulator Name to BeltSystemTutorialSimulator.
The Simulator Name has to be same for all Logic Simulators on the same machine. This is used as an address by the external controller to find the Logic Simulator.
Set the XmlFilePath to BeltSystemTutorialAdapterSettings.xml
We will be exporting our configuration to an xml file. In this xml file the I/O will be defined for the external controller.
Set the Server Name to ConveyorBeltTutorialServer.
The Server Name has to be a unique name in the network. This is used as an address by the external controller to find the Logic Simulator.
Set the IP Address to you AMS NET Id.
You can find your AMS Net Id if you RMB click the system tray icon of Twincat and go to About TwinCAT. This will open a new window. Here you will find your AMD Net Id.
In the IP Address, a port also needs to be provided. The default port for Twincat is 851. Add a semicolon followed by the port to the IP Address. Make sure to use your own IP and not the one in these images.
Export the policy to XML.
To export the policy to an XML file, click Export Policy to XML. This will combine all setting into the XML file for the external controller. You can click Open Policy File to inspect the file and see if settings were exported as expected.
Not needed: Export Configuration Files
Usually you would need to export the Configuration Files. Since the Twincat project was already provided, you can skip this step. Just be sure that you have exactly followed all previous steps, otherwise settings may not match and error could occur.
If you have followed all these steps, everything should now be setup correctly.
To see if the connection was made with the external controller, go ahead and open the Twincat project. Log in to the PLC and run it. Then in Unity start Play Mode. If no errors occur, everything should setup correctly. You can now set a velocity for the DC Motor from the Twincat PLC using the ouput oPreferredVelocity. The DC Motor should now start to rotate and objects on the belt should start being transported over the belt surface.
Prespective Documentation