Cylon Js – A JavaScript based Robotics platform

When we think about JavaScript, we usually have the notion of a small language that have
it’s life inside a browser, and inside a server in the recent times, performing some logic that plays a
key role in the modern world of dynamic web applications. But recently an effort from a company
named HybridGroup, has elevated the JavaScript platform from the web domain to the
Embedded/Robotic domain, by a framework called CylonJs

What is CylonJs?

CylonJs enables common web developers to program embedded devices using a
programming language that they are comfortable to play with (JavaScript). Usually, embedded side
development was approached by programmers, who will be having a very good knowledge about C
and the much lower assembly level languages. CylonJs changes that perspective.

Scope of CylonJs

CylonJs enables us to program most of the well known embedded programmable hardware.
The following are just a few among the entire list
• Arduino
• Arduino YUN
• Beaglebone
• Intel Galileo
• Intel Edison
• Intel IOT
• OpenCV
• Pebble
• Raspberry PI
• Sphero
The following link provides the entire list

How to start with the development?

All the modern web developers either should have tried or using package managers in front
end web development like NPM or bower. Installing CylonJs is just about installing an NPM
package.

Create a new folder and give the following command inside it

npm install cylon

This will install CylonJs and we can start with the development process. The coding can be done in
a NodeJs style development. The programs are run in JavaScript files. These will be calling the
corresponding APIs to talk to the interfaces of the connected hardware. The basic level IO and
connection stuff are all standardized under a single API.

Sample Code – Arduino platform

The following code, makes an LED blink when connected to pin 13 of the Arduino Platform

var Cylon = require("cylon");
// Initialize the robot
Cylon.robot({
 // Change the port to the correct port for your Arduino.
 connections: {
 arduino: { adaptor: 'firmata', port: '/dev/ttyACM0' }
 },
 devices: {
 led: { driver: 'led', pin: 13 }
 },
 work: function(my) {
 every((1).second(), function() {
 my.led.toggle();
 });
 }
}).start();

Connecting to a particular hardware involves just calling the associated meta data and the
connected port. It’s that simple. It is illustrated in the connections part of the above code.

The devices part provides information about the ports and the data flow through them.

The work part is what called as the execution engine, or the cycle or the heartbeat of this
code. This part runs the associated meta data over and over again in a looping pattern. This makes
the hardware run the burned code, continuously until it is switched off.

Compiling the code

The following packages need to be installed to compile the above code.

npm install cylon-firmata cylon-gpio cylon-i2c

Running the code is just like running any other node program

node <programFile.js>

How to feed this code to the device?

Even though JavaScript has occupied the embedded programming domain with CylonJs
there are certain limitations. Like JavaScript cannot talk to the basic hardware directly. It needs
some external help, to do so. CylonJS recommends the GORT toolkit

What is the GORT toolkit?

GORT tookit is a package, that enables the CylonJS code and burn it to the connected
hardware. GORT provides individual download on all the major operating systems like Windows,
Linux and Mac.

GORT can be downloaded at the following link

Once downloaded and installed, it will provide a command called gort in the terminal.

Using GORT to burn data

The following command scans for the serial ports with connected hardware

gort scan serial

This will scan the list of connected serial ports. Once we detect the specific port, the burning can be
done by the following command

gort arduino upload firmata <the port name>

For windows it will be COM ports, and for Linux like devices it will be /dev/tty/*

That’s it. The code will now start running in the connected hardware. The metadata in the
code differs based on the connected hardware. The following links provide the documentation

Let’s do something awesome with JavaScript…

 




No Comments


You can leave the first : )



Leave a Reply

Your email address will not be published. Required fields are marked *