- Artificial Intelligence
- Infrared Distance
- Third Party Robots
- Touch Tablet
- Ultrasonic Distance
- Virtual Reality
Google's DialogFlow (formally API.AI) is a free chatbot service which this plugin will use. Either manually enter conversational phrases into the input field, or send phrases programmatically using the provided ControlCommand(). This plugin requires an internet connection, which means your computer must be connected to both the robot and internet at the same time. Please consult the appropriate lessons in the learn section to configure your EZ-B to WiFi client mode or add a second USB WiFi adapter from here: http://www.ez-robot.com/Tutorials/Course/5
*Requires EZ-Builder 2019.12.06 or newer
Here is an example of a conversational ChatBot that you can configure with DialogFlow and incorporate other EZ-Builder plugins, such as cognitive services for Vision and Emotion detection...
Programmatically send phrases using the following ControlCommand() syntax...
ControlCommand("DialogFlow", Send, "Hello There")
The response from the server is stored in EZ-Script variables. Additionally, a script can be configured to execute when the server responds.
Some DialogFlow agents will return a list of parameters. The DialogFlow plugin implements 3 custom functions into the EZ-Script engine for obtaining parameters. The functions are...
Returns the number of parameters in the last response.
Usage: $x = APIGetParamCount()
APIGetParamByIndex( index )
Returns the parameter value at the specified index in the last response.
Usage: $Value = APIGetParamByIndex(2)
APIGetParamByKey( keyName )
Returns the parameter value by the key name. Look at the Agent or Variable Watcher to see what parameter key names are included in the response. The key names are case sensitive.
Usage: $Value = APIGetParamByKey("unit-to")
Here is an example of using the custom EZ-Script functions from the DialogFlow's Unit-Convert agent. If the input string is "What is 5mm into inches?", this EZ-Script code will show what the user is asking...
print("There are " + apigetparamcount() + " parameters in the response")
print("User is asking to convert " + APIGetParamByIndex(0) + APIGetParamByIndex(1) + " into " + APIGetParamByIndex(2))
1) Register with DialogFlow by visiting: https://dialogflow.com/
2) Paste your Client ID in this plugin's configuration window
*Note: Please consult DialogFlow's website for information on setting up a personal chatbot.
Example ChatBot - Create An Intent For Moving
Once you have some familiarity with creating a new Agent and adding the key to this plugin, we can walk you through how to create an intent. The verbiage used by AI bots is not clear from the beginning. However, once you understand what an Intent and Entity is, it begins to make sense.
The process that we will take in these steps will use text input to teach the bot by typing sentences around a specific action. In this case, we're going to teach the bot how to move a direction (forward or reverse) for a number of seconds. We'll do that by continually typing phrases into the Intent and the bot will create the necessary variables.
Load EZ-Builder and add two controls to your project. We'll add VARIABLE WATCHER and DialogFlow plugin. Because we'll be having the robot move FORWARD and REVERSE, you'll want to add these controls to an existing project so you can actually see the robot move. If you add it to a blank project, such as this example shows, you'll never have the robot actually move.
Load your Dialog Flow agent in a web browser
We're going to create a new Entity. An entity is essentially a variable that contains a bunch of synonyms. For example, you will see in the next few steps that we will create an identity called DIRECTION which will have two variables FORWARD and REVERSE, but a bunch of synonyms of each. This is how the AI magic understands what inputs people may provide that mean what you expect. So go ahead and create a new Entity.
Name this entity DIRECTION and create synonyms for each direction FORWARD and REVERSE as seen in the image below.
Now we will begin creating an Intent. This is done by pressing the + on the side menu next to INTENT.
Now begin adding phrases into the "User Says" box. This is the magic of AI, because the system will begin detecting the similarities of your statements and create an intent out of them. The sentences you enter must all be related to moving a direction (forward/reverse) for a number of seconds. See in this example the different entries I created. For best results, use the same entries that I did.
The seconds will now be detected as a time parameter, which normally would be a good thing. However, in this case we only want seconds. So we're going to edit the parameter and rename it to SECONDS and set the type to SYS.NUMBER.
Both parameters DIRECTION and SECONDS are required. So we'll need to set the checkbox for required on each parameter.
Now that the parameters are required, this is where the AI magic can have conversations with the user to get more information. For example, if you asked the robot to move Forward and didn't supply a number of seconds, the dialog prompt that we'll enter here will ask the user for how many seconds.
Here is the prompt for DIRECTION
Here is the prompt for SECONDS
Once all of the parameters have been provided to the bot during a conversation, the bot will respond. We can create our own response, which is friendly to the user. Here's an example response that uses the variables we created in the previous steps.
When the intent is successful and we wish EZ-Builder to do something, we need a way to identify what this intent is. The intent has an Action that is unique. In this case, we'll call the action move.direction.time
Save this Intent and we're done with the Dialog Flow editor and will return to EZ-Builder
Back in EZ-Builder, let's try out our Intent by typing MOVE and press ENTER in the DialogFlow plugin. Notice in the Variable Watcher that the $APIComplete variable is 0 (false). And, notice the Bot has asked us what direction to move? That is the bot executing the prompt we entered earlier because the parameter for direction is missing.
Respond with FORWARD and you will see the prompt now asking for how many seconds. The $APIComplete is still 0 (false).
Now enter a number of seconds. Notice the $APIComplete is now 1 (true) and the successful response is given.
The system now knows how to determine the direction and number of seconds to move. But, the robot doesn't know what to do with that yet. We will create a script that will execute the movement commands based on these parameters.
Click the CONFIG menu button on the DialogFlow plugin
Edit the SCRIPT
Finally, let's paste in some code that will be executed.
IF ($APIAction = "move.direction.time" && $APIComplete = true)
IF (APIGetParamByKey("direction") = "forward")
sleep(APIGetParamByKey("seconds") * 1000)