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

Learning more about queuing and playing animation segments


When we queue an animation segment, we pass it a duration, cue points, and keyframes. But we can also pass in other options that affect the playback of the animation segment. We can also call methods on the animation object that affect animation segments currently playing and in the queue.

Before we start messing with these, copy the content of easing-animations.js into a new file called playing-with-the-queue.js. Remove the call to myFirstAnimation.enqueue() at the end; we want a little control when we get into the REPL this time around.

 

Looping animation segments

First, let's add a function that will enqueue our animation normally:

function playMyAnimation() {
  myFirstAnimation.enqueue({
    keyFrames: keyframes,
    duration: duration,
    cuePoints: cuePoints
  })
}

Sometimes you want the animation segment you are enqueuing to run on a loop. Let's create a function in our board.on('ready') handler that will enqueue our animation...