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

Easing into your servo animations


Unless you want any of your future walking bots to be very firmly in the uncanny valley, you'll need to use easing to create a more fluid, natural motion with your animation segments.

How easing fits into an animation segment

Easing functions are added into the keyframes of a servo; so not only are we saying what position we want the servo to be, but how it gets there. For example, these keyframes:

let keyframes = [
  null,
  {degrees: 180, easing: 'inoutcirc'}
]

Will take a servo starting at any position and move it to 180, starting out slow, speeding up in the middle, and slowing down again towards the end.

There are many different options for easing, and they are documented in the ease-component (https://www.npmjs.com/package/ease-component) npm module included as a dependency to Johnny-Five. We'll be using incirc, outcirc, and inoutcirc to start.

Adding easing to our first animation

Copy the contents of my-first-animation.js into a new file called easing-animations...