Skip to content

2.7 CAIT Visual Programming Block References

michaelhwn edited this page Jan 30, 2021 · 3 revisions

CAIT Block References

Basic Blocks

Description: This block performs the initialization of A.I. components. Every program needs to have a "setup" block. It corresponds to the "setup" function in the converted Python code.
Usage: This block is usually placed above the "main" block.


Description: Main event loop. All program logic goes within this block.
Usage: Must be placed after a setup block.


Data Structure Blocks

Description: Create an empty Dictionary.
Usage: Can only be used in the main block.
Example:


Description: Adds a key-value pair into an existing dictionary.
Usage: Can only be used in the main block.
Example:


Description: Get a list of keys of an existing dictionary.
Usage: Can only be used in the main block.
Example:


Description: Get the value of a key in an existing dictionary.
Usage: Can only be used in the main block. Returns None if the key does not exist in the dictionary.
Example:


Description: Set the value of a key in an existing dictionary.
Usage: Can only be used in the main block. A new key-value pair is inserted into the dictionary if the key does not exist.
Example:


Description: Remove a key-value pair from an existing dictionary.
Usage: Can only be used in the main block. Performs nothing if the key does not exist.
Example:


A.I. Blocks

Description: Initialize the vision module, must call before using any other vision blocks.
Usage: Can only be used in a setup block.
Example:


Description: Detect and recognize the largest face in the scene.
Usage: Can only be used in the main block. The result is returned in the form of a dictionary. It can then be used with dictionary blocks.
Return Data Example: {"name" : "Michael", "coordinate": [0, 0, 10, 10]}.
Example:


Description: Add a new face to the face recognition database.
Usage: Can only be used in the main block. The added face can be recognized with the Recognize Face block afterward.
Example:


Description: Remove an existing face from the face recognition database.
Usage: Can only be used in the main block. The person with the removed face becomes Unknown after calling the Face Recognize block.
Example:


Description: Detect objects in the scene return a list of detected objects and their coordinates.
Usage: Can only be used in the main block. The result is returned in the form of a combination of dictionary and list. It can then be used with the dictionary and list blocks.
Return Data Example: {"name" : ["tv", "cellphone", "mouse"], "coordinate": [[0, 0, 10, 10], [10, 10, 120, 120], [20, 20, 40, 40], [30, 30, 70, 70]]}.
Example:


Description: Classify the current scene, returns the top 5 possible classes with corresponding confidences.
Usage: Can only be used in the main block. The result is returned in the form of a combination of dictionary and list. It can then be used with the dictionary and list blocks.
Return Data Example: {"names" : [["cellphone", 0.799], ["iPod", 0.088], ["remote control", 0.0034], ["water bottle", 0.0022], ["Band Aid", 0.0015]}.
Example:


Description: Initialize the speech module, must call before using any other speech blocks.
Usage: Can only be used in a setup block. Use can choose to use online or on-device mode. If using online mode, a google cloud account must be associated with the system. The language option is only available in online mode.
Example:


Description: Listen for the user's speech through a microphone, then converts the speech to text.
Usage: Can only be used in the main block. The result is returned as a string.
Return Data Example: "Hi, nice to meet you".
Example:


Description: Takes in a text and generates voice from it.
Usage: Can only be used in the main block.
Example:


Description: Initialize the NLP module, must call before using any other NLP blocks.
Usage: Can only be used in a setup block. Users can choose to use different models trained on their own. Model training can be done by using the train_nlu_model.sh from the utils folder.
Example:


Description: Takes in a text and analyze the user intention. It will also extract entity information from the text.
Usage: Can only be used in the main block. The result is returned in the form of a combination of dictionary and list. It can then be used with the dictionary and list blocks.
Return Data Example: {"confidence": 0.99, "entities": [{"entity_name": "person", "entity_value": "Michael"}], "topic": "user_give_name"}.
Example:


Description: Initialize the control module, must call before using any other control blocks.
Usage: Can only be used in a setup block. The user needs to place add hub blocks inside this block to initialize the LEGO Hub(s) they need. Example:


Description: Add a LEGO Hub to the initialize control block to enable control to this hub. Usage: Can only be used in a setup block. Must be used inside initialize control block.


Description: On a selected LEGO Hub, rotate a motor at a certain speed for some seconds.
Usage: Can only be used in the main block. The user needs to select a hub to control this motor. Either an ev3_motor block or a robot_inventor_motor block is required to indicate which motor to control. Speed can range from -100 to 100, with the negative sign being the direction of the rotation. Seconds can be 0 to inf.
Example:


Description: On a selected LEGO Hub, rotate a motor for a certain degree.
Usage: Can only be used in the main block. The user needs to select a hub to control this motor. Either an ev3_motor block or a robot_inventor_motor block is required to indicate which motor to control. The degree can range from -inf to inf, with the negative sign being the rotation direction.
Example:


Description: EV3 motor block. Usage: Can only be used in a motor control block.


Description: Robot Inventor motor block. Usage: Can only be used in a motor control block.


Description: Rotate a set of motors at a certain speed for some seconds simultaneously.
Usage: Can only be used in the main block. Users can choose to insert up to 4 motor speed blocks under this block for their robot build. Speed can range from -100 to 100, with the negative sign being the direction of the rotation. Seconds can be 0 to inf.
Example:


Description: Initialize the smart home module, must call before using any other smart home blocks.
Usage: Can only be used in a setup block. Example:


Description: Control a smart light device.
Usage: Can only be used in the main block. Users need to set up and integrate their smart light devices first through the Home Assistant Webapp located at port 8123. After that, they can choose which smart light device to control. Currently, CAIT supports the following control action: Turn On, Turn Off, Toggle, Change Colour, Set Brightness.
Example:


Description: Control a smart speaker device.
Usage: Can only be used in the main block. Users need to set up and integrate their smart speaker devices first through the Home Assistant Webapp located at port 8123. After that, they can choose which smart speaker device to control. Currently, CAIT supports the following control action: Play Music, Pause Music, Volume Up, Volume Down.
Example: