Playing with implicit animations

Load the folder onto your Pi, navigate into it using your Pi SSH session, and run the following commands:

npm init -y
npm i --save johnny-five raspi-io

Now that we're all set up, we run the code using:

sudo node implicit-animations.js

Once you see Board Initialized, we can run our functions and see the differences. Here are just a few to try:

normalFullSwing() // hm...
timedFullSwing(1000) // wait a tick...
timedFullSwingWithSteps(1000, 10) // why didn't it do it?

You may be noticing something is up by now. At most, you might see a twitch or two, but it's certainly not working as intended!

That's because of a very important thing with timing, and that's that if you don't wait for servo movements to finish, they'll just override each other, causing unstable results.

That's part of why the animation library is so important! It has the ability for you to queue animations, meaning that the servo will let each movement finish before moving on to the next, preventing the need for you to program the waiting in yourself (especially icky considering the asynchronous nature of JavaScript).

Now, we're going to use a few more implicit animations, and some setTimeout() calls, to make these functions work properly.

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

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