Building Kinematics Model
Begin a new model by clicking the button on the toolbar. Click OK on the Model Units window, we will use the default units for our model.
If at any time you encounter difficulties while building this model, a fully functional tutorial model can be found at http://www.flexsim.com/tutorials
Part 1: Basic Kinematics
Step 1: Create the Objects
- Drag objects from your Library Icon Grid onto the 3D View to create the model shown below.
Connect all of the objects as shown:
- Connect Source1 to Queue2 to Conveyor4 to Processor3 to Conveyor5 to Sink6
Step 2: Add Kinematics Label
All kinematics need a unique node for the information to be stored. The simplest way to do this is by creating a text label dedicated to the kinematics.
Alternatively, a node could be added to the object's variables, in which case of all the label commands would be replaced with getvarnode.
- Open the properties window of the Processor.
- Go to the Labels tab.
- Add a text label by clicking the Add Text Label and rename the label "kin".
WARNING: Do not try to delete the kinematics node from within the properties window. Use the following instructions to change the parameters of your kinematic. Deleting it manually may crash the program.
Step 3: Add Custom Draw Code
The kinematics will need to be updated continually as the model runs.
- Go to the Triggers tab.
- Click the code edit button next to the Custom Draw trigger.
- Enter the following line of code:
updatekinematics(label(current, "kin"), current);
- Click OK to apply and close the code edit window.
Step 4: Update Kinematics when Process Finishes
The kinematics will need a final update at the time they should be complete. This will ensure that, regardless of the framerate of your 3D view (which defines how often the Custom Draw trigger fires), or whether you have any 3D views open at all, the kinematic will still be properly updated to its final resting position/rotation.
- In the Triggers Tab, click the code edit button next to the OnProcessFinish trigger.
- Copy the same updatekinematics command used in the Custom Draw trigger:
updatekinematics(label(current, "kin"), current);
- Click OK to apply and close the code edit window.
Step 5: Add OnReset Code
You want your object to return to its original position when you reset the model.
- In the Triggers tab, click the code edit button next to the OnReset trigger.
- Use the initkinematics command with the node being the text label you just created. Switch over to the General tab of the properties window and check the x, y, and z position and rotation of the object. Set the corresponding values in the initkinematics command. (The rotation values of your processor will be 0 by default.)
- Set the last two parameters to 0.
initkinematics(label(current, "kin"), x, y, z, 0, 0, 0, 0, 0);
Note: The last two parameters will indicate rotation management and local coordinates. When rotation management is set to 1, your object will rotate so the the "front" (the positive x-direction) of it is facing the direction of travel. If local coordinates is set to 1, it will use the coordinates of the object's container instead of the model itself.
- Click OK to apply and close the code edit window.
Step 6: Update Kinematics when Setup Finishes
You will also want your object to return to its original state at the start of the kinematic. We will now add the kinematic information that will move the object.
- In the Triggers tab, click the code edit button next to the OnSetupFinish trigger.
- Copy the initkinematics command with the same parameters as in the OnReset trigger.
- Enter the following line of code:
addkinematic(label(current, "kin"), 0, 0, 3240, 360, 90, 180, 0, 0, time(), 2);
The addkinematic command sets the x, y, and z parameters, to 0, 0, and 3240, respectively. This will be a rotational motion so it will rotate around the z axis 3240 degrees (9 turns). The target speed (or maximum speed) is set to 360 degrees/sec, with an acceleration of 90 degrees/sec/sec and deceleration of 180 degrees/sec/sec. The start speed and end speed are 0. The start time will be the time that the command is called, so we use the time() command. Last of all, we want this to be a rotational motion so we set the parameter to 2 or KINEMATIC_ROTATE (for translational motion we would set this to 1 or KINEMATIC_TRAVEL).
- Click OK to apply and close the properties window.
Reset and run the model and you should see the processor accelerate, spin and decelerate to a stop. You may notice that if the next flowitem starts being processed before your kinematic is done that it will instantaneously reset its position to match the initkinematics parameters. Our next step will be to match the process time with the time it takes for you kinematic to end.
Step 7: View the Kinematic Information
Important information about your kinematic will be stored in the "kin" label.
- Run the model until a flowitem enters the processor and stop the model. DO NOT reset.
- Right click on the Processor and click the Explore Tree button.
- Expand the processor tree, then expand the "labels" node within that tree. Click on the "kin" label and you will see the information for the kinematic as in the following figure:
- Scroll to the right until you can see the starttime and endtime. The difference between the two is the time it takes for the kinematic to complete. You should see a difference of 12 seconds.
- Open the Processor's properties window.
- Under the Processor tab, change the Process Time to 12.
- Optional: Adding a Setup Time of a second or two will allow our item to move out of the processor before the processor begins spinning again.
When you run the model now you should see that the processor finishes processing when it is done spinning. Kinematics lets you set up your simulation in terms of speeds and accelerations of your equipment as well as giving you the visual.
Kinematics can be used to do mutliple simultaneous movements to a single object. Try adding more addkinematics commands to the OnSetupFinish trigger.
Part 2: Update Kinematics Dynamically
In this part of the tutorial, we will have the processor spin at different speeds according to the item type.
Step 8: Create Multiple Itemtypes
- Open the properties window of the Source.
- Go to the Triggers tab.
- Click on the add button the next to the OnCreation trigger.
- Select the Set Itemtype and Color pick option.
- Leave the values as default.
- Click OK to apply and close the properties window.
Step 9: Process Each Itemtype Differently
Each item type will be processed at a different speed and therefore require a different process time. Since this will change dynamically as the model runs, we will make a number label to keep track of the information.
- Open the properties window of the Processor.
- Go to the Labels tab.
- Click Add Number Label and rename the label "proctime".
- Go to the Processor tab.
- Enter the following command into the Process Time field:
getlabel(current, "proctime")
Step 10: Create Dynamic Kinematics
We need to customize the kinematics so that it changes for each item type.
- Go to the Triggers tab.
- Click the code edit button for the OnSetupFinish trigger.
- Enter the following code:
initkinematics(label(current, "kin"), 13, 1, 0, 0, 0, 0, 0, 0); int z; int speed; int type = getitemtype(item); switch (type) { case 1: z = 1080; speed = 360; break; case 2: z = 3240; speed = 360; break; case 3: z = 3240; speed = 180; break; } addkinematic(label(current, "kin"), 0, 0, z, speed, 90, 180, 0, 0, time(), 2);
The initkinematics command should be the same as in Part 1. The addkinematics command is placed within an if statement that checks the item type for each item as the setup finishes. Try playing with the z-rotation value as well as the maxspeed, acceleration, and deceleration values of the processor.
Step 11: Update the Process Time
We will now get the kinematic information from our object and use it to change the processing time of the processor.
- While still in the custom code for the OnSetupFinish trigger, add the following code:
double endtime = getkinematics(label(current, "kin"), KINEMATIC_ENDTIME); double starttime = getkinematics(label(current, "kin"), KINEMATIC_STARTTIME); double proctime = endtime - starttime; setlabel(current, "proctime", proctime);
The getkinematics command gets information from the last update made to the kinematic. The available information that can be grabbed is described in the Kinematics section of the help manual.
If you have more than one kinematic at a time, you can set which kinematic it pulls information from, and even get information at specific distances or travel times in the middle of the kinematic action. See the manual for details.
- Click OK to apply and close the code edit window.
- Click OK to apply and close the properties window.
Reset and run your model. Your model should look similar to this:
This completes the Kinematics tutorial. Congratulations!