Calypso Module 4: Pursue and Consume
The Pursue and Consume Idiom"Pursue" means to chase something, e.g., "The police pursued the bankrobber". It can also mean to follow a path to a goal, as in "Mary is pursuing a degree in computer science". "Consume" means to ingest. For example, the average American "consumes" 250 eggs per year. It can also mean to use up, as in "fire consumed the wood pile". When something is consumed it no longer exists -- at least not in its original form. The Pursue and Consume idiom tells Cozmo to deal with a series of objects by visiting them one at a time and "consuming" them in some way. For example, suppose Cozmo sees some cubes that are glowing red, and the cubes are set to stop glowing when Cozmo picks them up. The program shown in the flash card below tells Cozmo to pursue each red cube and "consume" it by making it no longer pursuable. In this example Cozmo could do that by picking up the cube, which extinguishes the glow:
Which cube will Cozmo pursue first? (Hint: remember the First Law of Calypso.)
Trying out Pursue and ConsumeThis experiment can be done either with a real Cozmo or in simulator mode. But it's more fun to use Cozmo.
Color FiltersOur pursue rule is only interested in red cubes. This is called a color filter. The rule will ignore cubes of other colors, even if they're closer than the closest red one. Try it and see:
What Makes An Action "Consuming"?A consume action is anything that makes an object no longer pursuable. If Cozmo could actually eat a cube, or blow it up, or turn it invisible, then he would no longer see it, so he could not keep pursuing it. The pursue rule would then move on to the next closest cube. Since Cozmo can't eat or blow up cubes, the next best thing is to change the cube's color so that the pursue rule no longer pays attention to it. In the Pursue1 world he does this by grabbing the cube. The cubes in Pursue1 are programmed to stop glowing when they are picked up. We could also make Cozmo change the cube's color directly, but grabbing cubes is more fun. Challenge: Can you figure out how make Cozmo change the cube's color directly? (Changing it for him by clicking in the world map doesn't count.)
What Does "Bumped" Mean for Cozmo?The consume rule begins "WHEN bumped cube". For Cozmo, "bumped" means "got really close to"; he doesn't have to actually bump into the thing. Run the Pursue1 world and you will see that the consume rule is dimmed while Cozmo is approaching a cube; it only lights up when he's right on top of it, meaning he is "bumping" it. Cozmo can only grab a cube if he is close to it. If he tries to grab a cube that is too far away, the action fails and the DO part of the rule is dimmed. If Cozmo is bumping a cube, we know that he is close enough to grab it. Optional challenge task: What do you think will happen if we replace the Pursue and Consume rules with this one "impatient" rule?
Swapping the Rule OrderLet's switch to simulator mode, reload the Pursue1 world, and put the regular Pursue and Consume idiom back. When you run this program, Cozmo goes to the nearest red cube and picks it up (extinguishing it), then goes to the next nearest red cube, and so on. The pursue rule can always run, until there are no red cubes left. The consume rule is dimmed most of the time. When can this rule run? (Answer: it can only run when Cozmo is bumping a red cube.) If we swap the order of the two rules, we get this program:
What do you think this program will do? Let's try it:
The Second Law of CalypsoThe Consume-and-Pursue program behaves the same as the original Pursue-and-Consume version because of the Second Law of Calypso, which says that any rule that can run, will run:
A rule "can run" if its WHEN part is true. It doesn't matter what rules come before it or after it. When we say a rule "will run", we mean the action in its DO part will be attempted. The action could fail, as with the impatient rule that tried to grab a cube that was too far away. But the rule still ran. In the graphic above we see two versions of the same program: Consume-and-Pursue at the top, and Pursue-and-Consume on the bottom. Cozmo can see the red cube, so he can move toward it, but it's still pretty far away, so he is not bumping it. Thus, in both versions of the program the pursue rule is highlighted and the consume rule is dimmed. The two versions behave the same way. Does this mean rule order never matters? Not quite. There are situations where rule order does matter, which we'll get to in a later module. But for cases like Pursue and Consume, where the two rules have entirely different actions, the order is not important.
Review and DiscoveryDo the Module 4 Review and Discovery activity to review what you've learned.
Next ModuleIn the next module you'll learn how to make Cozmo talk, play sounds, and express emotions.
Back to Calypso Curriculum overview.
Copyright © 2017 Visionary Machines LLC.