vsTASKER 7 Tutorial
×
Menu
Index

Simple Knowledge

 
For this example, we will create a simple Knowledge that will constraint the basic entity of the previous example to zero the speed and heading when conditions are met.
 
First, we need to create a Knowledge.
Select Knowledge in the Environment Tree-List then, in the Display diagram section, right click and select Add Knowledge
 
 
The Knowledge is created.
Double-click the Knowledge symbol (below) to Open it's definition.
 
 
Now, you can use the Knowledge toolbar to create visually the Knowledge.
In this case, we will create one Context including 2 Rules.
 
First, let's create the Context by double clicking the Knowledge Knw, then using the toolbar button before clicking on the Diagram background.
 
 
Double click the Context (above) then add two Rules by clicking two times the button.
 
 
Now, double click the first Rule representation on the diagram to define it:
 
 
Here, we specify that if the speed of the Entity is less than 5 m/s, then, the entity must stop (speed = 0).
 
After Fire, we restart the Rule to ensure it will be triggered again if needed.
 
Now, double click the second Rule representation on the diagram to define it:
 
 
In the second Rule, whenever the Entity heading is above |90| degrees, Entity is forced to go north (0).
After Fire, we restart the Rule to ensure it will be triggered again if needed.
Finally, let's make the Context cycle every 2 seconds.
 
 
 
The Knowledge must be attached to the Entity (Behavior) the same way as we did for the Logic. Both will run in parallel.
To do so, select the Entity (basic), then select Knowledge Pane in the Behavior.
 
 
Let's then add the new Knw created Knowledge
 
 
And that's it (we can rename the Knowledge Behavior if we want)
 
 
Time to Save then Compile and Generate the code.
Start the Simulation.
 
Observe that the Entity basic will start moving randomly (speed and direction) from the Logic control but see how, every two seconds, the Knowledge will modify both speed & direction according to the two basic rules.