Book Image

Hands-On Robotics with JavaScript

By : Kassandra Perch
Book Image

Hands-On Robotics with JavaScript

By: Kassandra Perch

Overview of this book

JavaScript has an effective set of frameworks and libraries that provide support for embedded device programming and the robotics ecosystem. You’ll be able to put your JavaScript knowledge to work with this practical robotics guide. The book starts by guiding you in setting up an environment to program robots with JavaScript and Rasberry Pi 3. You will build beginner-level projects, such as a line-following robot, and then upgrade your robotics skills with a series of projects that help you get to grips with the Johnny-Five library. As you progress, you’ll learn how you can improve your projects by enabling advanced hardware components and programming concepts. You’ll even build an advanced AI-enabled robot, connect its NodeBots to the internet, create a NodeBots Swarm, and explore Message Queuing Telemetry Transport (MQTT). By the end of this book, you will have enhanced your robot programming skills by building a range of simple to complex projects.
Table of Contents (19 chapters)
Title Page
Dedication
Packt Upsell
Contributors
Preface
Index

How we will use the Raspberry Pi


So, we've established that the Raspberry Pi is a very versatile and powerful machine for its size, but with so many options, it can be hard to figure out where to get started. Luckily, we have a plan that will walk you through your first Raspberry Pi and Johnny-Five projects so that you can keep up, but which will also empower you to build your way into advanced robotics projects.

 

Taking advantage of all that the Raspberry Pi has to offer!

The projects we will build will take advantage of the fact that the Raspberry Pi is both a microcontroller and a computer. We'll use the Linux operating system, via the Raspbian distribution, and leverage it to run our projects in Node.js. We'll also use Johnny-Five and Raspi-IO to leverage the GPIO of the Raspberry Pi in order to create robotics projects in a way that makes the code easy to understand and portable to many different hardware platforms.

Johnny-Five – letting us code hardware in Node.js

In the past, when you thought of robotics projects, it meant writing in C or C++, usually through the Arduino IDE and APIs. However, as microcontrollers have gotten more powerful, they are capable of running other programming languages, even scripting languages, such as subsets of Python and JavaScript.

And, of course, with computer/microcontroller hybrids, such as the Raspberry Pi, you're able to run stock Node.js, allowing you to create even advanced robotics projects without having to deal with any low-level languages. There are quite a few benefits to being able to code robotics projects in Node.js:

  • Event-based systems: In the Arduino and C/C++ level of robotics programming, you will need to check the state of everything through each iteration of a loop, and act accordingly. This can create monolithic functions and code paths. With Node.js and Johnny-Five, we can use event emitters and systems, which fit in surprisingly well as they can read sensors and interact with peripherals in the real world, where things take time. This will help you to organize code in a way that reflects the asynchronous way the world works.
  • Garbage collection/automatic memory management: While Arduino and C++ handle most memory management for you, programming in microcontrollers that use C requires strict memory management. While you may need to bear the resource constraints of the Raspberry Pi in mind from time to time, it is much easier than the days of 20K SRAM.
  • Using a language you already know: Instead of trying to remember the way things work in a new language, it will accelerate your learning in the field of electronics and robotics if you focus on learning fewer things at once. Using Node.js can help you focus on learning the wide and varied world of electronics, instead of adding on the extra work of remembering whether it's uint8_t or uint16_t.