44
$\begingroup$

As somebody who is spending the majority of his time programming in JavaScript, what's the best route to get into small-robotics without needing to deviate too much from my current language focus?

Are there any project kits or tools that make use of the JavaScript language that might make the field more approachable for developers like myself? I would even be interested in virtual environments where all code is executed in a simulation.

$\endgroup$
5
  • 3
    $\begingroup$ You should checkout this post... weblog.bocoup.com/javascript-arduino-programming-with-nodejs It discusses a pure Js implementation of the protocol used for Arduino. Pretty cool stuff. $\endgroup$ Nov 7, 2012 at 19:45
  • $\begingroup$ I'd like to see some nodejs implementation running on the robot. One might just control the robot over the web using websockets. $\endgroup$
    – Lord Loh.
    Nov 7, 2012 at 19:48
  • $\begingroup$ You do not programme in JavaScript - You write scripts(which are used on a browser for Client manipulation of the DOM) You can programme in JAVA - which is completely different. node.js it not javascript either. It is a C library that interprets AJAX calls as mini server and is used for high volume requests- for example on ebay- You do not need to refresh a page on an item that is ending because javascript synchronises the bidding price and time by using node.js extremely quick response while reducing traffic overhead) node.js is good for arduino cause it is C $\endgroup$
    – Piotr Kula
    Nov 12, 2012 at 17:24
  • $\begingroup$ So you would programme the bot in c and interface to it using node.js - which inherently uses JavaScript ajax for request but you can also use server requests or other clever code that is not related to JavaScript in anyway. $\endgroup$
    – Piotr Kula
    Nov 12, 2012 at 17:27
  • $\begingroup$ Is the Arduino code the only efficient way currently? $\endgroup$
    – Huzo
    Feb 9, 2017 at 15:47

11 Answers 11

24
$\begingroup$

There are a couple of projects out there that mate the Arduino platform to the Node.js javascript execution engine. Take a look at Johnny-Five, which is a library on top of the Arduino Firmata remote control protocol or node-reflecta, which is a Node.js interface for the Arduino Reflecta remote control protocol.

I've personally built a Node.js controlled robot called RocketBot, that combines node-reflecta with node-joystick on top of a Beaglebone and an Arduino so I can attest this approach works well.

$\endgroup$
14
$\begingroup$

Hmm, interesting question! I personally would suggest that you take a look at the Arduino platform. It's programmed in C, so the syntax is going to be... familiar, to a JavaScript writer. In my humble opinion, knowing how the syntax (while loops, if/than blocks, etc) is laid out is 70% of the battle, once you're familiar with that, you can plug and play. You can pick up a starter kit for around $30 online from the good folks at SparkFun.com or adafruit.com, you can program it on a PC, Mac or Linux machine, and it comes pre-loaded with enough examples to ease you into the language quickly. I'm not saying that you're just gonna drop some JavaScript code into it and be on your way, but I was a JavaScript programmer when I started out with Arduino, and I found it quite easy to pick up and run with. Good luck, as a part time teacher in robotics it's always awesome to see people getting into the field!

P.S. - you should also be familiar/comfortable with building electronic circuits (lights, motors and the like), but any good Arduino introduction kit worth its salt will get you started if you don't have any experience.

$\endgroup$
3
  • 3
    $\begingroup$ P.S. - A good question for the fledgling, newly minted Robotics.SE site, I think :) $\endgroup$
    – Chris
    Nov 7, 2012 at 19:39
  • 1
    $\begingroup$ Great answer, @Chris. I've heard of the Arduino platform from some other JavaScript developers. Perhaps that's the best gateway drug for a developer looking to get hooked. $\endgroup$
    – Sampson
    Nov 7, 2012 at 20:06
  • 1
    $\begingroup$ As a young JavaScript/web developer I find your question super interesting. As stated before there are platforms for node.js and other various versions, however if you are really comfortable in JavaScript, you could really easily learn any other language, which I would highly recommend. Not only does it expand your ability to understand fundamental computer science, but it also makes learning new things easier. $\endgroup$ Nov 8, 2012 at 1:18
9
$\begingroup$

Robot Operating System (ROS) offers the ability to use Javascript to control your robots. Specifically you will want to look at rosbridge. You will then need to use rosserial to interface with the microcontroller controlling your robot.

While I am a big fan of ROS this is an overly complicated way to begin exploring the field of robotics IMHO. You would be better served to pick up an Arduino and learning a little bit of C. Arduino does a great job of making the process simple and C is not a large deviation from JS from a syntax perspective.

$\endgroup$
5
$\begingroup$

Generally there are many ways to use node.js with a platform, like this one for the RPi. There are a lot more similar ones if you just search for them.

Another interesting one is ArduGate, which lets web pages communicate with the arduino via JS (though probably not exactly what you wanted since it doesn't compile and load to the arduino)

Though I really don't see what's wrong with using a different language. I myself write primarily in JS, but I find myself perfectly comfortable programming an Arduino in C++ (it also allows C and Java, and if you put in a bit of work, quite a few more languages ). Remember, we're not needing anything fancy for programming a robot--just normal ifs,fors,whiles,switches, and the occasional class. Learn the syntax, and you're good to go :) The only thing is that C/C++/Java are strongly typed (though if you're using the RPi, python is weakly typed but picky in a million more ways), so you may get a bit of frustration in the beginning when you have to specify types for everything. One advantage of using the native languages is that it's much easier to find APIs and example code on the net. For example, aside from ArduGate(which has it built in and is probably not what you wanted), I can't find any way to access the EEPROM--a common task. So, unless you want to stick to simple programs, it's just better to use the native languages.

$\endgroup$
3
$\begingroup$

Microsoft Robotics uses a protocol called Decentralized Software Services Protocol (DSSP) and they released the specs under a license that allows anyone to implement it in any language. The DSSP protocol is totally compatible with current web standards and I think it would be a great idea to implement it in JavaScript and NodeJS. That can make it possible for your node application to interact with any DSS robotics services available today.

$\endgroup$
2
$\begingroup$

A friend of mine actually has a pretty powerful tank robot that's controlled with NodeJS over wifi. The robot itself isn't exactly "small-robotics" at 150 pounds, but you could probably learn quite a bit from the source code. It has a netbook onboard running a webserver and talking to an Arduino. You can find the source code on his Github project page. The real-time control from a web browser on another computer is surprisingly responsive.

$\endgroup$
1
$\begingroup$

There is also a project called Espruino, which is a JavaScript interpreter for low power ARM microcontrollers. It is a rewrite of the tiny-js project, a small C++ interpreter for Javascript.

$\endgroup$
1
$\begingroup$

Programming the AR.Drone 2.0 with Javascript is super fun. Here's an example that makes a drone take off, move around, do a flip, then land, all using the node-ar-drone library:

var arDrone = require('ar-drone');
var client = arDrone.createClient();

client.takeoff();

client
  .after(5000, function() {
    this.clockwise(0.5);
  })
  .after(3000, function() {
    this.animate('flipLeft', 15);
  })
  .after(1000, function() {
    this.stop();
    this.land();
  });

The blog post NodeBots - the Rise of JS Robotics talks about advantages javascript has for robotics, specifically the natural way that real world objects and actions can be modeled as chainable, evented processes. The example code above to animate a drone looks very similar to using jQuery to animate an HTML element:

$("#foo")
  .slideUp(300)
  .delay(800)
  .fadeIn(400);
$\endgroup$
2
  • $\begingroup$ I've edited the answer to be more specific and add more context. Thanks for the feedback. $\endgroup$ Aug 21, 2013 at 19:02
  • $\begingroup$ Thanks John, that's a great edit, just the sort of thing that makes a future-proof answer. $\endgroup$
    – Mark Booth
    Aug 22, 2013 at 8:34
0
$\begingroup$

It might be helpful to look for javascript-based robotics projects online as javascript-based robotics community has been growing rapidly since this question was asked. For examples, the blogger behind https://burningservos.com documented processes of building a four-legged robot from scratch and discuss multiple libraries javascript the blogger evaluated or used. There is also "hardware" section in glitch (or even at Adafruit and Hackster.io) where people share their javascript-based hardware hacking projects where you can check out libraries they used.

$\endgroup$
0
$\begingroup$

The approach I took to this in my project, https://github.com/Ezward/Esp32CameraRover2, was to develop a small core for the robot in C++; enough to do closed loop speed control on motors, provide a command interpreter so the client can control the robot and to serve an html/css/js client application over http. The client is served by the robot itself and connects to the robot over websockets. Partitioning in this way allows very time critical tasks, like speed control, to run on the robot, and higher level tasks (like go-to-goal, path following or object recognition) to run in JavaScript. This also allows the robot to be built using a very inexpensive microcontroller; this project uses an Esp32Cam. It can stream real-time video from the robot to the client which opens up a lot of options for processing images in JavaScript. The project is build on a very inexpensive platform (about $40 total for parts) and requires little-to-no soldering. I'm using the ESP32 Arduino library in the PlatformIO IDE, which is a plugin for Visual Studio Code. This is a great IDE for this kind of project; you get the ease of the Arduino framework for the low level robot code and you get a very nice JavaScript experience (unlike the Arduino IDE). Debugging the client code is done using browser developer tools.

$\endgroup$
0
$\begingroup$

A new compiler is available through the Microsoft App Store called "Robot JavaScript". This compiler works in Windows10 and compiles code for EV3 Mindstorms robots. If you have a Lego Mindstorms EV3, check out: https://www.microsoft.com/en-us/p/robot-javascript/9nb6w06lpx68

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.