Playing with implicit animations, take two

To fix your normalFullSwing() function, we'll set the servo.to(0) call to take 250 milliseconds, and call servo.to(180) after 255 milliseconds (just to be sure it's completely done getting to 0 first):

function normalFullSwing() {
servo.to(0, 1000)
setTimeout(() => { servo.to(180) }, 1010)
}

We'll do the same to the timedFullSwing() and timedFullSwingWithSteps() functions:

function timedFullSwing(time) {
servo.to(0, 1000)
setTimeout(() => { servo.to(180, time) }, 1010)
}

function timedFullSwingWithSteps(time, steps) {
servo.to(0, 1000)
setTimeout(() => { servo.to(180, time, steps) }, 1010)
}

Once you've made these changes, reload your project folder and run it:

sudo node implicit-animations.js
If you're using the book code directly instead of following along, implicit-animations-fixed.js contains the timeouts so you should run that file instead of running implicit-animations.js again.

Now that the code is running as intended, let's play around a little more with these implicit animations:

// Just a normal swing
normalFullSwing()
// Playing with the time parameter
timedFullSwing(1000)
timedFullSwing(750)
timedFullSwing(5000)
// Playing with the steps parameter
timedFullSwingWithSteps(3000, 2)
timedFullSwingWithSteps(1000, 10)
timedFullSwingWithSteps(1000, 100)

Make a mental note of what changing the timing and steps does to the servo's movements, it'll come in handy for the rest of the chapter.

Now that we understand some of the underlying effects of the animation library, and why it's so crucial when dealing with complex servo movements, let's dig into the animation library in detail. We'll start with the terminology, unless you have a strong background with animation (as in animated imagery), you have some vocabulary to learn!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.40.189