Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hat blocks for Scratch API #3

Open
davidjsherman opened this issue Mar 3, 2021 · 1 comment
Open

Hat blocks for Scratch API #3

davidjsherman opened this issue Mar 3, 2021 · 1 comment

Comments

@davidjsherman
Copy link

The current Scratch API requires an explicit busy loop, testing at a fixed cadence whether sensors have changed state to decide what commands to send to the robots. This doesn't agree with the Scratch event-driven paradigm and requires students to write unnatural programs. Since events are tested in order it also can create starvation, or require students to implement their own fair scheduler.

The Scratch API should provide hat blocks that trigger scripts when discrete events occur. These events could be:

  • Proximity sensor changes state
  • Proximity sensor detects color change
  • Camera detects an object by YOLO
  • Camera detects fiducial marker
  • Proximity sensor detects gesture
  • Message received over local are network

Implementing hat blocks using the Scratch Extension framework is not particularly well documented, but is not hard. There is a BlockType.HAT and there are examples for the Lego Boost in the official extensions:

Opcode whenColor:
https://github.com/LLK/scratch-vm/blob/f71f2b7fe2a5a0ff44f7bb53ef78beb2991314df/src/extensions/scratch3_boost/index.js#L1423-L1438

Implementation of the whenColor edge trigger:
https://github.com/LLK/scratch-vm/blob/f71f2b7fe2a5a0ff44f7bb53ef78beb2991314df/src/extensions/scratch3_boost/index.js#L2053-L2070

@davidjsherman
Copy link
Author

@ymollard Since this and #4 could apply to other Poppy robots, should the underlying issue be in poppy-project/pypot?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant