Calypso Module 13: ActionIntroductionThere are four kinds of Calypso actions:
Instantaneous ActionsInstantaneous actions take just a fraction of a second. Examples include "glow" and score operations ("+score", "-score", and "set-score"). Instantaneous actions can succeed and complete immediately. We'll examine those concepts more closely in the next section. Instantaneous actions can also fail if they are overridden by an earlier rule's action. This is in accordance with the Third Law: when actions compete, the earliest wins. Currently "glow" is the only instantaneous action that can fail this way. Score operations do not compete, so they always succeed. Because instantaneous actions take negligible time, they do not offer an "and then..." modifier because it would have no effect. The next section discusses actions that do offer this modifier.Extended-Duration ActionsExtended-duration actions take a while to complete but have well-defined end points. Examples include "say" and "play", which can generate lengthy audio output, or head and lift motions such as "look up" or "lift neutral". These actions can be carried out while the robot does other things at the same time, meaning other rules on the page should have the opportunity to run. So we make a distinction between success and completion. Extended-duration actions such as "say" and "play" succeed as soon as the action begins, but they don't complete until the action is finished. This convention allows rules indented under an extended-duration action to run at the same time as the action itself. For example, the folowing rules cause the red score to be incremented at the start of the robot's speech. The program will also switch immediately to page 2, and the speech will continue while the rules on page 2 run.This example lighlights the fact that unlike incremental actions (e.g., "move towards"), extended-duration actions are launched with a single rule firing and then run until completion; they do not require repetition in order to keep going. Sometimes we want to wait for an extended-duration action to complete. For example, we may want the robot to finish speaking before it increments the red score and switches to the next page. Extended-duration actions accept an optional "and then..." modifier that delays the success of the action until it has completed. Therefore any indented rules, which according to the Fourth Law are dependent on the parent action's success, must wait until the parent completes. Here is what the code looks like:WHEN DO say "The word of the day is banana" WHEN DO +score red-score 1 point WHEN DO switch to page 2 In summary: an extended-duration action can succeed as soon as the action begins, allowing dependent rules below it to run right away. Adding an "and then..." modifier delays the success until the action completes. As a visual reminder that dependent (indented) rule firing will be delayed until the action completes, the action tile and the "and then..." tile are drawn with serrated edges. Now let's look at the interaction between extended-duration actions and instantatneous actions. How will the red and blue scores advance when we run this program? Note that it does not use the "and then..." modifier.WHEN DO say "The word of the day is banana" and then... WHEN DO +score red-score 1 point WHEN DO switch to page 2 The above rules will run many times per second. You can see the blue score run up quickly. On the first rule cycle the first rule will launch a "say" action, but on successive cycles this action will fail because the robot is already busy speaking and it can't say two things at once. Since the indented rule can run as soon as the parent rule succeeds, the red score is incremented right away, but it will not be incremented again until the parent "say" action completes and another "say" action is launched. Meanwhile the blue score continues to advance on each rule cycle, i.e., multiple times per second. What do you think would happen if we added an "and then..." modifier to the "say" action? Think about it before reading further.WHEN DO say "The word of the day is banana" WHEN DO +score red-score 1 point WHEN DO +score blue-score 1 point Answer: the change in behavior is a subtle one. Without the "and then..." modifier, the red score is incremented as soon as the "say" action launches. With the modifier, the red score isn't incremented until the "say" action completes. In both versions, the red score is incremented only once per "say" action, while the blue score is incremented on every rule cycle. There is another class of extended-duration actions: those that are not guaranteed to succeed. Examples include "move ahead 100 mm" and "turn left quarter". These actions can fail if the robot is picked up or its cliff detector is triggered before the motion is complete. Therefore these actions will not succeed until they complete. As a visual reminder of this, the actions automatically receive a small "and then..." modifier and are drawn with serrated edges. The program below increments the red score every time the robot advances by 50 mm. If the move action fails to complete for some reason, such as the robot being picked up, the red score will not be incremented. The small "and then..." modifier (not a separate tile) is added automatically and cannot be deleted.WHEN DO say "The word of the day is banana" and then... WHEN DO +score red-score 1 point WHEN DO +score blue-score 1 point WHEN DO move ahead 50 mm and then... WHEN DO +score red-score 1 point Suspending ActionsSuspending actions, such as "grab" and "drop", are complex behaviors that involve the entire robot. These actions can fail, so success is not assured until the action completes. Like extended-duration actions they are non-interruptible once launched. But because they require coordination between body positioning, head control, lift control, and sound output, they require execution of all other rules to be suspended while they run. Suspending actions are always displayed with serrated edges and a matching "and then..." modifier, indicating that indented rules will not run until the action succeeds. But with suspending actions, no other rules will run while the action is is being performed, even those that are not indented. The following program will run up the blue score at a high rate as long as there is no cube within reach; the "grab" action will fail on each rule cycle. When the robot becomes aware of a cube that it can grab, the "grab" action suspends rule execution while it runs, so the blue score stops advancing until the action either succeeds or fails. Note that this is only true when running on the real robot at present; "grab" in the simulator currently succeeds immediately. This may change in the future.WHEN DO grab and then... WHEN DO +score blue-score 1 point Incremental ActionsIncremental actions are the opposite of suspending actions: they take only a tiny step on each rule cycle, have no well-defined completion point, and do not suspend the rule interpreter. Examples include "move toward", "visit" "look around", and "move wander". Because they need an extended duration to have any noticeable effect, but take only a tiny step each time, they must be repeated over a lengthy sequence of rule cycles to accomplish anything.Incremental actions are intended to be interleaved with other rules, allowing the robot to continually evaluate its situation and modify the action or even abandon it in favor of another if circumstances change. For example, consider this classic pursue rule: The First Law tells us that the robot will move toward the closest cube. On each rule cycle it takes only a tiny step toward the cube. If we move another cube closer to the robot, its attention will shift to that cube and it will alter its course. If "move toward" were a suspending action the robot would not respond this way. (There is no way to force an incremental action to be suspending.) Incremental actions succeed after every step they take, allowing indented rules to run. But they never complete, so they do not accept an "and then..." modifier. Because incremental actions must be performed repeatedly, they can't work if they are dependent on a WHEN condition that is only true for an instant. Examples include "hear", "feel", and "timer". Rules of this form are automatically marked invalid, as shown below:WHEN see cube DO move toward it To achieve the deired result, the "visit" action should be moved to a separate page where it will not be dependent on the "hear" predicate. We can use a "switch to page" action to reach that page when the predicate is satisfied.WHEN hear "Cozmo go home" DO say "I'm going home" WHEN DO visit "home" PAGE 1: WHEN hear "Cozmo go home" DO say "I'm going home" WHEN DO switch to page 2 PAGE 2: WHEN DO visit "home" Next ModuleIn the next module you'll learn learn how logical operations are represented in Calypso.Back to Calypso Curriculum overview. Copyright © 2020 Visionary Machines LLC. |