This program uses LEGO MindStorms EV3 robot a letter scanner. It will:
Serialization of rules
First, it loads a text file containing IF THEN rules. The syntax of the rules is:
(0,0), (0,1), (1,0), (2,0), (2,1) -> C
(5,2), (4,3), C -> G
where (0,0) refers to the grid coordinates of the pixels scanned by the robot. Note that:
The coordinates on the LHS may not be listed in any sorted order in the text file.
The letters in the rules may not be single-character, e.g., if we use the Greek character set, the letters may be alpha, beta, etc.
(0,0) refers to the top left of the pixel grid.
AI algorithms
It offers the user the option to do forward reasoning or backward reasoning:
i. Forward Reasoning:
i. It compiles the rules into a binary decision tree, wherein, each node is a pixel, and its two children represent the pixel being on or off.
ii. It scans the pixels in an order determined by you: row-major - this will the same order used for the binary decision tree.
iii. After reaching each new pixel, it prints all the remaining candidates as per the decision tree, e.g., after finding that pixel (0,0) is off, the remaining candidates may be only A or I.
iv. It traverses the decision tree and print all the deductions, e.g., in the above example, not only that the scanned pixels ultimately represent G (a leaf node in your decision tree), but en-route, some subset also represents C (an intermediate node in the decision tree).
v. If the scanned pixels are not an exact match to any character in the rule base, it prints the possible candidates - these are the leaf nodes in the subtree whose root is the intermediate node where the reasoning ends.
ii. Backward Reasoning:
i. It asks the user for the character that should be recognized.
ii. It scans only the pixels on the LHS of the rule for that character. (This could mean, considering additional rules, e.g., to recognize G, it should also consider the rule for C above).
iii. The moment a pixel expected to be on is found to be off, it immediatelys report that the character was not found, and stop.
Robot behaviour
Calibration:
If this choice is selected, the robot cycles through the following three inputs:
i. Read the ON color - you place the robot on an on strip, it reads the light sensor and saves the value
ii. Read the OFF color - you place the robot on an off strip, it reads the light sensor and saves the value
iii. Read the pixel size - you place your robot just before the pixel. It reads the distance traveled between two transitions: off-to-on and on-back-to-off. This is the size of a pixel (assumed to be square).
Scan:
If this choice is selected, the robot offers two options:
Forward Reasoning:
It scans the pixel grid in row major order. It emits three different sound patterns (with accompanying display behaviors):
A sound every time it reads a pixel, on or off. On the screen, it displays the coordinates of the pixel it thinks it is scanning (e.g., 2 3), followed by the remaining candidates as per the decision tree;
A sound pattern when it successfully identifies a letter in its rule base. On the screen, it displays its deductions, i.e., all the letters represented by the pixel pattern and sub-patterns, if any;
A sound pattern if it fails to find any letter in its rule base. On the screen, it displays the possible candidates.
Backward Reasoning:
i. It displays the letters for which rules are provided in the rule base;
ii. It lets the user select the target letter using one of its buttons;
iii. It then proceeds to scan. It emits three sound patterns with accompanying display behaviors as follows:
A sound every time it reads a pixel, on or off. On the screen, it displays the coordinates of the pixel it thinks it is scanning (e.g., 2 3).
A sound pattern when it successfully identifies a letter in its rule base. On the screen, it displays success.
A sound pattern if it finds a pixel to be off that should be on. On the screen, it displays failure.