Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

JavaScript Modules allow you to extend KRL language within a pico engine. They are often used to take advantage of platform specific features. For example, extending KRL to natively manage GPIO pins of a raspberry pi hosting a pico engine.

...

The pico engine is built on top of node, which makes using npm packages ideal and easy to use to extend KRL.  The following example is from the pico rover project. The pico rover is a mecanum wheeled rover that is natively controlled from KRL with a pico engine running on a raspberry pi. A custom JavaScript module is used as a singleton to control motors attached to Adafruit's MotorHAT

This is a good example of how actions should be defined and used. When the speed of a motor is changed, the physical state is changed.  Actions allow the state of a pico to change, the state of a pico represents the physical state of the analog device. When motorHat methods are called they result in a physical state change.   

MotorHat Module Instantiation Example

...

JavaScript Modules empower developers to exstend extend KRL to perform low level operations natively in KRL. This has been demonstrated in the example above by exposing hardware control as a module used as a singleton in KRL.