Calypso Module 13: Action

Learning Goal: This module examines the different types of actions that Calypso provides and how they affect the sequencing of rules. We'll also examine the "and then..." modifier and the concepts of action "success" and action "completion".


Introduction

There are four kinds of Calypso actions:
  1. Instantaneous actions such as "glow" or "+score" take effect immediately.

  2. Extended-duration actions such as "say" or "play" take a while to complete, but do not hold things up unless we explicitly request this with an "and then..." modifier. Otherwise, other rules can run while these actions are doing their thing.

  3. Suspending actions such as "grab" or "drop" are complex behaviors that make use of the entire robot. They suspend the rule interpreter until the action either completes or fails. Suspending actions come with an automatic "and then..." modifier.

  4. Incremental actions such as "move toward" or "visit" are the opposite of suspending actions: they take only a tiny step on each rule cycle, so they must be performed repeatedly to make significant progress. While this is happening, other rules can also run, enabling the robot to react to new developments such as spotting an object it hadn't seen before. These rules might even cause the robot to stop pursuing the incremental action and instead begin some other behavior.

In the remainder of this module we examine the four action types in more detail, looking at how they interact with the Laws of Calypso and the related but distinct notions of action "success" and action "completion".

Instantaneous Actions

Instantaneous 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 Actions

Extended-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.

  WHEN DO say "The word of the day is banana"
      WHEN DO +score red-score 1 point
      WHEN DO switch to page 2

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" and then...
      WHEN DO +score red-score 1 point
      WHEN DO switch to page 2

In summary: ,amy extended-duration actions can succeed as soon as the action begins, allowing dependent rules below them to run. 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"
      WHEN DO +score red-score 1 point
  WHEN DO +score blue-score 1 point

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" and then...
      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 move ahead 50 mm and then...
      WHEN DO +score red-score 1 point

Suspending Actions

Suspending 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 Actions

Incremental 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:

  WHEN see cube DO move toward it

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 hear "Cozmo go home" DO say "I'm going home"
      WHEN DO visit "home"

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.

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 Module

In the next module you'll learn learn how logical operations are represented in Calypso.


Back to Calypso Curriculum overview.


Copyright © 2020 Visionary Machines LLC.