Coder Social home page Coder Social logo

maxosprojects / cozmo-blockly Goto Github PK

View Code? Open in Web Editor NEW
43.0 6.0 23.0 20.69 MB

Cozmo Programming with Blockly

License: MIT License

JavaScript 92.11% CSS 0.58% Python 0.67% HTML 6.58% Emacs Lisp 0.01% Shell 0.04% Batchfile 0.01%
cozmo cozmo-sdk blockly programming learn-to-code

cozmo-blockly's Introduction

Cozmo Programming with Blockly

Check out the gallery

Features

All programming constructs are available to teach/learn basics of programming. 3D live visualization makes it a little more interesting. Cube rendering as any character (currently Minecraft mobs are supported) bumps interest even more. Physical interaction with objects and watching live how it is reflected in Cozmo's world should be even more engaging.

Currently with Cozmo you can do:

  • basic actions (drive, turn, speak), the list will be extended with time
  • "drive to coordinate" action
  • add static objects (Cozmo will drive around them on "drive to coordinate" action)
  • some animations
  • cube tap events
  • "cube been seen" condition
  • "cube is visible" condition
  • "distance to cube" statement for math or logical operators
  • turning towards a cube
  • setting lift height
  • setting head angle
  • picking up cubes
  • placing cubes on the ground or on another cube
  • enable "free will"

Improved security compared to Cozmo ScratchX extension:

  • everything runs on your computer without third-party servers or scripts
  • programs you save reside on your computer and have no links to third-party scripts in them - just plain Blockly XML programs

Some other features:

  • can be rendered in a mobile browser and supports touch interaction (tested in iOS 10.2)
  • 3D visualization of Cozmo and his environment - works in a desktop or mobile browser (tested in iOS 10.2)
  • 3D visualization supports Anaglyph rendering - just toggle it and put on the red-cyan glasses and you're there, with Cozmo
  • cubes in 3D visualization can be replaced with Minecraft mobs (and a couple of skins are available, see examples)
  • static objects can be added (e.g. a wall) both to 3D visualization and to Cozmo world (Cozmo then plans path around it on "drive to coordinate" action)
  • maze can be generated (each "maze" block generates maze only once and the maze is persisted with the program so the student can build a program to guide Cozmo through the maze)
  • 3D visualization hides cubes that have not been observed since program start and makes cubes not visible at the moment semi-transparent
  • view camera in the same browser tab (just another blockly tab) - available only when program is running
  • program blocks (statements) are highlighted when being executed
  • view your program translated into Python or XML AST

How to run

  1. Check out this repository with "git", or download it as a zip archive and unpack
  2. Install prerequisites:
    • pip3 install --user cozmo[camera]
    • pip3 install --user tornado ws4py
    • it is highly recommended to install Node.js as described in Security considerations section
  3. Go to server folder
  4. Start the server: python3 server.py (additionally, -n <the future programmer's name> can be supplied to set the default filename when saving/reloading programs - convenient on mobile devices)
  5. Point your browser to http://localhost:9090/cozmo/
  6. Build your program and run with the red play button in the top-right corner

If your program hangs, or you just want to stop it, click the stop button.

The last executed program will be stored in .last file for you to be able to reload it. You can also save any program with any other name and load any previously saved programs.

Security considerations

There are two modes of code execution: secure and non-secure.

secure mode requires installation of Node.js. In that mode the code you create with Blockly and execute with the play button is sent as Blockly XML AST to the server and there translated to an actual Python code and executed.

After you download and install NodeJS go to the nodejs folder and run npm install. That would install all the modules that are required for that additional service.

non-secure mode doesn't require Node.js. In that mode your program is traslated into Python code and is sent to the server for execution. This mode is intended for contained environments (e.g. in a home network). The risk here is that the server accepts arbitrary code from the network for execution. If you are not sure your local home network is secure, or if you're planning to let people with potentially malicious intentions program your Cozmo, or you're running server.py not in your local home network, it is highly recommended to run server.py in secure mode.

By default server.py runs in secure mode. To run it in non-secure mode use --nonsecure command argument.

Developing

There are two Javascript versions: compressed and uncompressed. Compressed version is compiled with google's closure library, is minified and obfuscated. Uncompressed version is debuggable.

To run uncompressed version: python3 server.py -d which enables debug mode. You may encounter some caching issues. If so, restart server.py

Issues

Any issues? Report an issue above.

Used by

MEGAkid: Learn to Code the Cozmo Robot! Beginners: Ages 6-12

cozmo-blockly's People

Contributors

maxosprojects avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

cozmo-blockly's Issues

Bad file descriptor

the project is great!

when I upgrated my app (2.0.2), I can't use the project ๐Ÿ˜ญ

image

I get following error when I try to run it

[Server] Starting server...
Traceback (most recent call last):
File "server.py", line 234, in
main()
File "server.py", line 231, in main
CozmoBlockly.start(args)
File "server.py", line 199, in start
tornado.platform.asyncio.AsyncIOMainLoop().install()
AttributeError: module 'tornado.platform' has no attribute 'asyncio'
internal/modules/cjs/loader.js:596
throw err;
^

Error: Cannot find module 'xmldom'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15)
at Function.Module._load (internal/modules/cjs/loader.js:520:25)
at Module.require (internal/modules/cjs/loader.js:650:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object. (/Users/jacobkim/School/Fall2018/Learning from Demonstration/Cozmo/cozmo-blockly/nodejs/headless.js:3:20)
at Module._compile (internal/modules/cjs/loader.js:702:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.