Giter Club home page Giter Club logo

trik-typescript-template's Introduction

Motivation

This project was written so that TRIK programming could be less of a pain. It does so by providing JS api's and syntactic features that are missing in QtScript using core-js and babel along with static typing using TypeScript. This allows to use not-so-ugly classes, iterators, generators and so on.

Also this project can be used for programming of TRIKs without trik-studio. This is achieved by using remote-run.py script that allows to upload, run and get output of your program. But no simulator integration is implemented yet.

Description of build system

In order to accomplish this goal, a compilation process must be organized. rollup is used for this. Simply speaking, it takes a bunch of .ts files and generates one .js bundle that has all the functionality combined.

This setup is more-or-less generic rollup-typescript-babel setup (like this one), with some notable additions:

TRIK modules and typedefs

Conventional TRIK scripting uses various global variables to interact with APIs. To support type definitions they are provided as modules instead. brick corresponds to trik_brick, script corresponds to trik_script, mailbox corresponds to trik_mailbox and Threading corresponds to trik_threading.

All of those modules are have (partial) type definitions, located in src/lib_defs/trik.d.ts. They are based on trikRuntime source code (brickInterface.h, ScriptExecutionControl.h, mailbox.h and threading.h)

Entry points

Entry point should be located in src/entry_points or any subdirectory. Each entry point will result in generation of separate, fully-independent bundle that can be executed on TRIK.

Entry points are divided into two types: those that execute on real robot and those that are designed for simulator. This is shown by putting either real or sim to the file name.

Resulting bundles will be placed into bin/real and bin/sim.

Polyfills

Polyfills used on TRIK are located in src/polyfills directory. index.js imports all other files (it is implicitly added as an import to every entry point compiled). global.js defines variable global (QtScript does not have it). unsystem.js removes unneccessary variables added by TRIK's system.js from global namespace. trik_shim.js imports various core-js modules that provide runtime support for missing APIs. Some of the APIs are not imported, but implemented there using TRIK's non-standard APIs.

remote-run.py and End-Of-Script marker

remote-run.py implements the protocol used by trik studio for uploading and running of programs. But the problem is that it has no means of knowing when your script is done executing (without errors). This is achieved by adding end-of-script markers to each real robot entry point. It's a piece of code that prints a pre-defined value (__eb3caide9Oojaiku__stop_marker__) to the console. When remote-run.py encounters it, it assumes that script is done executing and exits.

Placement of such a marker is achieved by a (small) rollup plugin: rollup-plugin-real-transform.js.

Also remote-run.py has ability to work with several robots. This is done by introducing a ADDRESSES constant, defining all the addresses that are to be used. An index in that array could later be provided to the script as a second (optional) parameter.

Usage

Quick start guide would be:

  1. Install npm
  2. Clone the repo (git clone https://github.com/DCNick3/trik-typescript-template.git)
  3. Install required npm packages (npm install, executed in the repo directory)
  4. Build the code (npm run build)

To upload some code to the robot run npm run run

Target file and robot index can be changed in package.json

Code examples

This repo contains sample code that demonstrates some of the features of the build system. See src/implementation/index.ts for actual code and src/entry_points for entry points.

trik-typescript-template's People

Contributors

dcnick3 avatar

Watchers

 avatar

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.