Maestro Servo Controller (Raspberry Pi)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hey what's going on guys it's his video I'm gonna be talking about servo control with the Raspberry Pi so if you've noticed in my previous video I talked briefly about the 16-bit PWM servo control and I showed you guys how to set that up however honestly that servo controller has a bit of jitter and it's it's pretty difficult to work with so I sort of stumbled across this servo controller platform and in my experience it's been working really well and it's been relatively easy to work with it's provided by this website Pololu robotics Pololu comm the links for all these parts will be in the description like always but let's go ahead and dig into this servo controller and talk about the features a bit so first and foremost if you go on to the site you'll notice that there's several different versions of this servo controller this is the 18 channel version so that means you can hook up 18 different servos to it the site provides six 12 24 no 6 12 18 24 channel version servo controllers so really depending on your use case you can sort of fine tune how many inputs are needed for your project what's really great about this platform 2 is that it's really well documented so let's talk about the power options you have so the board needs power as well as the servos they also show you different wiring schematics so you can run everything on one power supply but that's not ideal in this tutorial we will be covering a separate like how to set up a separate power supply for the servos and then we will be community kidding to the Raspberry Pi via the TTL serial interface so I initially tried to connect the servo controller to the Raspberry Pi via the mini USB serial interface however that was slightly problematic on the Raspberry Pi side setup wise so TTL the GPIO pins works pretty well as an alternative so with all that said and done let's go ahead and talk about the parts that you're going to need so you're gonna need four female to female jumper cables so one for ground one for five volts one for the TX pin and one for the rx pin so it's going to be wired up in a sort of crossover set up so that TX pin on the servo controller is going to link to the RX pin you're also going to need a mini USB cable because the way that we're going to interface with this device is we're actually going to program it with the computer like these subroutines and then we're gonna call those subroutines via Python script on the Raspberry Pi that's the ideal way to do it and you'll see why in a bit we'll dig into that a bit later and for testing purposes I'm gonna be using two 9 gram servos so you can use really any server you want with this platform the specs are listed in their documentation of what sort of the you know power requirements are required and what it can handle but in my experience it's pretty versatile also I'm going to be using an external power supply to power these two 9 gram servos so I'm just going to be running them off 5 volts if the amount of power for your servos really depends on the type of serve you you have in your application so definitely do your research there don't like you know quote anything that I'm doing here definitely double check to make sure you're feeding everything the right voltage is and whatnot you might also need a small screwdriver to screw in the the power to these growing terminals alternatively you can use these two GPIO pins for power as well but I'm just gonna hardwire it in there so with all that said done let's go ahead and wire this bad boy up so if we flip this over it's a bit hard to see but all the pins here are listed there's a ground then Rx and TX so I'm gonna go ahead and wire this side up real quick so Browns gonna be ground red will be the five volt and then what is it Rx will be orange and TX will be yellows I'm gonna do that real quick so just have them lined up right here and I'm just pushing them in so these four pins go and then now that that's done we can head over to the PI so I'm using a PI zero here just because it's small form-factor that the PI 3 will work as well a quick note about this setup though because the Raspberry Pi is sort of setup weird when we do go to activate the TTL serial interface we're gonna have to disable the Bluetooth functionality because the Bluetooth chip runs by default on this TTL serial interface that we're going to be using so if you have plans to use bluetooth you're gonna probably need to go another route and maybe try hooking up via the USB but we're not covering that in this video so let's go ahead and wire this up so we need 5 volts so that's the second pin on the top row and then ground would be this third pin so the brown goes to ground and then like I said orange was was our X on the servo controller so we're gonna hook it up to that the TX pin which is right next to the ground pin and then finally we just have this yellow uhm GPIO jumper and this goes to the RX pin on the PI and then as wiring is concerned that's pretty much it I'm gonna go ahead and hook up my power leads to the servo controller so what I need to do here is loosen these two screw terminals I know from experience the negative side is the rightmost screw terminal so I'm just going to put that in it's very important that you make sure that the polarity is correct on these yeah if you switch the these two terminals it won't work properly apologies these wires are pretty janky so it's a little bit difficult for me to shame them to place so that's good there and then finally the red positive water all right so now this is ready to accept 5 volts via this barrel connector let's go ahead and hook up our servos so I have two cells here just for demonstration so we can I can demonstrate you know controlling multiple servos so on the back you know all the servo interfaces are labeled so it's from 0 to 17 so we're going to be plugging in 0 and 1 so also the different signal positive and negative as also labeled so on these nine grams servos the oranges signal red is positive and then Brown is grounded negative so we're gonna hook that up real quick so signal is the left-most and there we go so that's it that's pretty much that covers learned so let's review what I've done here real quick I've hooked up these two 9 gram servos signal on the left 5 volts on the middle and then ground on the right and then I have the barrel connector hooked up here so positive on the left side and then negative on the right and then I've bridged these two boards together so via the TTL serial interface so we have ground 5 volts what is the orange here so our X and then TX and then the same thing here as well but these two pins are switched here the RX and TX so that pretty much covered its physical setup we're gonna head over the computer next I'm gonna be talking about how to set up the PI and then as well how to set up the maistro' controller servo controller via their Mesa maistro' control program that's provided so I just SSH into my Raspberry Pi so I'm gonna walk you guys through how to set up the serial interface so you need to make sure that you power your PI and because we wired up via the GPIO the maistro' servo controller will be powered to you you should see a orange blinking light indicating that the GPIO pin is setup is correct we don't really have to worry about the servo power at this point in time but if you want to you can hook that up as well but with all that said now let's go ahead and get the serial interface set up so the first thing we need to do is edit the Raspberry Pi config so we do sudo speed config I've already done a lot of this stuff so I'm just so it may show up differently from what you see here but once you type that command in you're gonna go to interfacing options and you need to go to serial and you want to do know so you want to disable the login shell and you want to enable the serial port hardware and then hit OK once that's done go ahead and finish and now we have to install PI serial so we have to do Python - and hit install PI serial so go ahead and do that it may take a while but just be patient so as you can see it was successful once that's done we're gonna have to you pull down the Python library so type git clone and then copy and paste the link go ahead and do that so go ahead and hit enter after this I'm not gonna do that because I think I already have some particular files in there so hit enter it should pull down they get project and then you should be good to go after that's done we have to disable the Bluetooth you UART because by default the Raspberry Pi uses a serial interface for the Bluetooth controller so to to edit that all we need to do is type sudo nano config txt and then scroll all the way to the bottom and you want to append this line here DT overlay equals pi/3 - disabled - bTW go ahead and save and exit after you've done that go ahead and do a sudo reboot so since I already had that done I'm not gonna do that right now after it reboots go ahead and type this command here D message type grep TTY to verify that everything is set up correctly and in this case we can see here these two things right here you should have some similar output and yeah that's pretty much it that's how we get the serial interface configure on the Raspberry Pi so now we're gonna move over to setting up the maistro' controller using the maistro' control software okay so i've just moved over to my Windows desktop and the first thing that you want to do is go ahead and download the maistro' servo controller software and you can get it at this site PO lalu comm the link will be in the description on my website so go ahead and download that for whatever operating system you're using in this case I'm using Windows once you do that plug the micro USB to USB cable into the maistro' controller and into your computer and then fire up the may show control center software so this is what you're seeing here this is a software interface so you should see that it's connected to you know device number whatever there are some controls here if you have trouble the first thing that we need to do is enable channel 0 and 1 because we have the two servos hooked up to that so let's go ahead and do that once you click these you should notice that they move and they sort of when you call it orientate themselves to the middle so this is essentially how we are going to record the different positions now we can use a slider here you notice that when we move at the servos will start to move I guess I'll walk you through all these different tabs so this is sort of where we'd set the positions here is I guess where we see errors this is sort of the channel settings serial settings sequence script so I think what's really relevant is status sequence in script we don't really need to mess with errors channel settings or serial settings by default you should have it at you are fixed baud rate 9600 I already have a script on here so I'm gonna go ahead and clear this out I should still eat everything so now that we have a blank slate let's go ahead and start recording some movements or savings positions on the dis control software here so the first thing we need to do is move the different channels for the servo so I'm going to go ahead and move channel 0 and 1 these sliders to the left and then save the frame the first frame is 0 and then move both of them to the right save it as another frame and then finally recenter everything as our third frame so now we have three movements and if we go to sequence we can see all these movements saved in different frames here so if you play the sequence you should notice that your servos move now that that's done we can copy this sequence to the script so essentially what this copy of the script means is we can copy these movements to the servo controller memory and this sequence is essentially you can think of it as a function it's called a subroutine so if we copy this to the script you can see it's saved as sequence zero and we have all the frames here so if we go back here and actually it's let's go back to the sequence tab and hit new sequence let's make a new function and we start over we can see the frame goes back to zero now let's change it up a little bit let's make the channel zero to the right on the slider and then channel one go on the left and see that one frame and then have them return to Center so and then save that frame so now when we go to sequence we have two sequences right we have our previous movement essentially in one subroutine and then we have this new set of movements in another subroutine so we're dumb copy the new students we just made to the script and you can see something weird here in the sense that we have sort of a redundant functionality here so it's always good to just before you copy everything scripts just delete everything on the script and then go back here and click copy all secrets to scripts so that way you don't have redundant code and you have more memory so now we can see that we have these two subroutines right so the first subroutine has the three movements and then the second subroutine has these two movements and we can go ahead and apply settings and now it should be saved to our server controller memory so we can see here there are 8000 192 bytes and we use 175 so it's it's I think the best way to go about defining your logic is to have as small of movements defined in the servo controller and abstract all the more complex repetitive stuff you know in Python so now that this is done we can head over to our Raspberry Pi and and s is a an SSH in and then to create a Python script to interact with the servos via code so let's go ahead and do that so I've SSH back into my Raspberry Pi and I've navigated into the maistro' git project we pulled down earlier so I've created these two sample scripts here and I'm gonna sort of walk you through different ways to interact with a servo controller so the first way is we're physically going to control the servos manually and not really interact for the subroutines and I'm the way that we're going to do that is in the library we can set the positions manually so in order to do that there are a number of things we have to do are put into our Python script so we need to import the maistro' library and then i've imported time here to sort of add a pause in between each of the movements so we need to initialize the controller here so I do servo equals maistro' controller and then you can see here I I have the channel 0 and channel so every time we want to set a movement we have to set the acceleration like the speed it moves that and we just set the target so it's the PWM like position and then we have to do that for each channel so you can see here that these first set of movements I'm moving the to chant to servos to 6000 and setting the acceleration of 25 then I'm sleeping for 2 seconds and then I'm setting a solution to 25 and then moving them to the position to 1,000 so if I go and type Python tests up py it should go ahead and move those servos so that's a very simplified example here of how to manually control their servos this is not the ideal method to control their servos because if you think about it you'd have to type a lot of lines of code just for like simplified movements where it's much a much better methodology to go ahead and use the control software here and essentially just record the positions and then we can just call these functions so I'm going to show you that now with the subroutine Python script I create it's okay set up qy so if you remember earlier i defined these two subroutines sequence 0 sequence 1 and they already have the movements defined so we're just going to go ahead and call those functions essentially and then they should move the servos accordingly so now we can we can see here it's very similar to our script above you know import maistro' import time you know initialize the controller then right here the difference instead of we instead of setting setting the servo manually the acceleration and target we are just calling this subroutine 0 so right here I'm calling this subroutine 0 printing a message and then I'm gonna sleep for a couple seconds and then I'm gonna call the second subroutine and then also put that message so let's go ahead and do that so python set p/y so it runs through all of those movements and then it calls the next function essentially and then it runs the next so in this way it's much easier to configure multiple servos or the very complex movements and also you can sort of abstract the complexity to the Python script without having to deal with you know like for example threading because there's really no way you can easily control multiple servos in this manner but with the this sort of process I've just showed you it's much easier to go ahead and do that so yeah I hope you enjoy today's tutorial that's sort of like a simplified look at the maistro' controller and some of this functionality if you have any questions leave comments down below you know like and subscribe it's always appreciated and yeah stay tuned for some upcoming videos I know it's been a while I have a lot of things in the works so yeah see you later guys peace
Info
Channel: PiddlerInTheRoot
Views: 12,331
Rating: undefined out of 5
Keywords: Raspberry, Pi, Servo, Maestro
Id: 6EGSsxPzXO0
Channel Id: undefined
Length: 26min 34sec (1594 seconds)
Published: Wed Feb 28 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.