Allo-AVA / transcript /DIY_jsXolwJskKM.txt
SaifPunjwani's picture
Add files using upload-large-folder tool
c2af964 verified
raw
history blame
14.4 kB
[0.000 --> 4.480] I've recently been watching animatronic videos on YouTube. There are lots of great mechanical
[4.480 --> 10.240] assemblies for heads, hands and other types of creatures built with 3D printing and other techniques.
[10.240 --> 15.040] If you've ever built a project using RC style servos in Arduino, you know that it's really
[15.040 --> 20.640] very easy to move servos around using the Arduino servo library. But you'll find that the servos
[20.640 --> 25.520] start suddenly, move to their new positions as quick as the motor will go, and then stop suddenly
[26.400 --> 30.240] This can be quite noticeable and it can make the project look less organic than it could.
[30.880 --> 36.080] So today I'm going to show you how to make servos or other actuators move much more smoothly
[36.080 --> 39.680] using only two simple extra lines of Arduino code.
[56.000 --> 70.560] Thanks to 3D Fuel for the filament for this project and lots of other projects, so check out my
[70.560 --> 76.160] channel for more 3D printing projects and check out 3Dfuel.com. I decided it would be more
[76.160 --> 80.480] interesting to show you how this works if we had an animatronic device to actually demonstrate it
[80.560 --> 85.200] on, so I'm putting together a relatively simple thing with two eyeballs and some other axes
[85.200 --> 90.000] that move. So we've got a pivot for each eyeball and you'll see I've left slots in the top there
[90.000 --> 95.280] so we can get the screwdriver in for various things. There's another lever that's going to drive
[95.280 --> 100.480] each one of those pushed by a servo. It only needs to be pretty simple so the eyeballs only look
[100.480 --> 104.560] left to right, there's no up and down motion, although we'll look at that later in the neck.
[105.360 --> 109.600] You really don't need expensive hardware to make the motion of your animatronic project smooth,
[109.600 --> 115.520] so I'm using some really cheap 9g servos which are branded with some random name and I got these
[115.520 --> 120.880] off Amazon. These all fit into 3D printed brackets and we're going to have one of those to move
[120.880 --> 126.960] the eye on each side. All of the pivot points are just screws straight into the plastic, I've used
[126.960 --> 131.760] some of the smaller screws that came from mounting the servos as well. So here we can see one of the
[131.760 --> 136.800] servos mounted on its 3D printed bracket and that's going to move the eyeball side to side quite
[136.800 --> 144.400] convincingly. I thought it would be a nice feature to have a pair of eyelids on each eye that
[144.400 --> 148.400] just gives it a bit more character and have designed the top and bottom lids to fit together and
[148.400 --> 153.360] hinge around the same pivot point. And again these are just attached with a single self tapping
[153.360 --> 157.760] screw straight into the plastic and into that single pivot point on both eyelids.
[160.240 --> 164.400] Again I've added another cheapo servo that's going to push both of those lids closed and
[164.400 --> 169.680] there'll be one of those on each eye. So I made some 3D printed levers with a slight crank in
[169.680 --> 174.160] and that just means it can reach over the bracket that's holding the pivot point of the eyelids
[174.160 --> 179.520] so that the servo can push and pull both of them at the same time without any obstructions
[179.520 --> 186.080] and that seems to work pretty well. I have of course been making two of these and these are
[186.080 --> 191.280] mirrored pairs. Both of them are attached to a single bracket with a pivot point in and that
[191.280 --> 195.440] means they're both fixed together just like they would be in a creature's skull. There are
[195.440 --> 200.080] several pieces that make up the neck mechanism there's this intermediate piece that has two servos
[200.080 --> 205.600] on and it also has a pivot. All of this is 3D printed and all of it's running just on the thread.
[205.600 --> 210.320] This particular piece is on an M6 bolt. This is attached to the first section that has the
[210.320 --> 216.160] eyeballs mounted on so that we can move around in two axes. And that will of course be controlled by
[216.240 --> 221.440] the two servos with two levers pushing the upper stage and the combination of the position of those
[221.440 --> 228.000] two servos will move the two axes. That whole piece has a piece of M8's studying screwed into
[228.000 --> 233.920] the bottom and that fits into some bearings mounted in the actual base. There's a washer here
[233.920 --> 238.880] acting like a little spacer just to shift that top part up so it can run freely on the bearings
[238.880 --> 244.640] and that gives us the side to side motion and that's controlled by a third servo with a lever
[244.640 --> 249.920] and these are just pretty cheap servos as well that I got off Amazon. I built a breakout board
[249.920 --> 254.960] so I can plug all of the servos in and distribute power and ground to them. I just built this on
[254.960 --> 260.160] core components perma proto board so that I can break out all of the wires and all of those who
[260.160 --> 264.480] have caused the attached additional pins on an Arduino Uno which is all you really need.
[265.120 --> 269.280] I'm powering the servos from a two amp adjustable regulator turned down to five volts
[269.280 --> 273.920] and any old battery I had lying around and that should be plenty of current for this type of
[273.920 --> 279.600] project. To start with I'm going to use a switch to control this which just switches on and off.
[279.600 --> 285.520] I've made some really simple Arduino code that reads that switch into a variable. It reads it in
[285.520 --> 290.320] and then multiplies it by a hundred so we get quite a big number and then I'm typing it out to
[290.320 --> 295.600] the serial terminal so that we can see it and I'm running this every 10 milliseconds so that it runs
[295.600 --> 301.120] a hundred times a second. So if we open a serial plotter and have a look at the switch we should be
[301.120 --> 306.560] busy that we get a square wave as I switch it between zero and a hundred and we can see that's
[306.560 --> 311.760] quite sharp. So if we were to use that to move a servo then it would move as fast as it can to
[311.760 --> 318.800] its position and then stop abruptly. But what we really want to do is not let that number change
[318.800 --> 324.320] too quickly so we get a smoother motion so I've created two new variables one called switch smooth
[324.320 --> 329.360] and one called switch previous and all of the code is in here which is just two lines.
[329.920 --> 335.200] So what we're doing here is taking only 5% of the new value that we're reading from the switch
[335.200 --> 341.520] and multiplying by a hundred and 95% of the previous value. We then create the previous value by
[341.520 --> 346.880] bookmarking it here so it's the same as the new smooth value we've created. I'm then typing
[346.880 --> 352.240] those out to the serial terminal so we can see both the original value and the new smooth value.
[353.760 --> 359.040] So now in our serial plotter we can see the same original blue square wave and the new data which
[359.200 --> 364.160] is the red line and we can see that this slowly decelerates as it gets towards its target
[364.160 --> 369.040] and that's because the number can't change that quickly because it's largely using the last value
[369.040 --> 375.920] and only a small fraction of the new value on each cycle of the loop. But before we see how that
[375.920 --> 383.040] goes it's time for a quick ad from the video sponsor which is JLCPCB. JLCPCB are at the forefront of
[383.040 --> 388.960] the PCB manufacturing industry and they provide high quality low price PCBs. It's easy to
[388.960 --> 394.240] order from JLCPCB just to let your shipping destination and click on quote now and upload a
[394.240 --> 400.000] gerber file. The JLCPCB website will show a preview of the board and then you can select various
[400.000 --> 406.080] options for manufacturing. Save it to your cart and enter your shipping information. JLCPCB
[406.080 --> 411.200] currently have an offer where you can get five one-to-four layer PCBs for just two dollars with
[411.200 --> 417.760] free SMT assembly. JLCPCB shipped worldwide and they have fast build times so you can get your
[417.760 --> 424.880] PCBs in as little as three to five business days. The ordering process is very easy at JLCPCB
[424.880 --> 428.160] so use the link in the description to this video to check it out now.
[429.440 --> 434.000] So still just using the switch to get my data input I've now mapped the data output to one of
[434.000 --> 440.480] the servos. I've actually turned up the ratio so we're now using 97% of the previous value and
[440.480 --> 446.240] 3% of the new value and that makes it even smoother and you can adjust the ratio as much as you like.
[446.960 --> 452.080] But you can clearly see that that servo is decelerating as it gets to its target and that means
[452.080 --> 458.560] we get a really smooth organic motion. I thought I should just mix in the eyeballs as well so I'm
[458.560 --> 464.640] still using the switch and you can see my two waveforms so that my eyes also decelerate as they move
[464.640 --> 473.760] in each direction. So I'm pretty happy with that so far. But I thought we should breathe some life
[473.760 --> 478.240] into it so I got a pair of joysticks that are mounted in a box from an old project and these
[478.240 --> 484.400] each have three axes as the tops turn as well. So that's wired into six analog in on the Arduino
[484.400 --> 489.680] Uno although I'm actually only using five of them. I've applied the smoothing to those values and now
[489.680 --> 494.720] you can see no matter how fast I move the stick we always get that deceleration in the animatronic
[495.280 --> 500.480] and that makes a really organic motion that I'm really happy with. My left hand stick is
[500.480 --> 506.160] controlling the three neck axes and my right hand stick is controlling the eyeballs and the eyelids.
[506.160 --> 510.480] Obviously I've got one axis spare if I actually could move the eyeballs up and down but for now I
[510.480 --> 517.280] think that demonstrates the concept pretty well. Of course we still get a sharp motion when we start
[517.280 --> 522.400] the movement and that's pretty normal because most creatures and people will actually move fast
[522.400 --> 527.760] to start with and decelerate as they get to the target so that actually makes it quite realistic
[527.760 --> 529.360] and quite lifelike.
[552.080 --> 556.640] And if I suddenly let go of the sticks you can really see the motion smoothing on all those servos.
[558.080 --> 563.600] If we want to run out animatronic or prop on the fixed sequence of motions we can still do that
[563.600 --> 568.800] but we must keep the loop running all the time so that we keep that smoothing over each iteration
[568.800 --> 572.800] of the loop and that means we can't really use delays which would block the code.
[574.560 --> 579.760] I've based my code on the Adafruit Learning Centre multitasking Arduino tutorial so
[579.760 --> 585.600] yep let's ditch that delay and the idea here is to use the system clock so we can check the time
[585.680 --> 590.480] see how much time is elapsed and trigger events without using delay which would block the code.
[591.120 --> 596.160] For us that means seeing if a certain amount of time is elapsed incrementing a flag to the next
[596.160 --> 601.840] value and resetting the clock to the current time. Then the next time round the loop we can see if
[601.840 --> 606.640] the flag is at the right value and another set of time is elapsed and then we can increment the
[606.640 --> 611.600] flag again and reset the clock again to the current time and in each step of the sequence I'm
[611.600 --> 616.480] setting my pot values to whatever positions I want instead of moving the analog pots on the
[616.480 --> 622.000] controller and after this I've got the same filtering and smoothing code applied. So the result
[622.000 --> 627.520] of this is that the loop keeps running round and round at 100 or 200 hertz or whatever we set it to
[627.520 --> 632.800] but because the loop's running the smoothing still works on each iteration of the loop decelerating
[632.800 --> 638.640] those values. Each time the loop runs it checks for that step flag to be at the right value and
[638.640 --> 641.840] for the time to have elapsed and doesn't do anything else otherwise.
[643.440 --> 648.400] And multitasking means of course we could run multiple step sequences at the same time
[648.400 --> 652.960] because our loops are always running really fast and it's only kicking off the steps
[652.960 --> 656.800] if the time is elapsed and the flag is at the right value so we could have several sets of
[656.800 --> 661.520] things running on one Arduino and that would all be fine. It's particularly important though because
[661.520 --> 666.640] the motion smoothing relies on that loop to keep running so that it can keep iterating on each
[666.640 --> 671.760] loop with the previous value and the new value and chopping them up to give that deceleration even
[671.760 --> 675.920] though there's no new inputs. So I think that's been quite interesting. If there's any more little
[675.920 --> 680.320] tutorials you'd like to see about how to do something with an Arduino or something else then let
[680.320 --> 684.320] me know in the comments. I'm going to publish all the cad and code for this if you'd like to have
[684.320 --> 689.040] a look at it so check that out in the link in the description below it's on GitHub and if you'd
[689.040 --> 693.200] like to support with your Patreon or YouTube channel membership those links are below as well
[693.280 --> 697.760] and Patrons and YouTube channel members can get access to all the videos up to a week early
[697.760 --> 701.840] as well as sneak peeks and pictures of what's coming up to be part of that discussion.
[701.840 --> 704.000] Alright that's all for now.