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

Preface

There has been a rapid increase in the use of JavaScript in hardware and embedded device programming. JavaScript has an effective set of frameworks and libraries that support the robotics ecosystem.Hands-On Robotics with JavaScript starts with setting up an environment to program robots in JavaScript. Then, you will dive into building basic-level projects such as a line-following robot. You will walk through a series of projects that will teach you about the Johnny-Five library, and develop your skills with each project. As you make your way through the chapters, you'll work on creating a blinking LED, before moving on to sensors and other more advanced concepts. You will then progress to building an advanced-level AI-enabled robot, connect their NodeBots to the internet, create a NodeBots Swarm, and explore MQTT.By the end of this book, you will have gained hands-on experience in building robots using JavaScript

Who this book is for

Hands-On Robotics with JavaScript is for individuals who have prior experience with Raspberry Pi 3 and like to write sketches in JavaScript. Basic knowledge of JavaScript and Node.js will help you get the most out of this book.

What this book covers

Chapter 1, Setting Up Your Development Environment, this chapter covers the Raspberry Pi and how to use and set it up. This includes setting up raspbian on an SD card, installing Node.js, installing the Johnny-Five library, and installing the Raspi-IO library. The chapter will also explain the overarching concepts of Johnny-Five and Raspi-IO, as well as the benefits programming robotics in JavaScript brings.

Chapter 2, Creating Your First Johnny-Five Project, in this chapter, the reader will build their development environment for their Johnny-Five projects, and create their first Johnny-Five project: a blinking LED

 

Chapter 3, Building Interactive Projects with RGB LED, in this chapter, readers will be introduced to digital and PWM IO pins via LEDs–they will create a couple of projects with multiple LEDs and an RGB LED and explore fully the Johnny-Five LED API. We will also look at including outside Node.js libraries by including the color library to control the color of the RGB LED.

Chapter 4, Bringing in Input with Buttons, in this chapter, we'll show users how to incorporate basic input into their projects with buttons. Readers will learn to track the button by using Johnny-Five Button event.

Chapter 5, Using a Light Sensor to Create a Night-Light, in this chapter, we will add a sensor and create our first practical project: a night-light! The night-light will work by reading from the light sensor and if it's bright in the room, leave an LED off, but if it's dark, light it up! We'll also discuss the role sensors play in the robotics project ecosystem.

Chapter 6, Using Motors to Move Your Project, in this chapter, we will talk about making your project move with motors. This includes the extra hardware you will need for your project to be powered properly, how to wire motors to your project, the johnny-five motor API, and troubleshooting common problems when it comes to using motors with the Raspberry pi.

Chapter 7, Using Servos for Measured Movement, in this chapter, we will discuss measured movement in robotics projects with the servo, and build a servo that responds to a sensor. Readers will learn about servos and the Johnny-Five servo API, as well as build o project with one. They will also learn about the differences between servos and motors in the context of making robotics projects that move.

Chapter 8, The Animation Library, the animation library is a great way to fine-tune control over your johnny-five servo projects by controlling the speed, acceleration curve, and start and end points of your servo's movement. In this chapter, we'll look at the animation library and walk through how to control precision servo movements.

Chapter 9, Getting the Information You Need, in this chapter, we will look into why you would want to connect your NodeBots projects to the internet. We'll start by looking at ways you can use GET requests to obtain information from websites; like weather forecasts for your area. We'll build our first internet-connected bot using weather data and an RGB LED.

Chapter 10, Using MQTT to Talk to Things on the Internet, in this chapter, we'll talk about MQTT, a common IoT communications protocol. We'll look into using an MQTT broker, subscribing to it with our NodeBot, and using that data to react in real-time.

 

Chapter 11Building a NodeBots Swarm, in the final chapter, we will go over possible paths to continue on your NodeBots journey. We will look at how to take the skills developed in the previous chapters and apply them to building multiple connected NodeBots, as well as exploring the avenues left to explore in the Johnny-Five library. 

To get the most out of this book

You will require the following basic things in order to build all the projects that are included in the book:

  • A laptop computer with any OS
  • Raspberry Pi3
  • Micro SD card (atleast 8 GB)
  • Breadboard and wires
  • Adafruit DC and Stepper Motor HAT for Raspberry Pi - Mini Kit
  • Raspberry Pi 3 T-Cobbler
  • GPIO expander board
  • LCD hooked up to your Pi 
  • DC Toy / Hobby Motor - 130 Size
  • 4 x AA Battery Holder with On/Off Switch

For more details on requirements, the setup of hardware and software is explained in each chapter of the book under the Technical requirements section.

 

Download the example code files

You can download the example code files for this book from your account at www.packtpub.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packtpub.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

 

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Hands-On-Robotics-with-JavaScript. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://www.packtpub.com/sites/default/files/downloads/HandsOnRoboticswithJavaScript_ColorImages.pdf.

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "Mount the downloaded WebStorm-10*.dmg disk image file as another disk in your system."

A block of code is set as follows:

board.on("ready", function(){
  // Everything else goes in here!
});

Any command-line input or output is written as follows:

sudo node implicit-animations.js

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "To set up a feed, select Feeds in the left menu."

 

Note

Warnings or important notes appear like this.

Note

Tips and tricks appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: Email [email protected] and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packtpub.com.