Placeholder Image

字幕列表 影片播放

  • Hello for this video.

  • I wanted to do something a little bit different, and that's been made possible by the very generous support from my patriotic or patriots, depending on where you're from for a while, I wanted to tackle embedded systems as a topic, but I've looked for a suitable entry point that simply enough to make into a nice video but also lays the foundations for future video work.

  • So let's get to it.

  • Let's make and program over biotic arm.

  • The aim of this video is to control a robot arm while asleep.

  • Fear my computer here, I've got my computer on on the screen.

  • I want to have some sliders, which allow me to set the joint positions off the robot's movable parts on my computer.

  • I have a USB port on into that I have a Bluetooth jungle the Bluetooth jungle is going to transmit to a Bluetooth receiver.

  • This receiver is going to then communicate with a microcontroller micro.

  • See, in this case, it's an embed L.

  • P C 17 68 on.

  • It's going to do that communication via what's known as a you are out on.

  • I will go through all of these terms as part of this video vote.

  • Bottom consists of six degrees of freedom.

  • That means he's got six movable components.

  • These are known as servos on the servos require a pulse width modulation signal P W M from the microcontroller to set their positions.

  • So from the microcontroller bones have six lots of P w m.

  • We also need to think about power.

  • It's a power my system from a small supply connected into the mains, which is going to convert it to six volts and then want to power my microcontroller by this six faults.

  • But then I also want to power all of my servos bythe same six volts.

  • I'm going to use the pixel game engine to draw some sliders on the screen on.

  • I want to communicate with the Bluetooth jungle Veer, a virtual calm part.

  • And so the ultimate aim is that when we move a slider, we see a joint move in real time.

  • This is the robot arm I intend to build.

  • It's the D i y more rock through you.

  • Six degrees of freedom aluminium robot arm with a claw on this specific purchase from Amazon, you can upgrade to also include the six servos, and I did just that.

  • So thank you to my patrons for funding this project.

  • But there is no doubt it is the cheapest and nastiest robot arm on Amazon.

  • But I think that's OK, because if we can get this to work and get it to work, well, then you know it just goes to show you don't have to pay a fortune for some really cool stuff.

  • The microcontroller I'm going to use is the embed L.

  • P C 17 68 and this is a really nice microcontroller.

  • I know a lot of you will be familiar with things like our DWI.

  • No, I don't tend to use those very much.

  • I prefer using this instead, mainly because it's also quite applicable to use in industry.

  • I like the fact that it's so small and it's so modular on.

  • It's so easy to program and we'll see just how easy to program it is later on.

  • They're not the cheapest microcontroller modules available, however.

  • It is entirely open source, both from a firmware aunt hardwork perspective on it has lots of ready to go peripherals just simple and easy to use.

  • It also has a form factor, which makes it very easy to plug into prototyping board and a quick look at some of the specifications here.

  • It's an arm cortex M three, which is a low respect, armed process, sir, but it's a tremendously capable process.

  • Er, it can clock in about 96 megahertz.

  • It's got 32 K of RAM on 512 K of Flash has got a whole bunch of io for us to exploit, but the bits I love about it, the most of these programming is dragon Drop.

  • It pops up like a flash drive, and you just drag the program file onto it.

  • Very nice on all of the coding that can be done via the browser.

  • And you might be thinking, Oh, dear May, That sounds dreadful.

  • Actually, it's not that bad and experience it all.

  • It's quite a sophisticated Web interface.

  • You can use offline tools if you want to, but that does require a bit of setting up.

  • I like embeds.

  • I've been using them for quite a number of years, even an industry as we can see, it's quite a small device, so it measures here.

  • About 53 millimeters by 25 millimeters.

  • And it's designed to fit into standard 2.54 millimeter pitch headers on the back here because it is also two things going on on.

  • This is what makes it easy to use.

  • This is the user interface circuitry.

  • There'll actually just plug it into your computer and program it quite simply.

  • But on the on the top is that where the real stuff happens?

  • And there's not that many features, really.

  • We have a big button in the middle.

  • This is to reset the module, that this is the arm cortex M three process itself, and we have four little L.

  • Edie's, which are under user control.

  • The other two big components on here are just power regulation because we can provide power to this very the pins or via the USB, and there's an advantage to being able to power it by the pin.

  • So here we've got ground involved a gym, but because that's accepts the vaulted range between 4.5 to 14 faults.

  • Where is from us being?

  • We just get five.

  • It's more convenient sometimes to just power your system from one place, particularly in this case because the sober motors I'm going to use I'm going to power those at six volts.

  • They would work at five volts.

  • But I don't have the current capacity from the U.

  • S.

  • Be hope in order to drive all of them.

  • So I'm having to drive the servers from a separate power supply every time you buy an embed and I must support about 50 off them.

  • By now, you get a little card like this, so I'm quite a stack of these things.

  • But it's a really convenient thing to show you where all the pins up so we can see we've got power pins here, labeled in red on all of the other pins are music configurable.

  • I owe in one way or another.

  • So we've got two lots of espionage bosses on.

  • We've got to lots of new art on this side.

  • We've also got a You are on this side, too.

  • Well, look at you out for communicating between the computer on the control module.

  • We've also got some analog in pain.

  • So there's a built in analog to digital converter on here and that will accept up to six inputs.

  • It's it's okay it's not the fastest, and it's not the most noise free.

  • But for most applications, it's fine.

  • And with some twit Lee of the hard work, this sort of assembly level in my control, you can actually tidy that up quite a bit.

  • There's a single analog out employing the opposite.

  • There is a digital time low convertible.

  • We've also got two I scored.

  • See bosses.

  • They're usually quite popular.

  • I don't like them as much as SP I, but it depends on the application.

  • But most importantly for today we've got six pw em out pin.

  • So these are hard work and figured so.

  • The PW M is handled by the hard work, meaning we don't have to maintain that in software.

  • There's also us peace.

  • If you doing USB on the go applications.

  • These the pigeons use for that.

  • And finally, there's Ethernet.

  • At best.

  • It's a functional level.

  • Ethernet.

  • It's not for any high speed streaming.

  • The whole device is really only clock Kable at 96 megahertz, which doesn't sound like a lot, but it's enough to do a lot of interesting things for sure.

  • The embassy also really conveniently provides a regulated 3.3 faults output on will be using that to power the Bluetooth module.

  • This is the Bluetooth module.

  • I'm intending to use the D S D tec H c 05 Bluetooth serial passed through module with while a serial communication with button.

  • They says for Arduino, but doesn't matter.

  • It's just a Bluetooth module that gives us access to a U art.

  • And I've chosen this because I'm literally just going to plug it straight into the bread board and hope that it works.

  • I have a little USB dongle on my main computer and this is my Bluetooth module.

  • And I chose this just because of its simplicity.

  • It's entirely contained.

  • So here you can see we've got the Bluetooth antenna on.

  • We've got some interface checks to handle the radio.

  • I guess on on the back, it very conveniently labels what the pins are.

  • We're not interested in all of the what we're interested in his VCC, which will go to power from now.

  • We're gonna parrot from 3.3 volts.

  • Not the recommended 3.6 faults you can see here.

  • Exactly.

  • It's OK.

  • It works on dhe.

  • We've got the t, X t and R X d lives there.

  • The ur lives.

  • That's where our communication is going to be happening.

  • So the computer is going to transmit via Bluetooth to this module, and this module will convert it into three vault three level you are which the embed can understand quite naturally, the other pins.

  • I'm not too interested in what they do when you enter the world of embedded systems development.

  • One of the first things you'll come across is the need to have things very overtime in a kind of analog e type way.

  • But all you've got is a bunch of digital pins.

  • Well, one way to satisfy this is to use pulse width modulation, which sounds very complicated but is in fact, quite a simple thing.

  • If I create an axis which represents time on, I take two points along that access.

  • This is more commonly known as the period, because what I'm going to assume is that we're going to have some repeating signal between these two points.

  • Digital signals, of course, can only really be zero on Dwan.

  • Just to make this clear, I'm going to add in another timeline.

  • So I've got two sections of time here a digital clock is a signal that isolates between one and zero.

  • So, for example, it may look something like this.

  • The time that the clock is high is the same as the time that the clock is low on this.

  • Repeats for a P W M Perspective O'clock is P W M at 50%.

  • Let's consider a P W M A 25% Well, in this case, it's high for 25% of the period, but low for 75% of it.

  • And it repeats.

  • I'm sure you've already worked out by now.

  • But if we wanted something like 75% P W.

  • M, it's highly for 75% of the period on low for the remaining 25%.

  • So to specify a PW EM signal, we need two pieces of information.

  • We need the period, which is this duration of time, and we need the duty cycle.

  • There are variations of this depending on the polarity of your signals, but I'm not going to look into that today.

  • So let's program the microcontroller now.

  • Now, firstly, I must apologize.

  • Unlike Visual Studio, I don't have as much graphical control over how the browser Integrated development environment looks for embed, so I can't really change the font and zoom in quite as easily as I can in visual studio, so we'll just have to make do.

  • But all of the source code for this will be available in the getup and is Linka ble from the description below a blank embed program.

  • Looks like this on this is the environment have put on the dark theme, so I don't blind myself and it looks just like a C plus plus programming environments.

  • I've got some files and projects down here on the left.

  • I've got a coding window here and I've got some output window at the bottom on that.

  • This is the skeleton stub program.

  • You include embed dot H, which provides you with all of the tools and new Cilla sees of the board on it gives you an in Maine and says, Well, have at it.

  • You compress control and be or click build from the menu appear and it builds it and gives you the syntax error.

  • And this is all happening in the browser now, since we've just been looking at Peter, you am.

  • I think the first thing to implement is a simple PW AM exercise, so I'm just going to specify a pin called pw em out.

  • So this is an object which will facilitate the coordination of the PW em peripherals for specific pin.

  • I'm going to give that pin the name led Led one.

  • Actually, we're goes, we're going to blink one of the ladies on the board according to the P W M Signal on, I could specify which particular piece of hardware I want when I'm constructing this pin and on the embed conveniently it's led one now, thinking back to PW em if you em.

  • But they're two bits of information you need to specify.

  • The first is the period.

  • So on my pin object led one.

  • I'm going to specify the period I'm going to set the period to be one second.

  • I'm not going to specify the duty cycle by writing to that P W.

  • M.

  • Pin.

  • The duty cycle is a percentage.

  • So if I set this as no 0.5, what we should expect to see is the led blinking on enough at 1/2 2nd interval on because I'm old fashioned and I don't want main to exit just in case it resets the embed controller.

  • I'm just going to sit in a loop.

  • It's compile it.

  • So compiling it was very simple.

  • Well, actually, all have done was building.

  • But if I click compile, it will run through the build process on Dhe gives me a file to download, which we've just seen here on this file is called Robot arm dot lpc 1768 dot been, which means it's a binary file on That's the file that I'm going to Dragon drop onto the embed when it appears like a flash drive.

  • So I'm just going to plug the embedding.

  • You take my embed.

  • I'm going to insert the USB connected directly to my computer, and we could see it's powered up the embed on that This led here tells you that the bed has power.

  • The embed itself pops up just like a regular flash drive.

  • So I'm going to take the binary file that's just been given to me by the chrome browser on.

  • I'm going to drag it onto the flash drive.

  • And as you just saw on the camera, the led blinked.

  • That's telling us that the file has been flashed onto the memory of the embed.

  • I no need to press the button on the amber to reset it, and we can see now led one flashing with a 50% duty cycle on a period of one.

  • And that's just been done via P.

  • W N.

  • This doesn't mean we can flash.

  • The other led is, too.

  • So I'm going to duplicate this code for the four ladies on the board.

  • But I'm going to set the duty cycles to be different, so we'll have led to moving at 75%.

  • Led three moving at 25% on led four.

  • Moving at I don't know.

  • Let's pick something like 10%.

  • Click the compile button and straightaway.

  • There's an error, of course, simply because I'm not defined.

  • What the pins are.

  • Welcome to embedded.

  • Try that again.

  • There we go.

  • Success, and it's giving me the file.

  • So I'm going to drag that file onto the embed and program it Now.

  • You can see there's multiple files now on the M bet That's okay.

  • The most recently written thing to it is the thing that flashes.

  • So going back to our device, I'm going to reset it by pressing the button on the top.

  • We can see we've never led ease with different duty cycles, a bit tricky to tell which one was which.

  • But we can see that led four.

  • Here is a very brief pulse that was our 10%.

  • Where is led to was 75% led.

  • One was 50% and we see that extinguished before the 75% 1.

  • But we see the 25% 1 extinguished before the 50% 1.

  • So it is working on the period of the people here are all in sync.

  • I'm going to remove the other l E D's on Just show one last thing regarding Peter, we went.

  • We've set the period here to be one second, which is actually quite slow.

  • So I'm going to set that Toby 10 milliseconds instead on I'll introduce an additional variable time on in my wild loop.

  • I'm going to set the duty cycle for that particular pin to be a function off time.

  • In fact, specifically, I'm going to set it to be a sign of time.

  • But Signe will, of course, give me a value between minus one and plus one.

  • So I'm gonna add one to that and divide the whole thing by two.

  • I want time to increase, so I'm just going to add a little tiny bit to it.

  • Let's take a look.

  • So I just reprogrammed the embed on I've reset it, and what we see now is a nice, gently pulsing led one S o P.

  • W M is really used for whenever you want something to look analog e in a digital domain, the led is flashing on enough so quickly, and we're in control of how quickly it is flashing on enough that we could make it look like different intensities, a very common technique on anything where you see ladies with this sort of behavior.

  • Pulse width modulation is also used to regulate power efficiency in battery powered circuits, because most of the time you don't want your led on all the time.

  • It's quite sufficient, tohave it, pulsing it perhaps a 50% duty cycle to the human.

  • I'd still just as bright.

  • It's still usable tool, but it's only using 50% of the power you aren't stands for universal asynchronous received transmit, and it's a mechanism for sending and receiving data between two devices.

  • So here have device A and it's going to have an Rx pin on a t.

  • Exp in So it receives data from its our ex pin on will transmit data to its t.

  • Exp in.

  • This could be talking to another device.

  • Let's call it B, which also has on our X pin on the T X pin on again.

  • Transmits via T X on receives the Rx.

  • If it is agreed beforehand how A and B should communicate with each other.

  • Creating a you are it is very simple.

  • We simply take our X and connect it to T X.

  • Because this is a high level video, I won't go into too much detail regarding the nature of the signals that are being transmitted.

  • But this mechanism has been around for decades, and I don't think it's going anywhere anytime soon simply because it's so easy to use.

  • But it does require that both devices are talking the same language.

  • So one of the properties that will need to set is known as the board rate or bowed rate, depending on where you're from and this is a good agreement beforehand, that specifies how many bits per second are going to be transmitted along the Rx and T X lines, ones who specified this speed that which are you are will use for transmission.

  • We also need to specify the protocol.

  • Onda very common protocol is known as eight n.

  • One on dhe.

  • This tells the U.

  • R.

  • It's expecting a package of eight bits with one stop bit and no parity checks.

  • And so for transmitting a single bite across the U.

  • R, we may assume that there is a packet that looks a bit like this where the first thing that comes along is what's known as the start bit.

  • Then we have our eight data bits one, two, three.

  • So life six seven on dhe ate.

  • Then we have our stop it before we go back to rest.

  • This implies, of course, that for every eight bits of data we want to send or one byte of data, we actually send 10 bits.

  • Were the You are on the hard work will look after that forest.

  • We don't need to do that in software.

  • We just send the bite we're interested in on rely on the peripheral hard work to apply the start and stop.

  • It's for us, which means we can't simply divide the board rate by the number of bits that we want to send to give us a bites per second value.

  • In this particular instance, it's 10 bits per bite, so we can realistically send about 960 fights per second.

  • And that might seem horribly slow to those of you on ultra fiber megabit Internet.

  • There are other board rates.

  • You can choose their standard board rates, and basically they follow the old modem speeds.

  • And there's a reason for that.

  • But a typically high end board rate made look something like 115200 You can go a bit higher than this, but real world starts to play.

  • An effect on your protocol at the length of the cables need to get shorter.

  • The nature of your circuits need to be ableto handle high speed digital signals, but also the system processing the packet at either end also needs to be much faster because even though here we've got a very slow clock speed compared to the microcontroller that peripheral its handling, the U.

  • S.

  • Has to have lots of individual clocks Perbet in order to work out what they are so very quickly, you can see that we do need fast clocks, even tow handle, low speed you art.

  • But thankfully for today, the embed is going to take care of all of that for us, in fact, and how do we know would do, too?

  • The take home message from this is you are two very simple to use on.

  • It's such a ubiquitous mechanism of communication.

  • Nearly every device you buy will have the capability to talk to something.

  • Very.

  • You aren't even that super flashy new PC you've just bought.

  • If it's got a comm port or it's got headers on the motherboard for a combat, it can talk very.

  • You are in my robot arm application.

  • I'm facilitating the ur via Bluetooth.

  • The actual data transmitted via Bluetooth doesn't look really anything like the U R signal, but the Bluetooth module will reconstruct it into a U R signal that my embed module can understand.

  • I could, on the embed also used the USB interface directly.

  • This is the one that's plugged into the computer to make it appear like a flash drive.

  • You need to download an additional driver to do that, but it will make the U.

  • S B port appear like a virtual comport.

  • Now I think it's time to look at building the robotic arm.

  • I did a full video about this.

  • About it was a live stream Q and A session.

  • But I've convinced it now into a couple of minutes for you to have a look who the server motors provided with my robot arm, where the MG 996 are all metal gear, servo motors.

  • And it looks like this.

  • It came with a load of peripherals I didn't actually need.

  • But the servo itself is this junkie box in the middle, where the connector for power, ground and signal the data sheet itself is dreadful.

  • But it does have some useful information.

  • So the operating voltages 4.8 volts to 7.2 bolts.

  • That's okay.

  • I'm in turning to you six faults, but more worryingly is the ruling.

  • Current is 500 millions, and it can stall at 2.5 amps.

  • This is a problem because I've got six servo motors, so let's assume that's all six running at 500 millions.

  • I need a three amp power supply.

  • I don't have one.

  • I only have a 2.5 amp supply, so I'm gonna have to cross my fingers and hope that that works.

  • Servos work using a pw em signal on.

  • We can see here that the period of the PW M is 20 milliseconds or 50 hertz, and you'd expect the point of the signal would be a 0% duty cycle.

  • Would be one extreme of the range of the servo on 100% duty cycle would be the other.

  • But that's not the case.

  • And in fact, the entire range of the servo is crushed down into a small range of the duty cycle.

  • As alluded to by this wonderful sentence position 1.5 millisecond pulse is middle 92 millisecond pulses.

  • Middle is all the way to the right.

  • Minus 91 millisecond pulse is all the way to the left.

  • I think there's been some translation going on here.

  • However, what this is saying is that one extreme is one millisecond.

  • On the other extreme is two milliseconds on.

  • Of course, the middle, the zero position of the servo is in between the two.

  • So looking at our PW M signals again, let's assume they start somewhere.

  • Here are the stuff of the period.

  • Is here android to here?

  • We know that the period was 50 milliseconds.

  • What it tells us is that 90 degrees So that's the server all the way to the left.

  • Let's say, had a duty cycle where the pulse was one millisecond hi, zero degrees at a pulse that was 1.5 milliseconds and the full plus 90 degrees.

  • All the way to the right was two milliseconds.

  • And so the active range of our servo motors is quite narrow relative to the period.

  • And this means we're going to need to do some maths to do this scaling forest.

  • So let's say we have a target angle on.

  • We'll call at 45 degrees were also given a duty cycle men as being 0.0 01 a duty max off 0.2 So the range of the duty cycle is just one millisecond.

  • I also have an angle men of being minus 90.

  • So that's to physically stop the motor from trying to damage itself and an angle max of plus 90.

  • So with this information, we can develop the relationship between the requested angle on the requested duty cycle.

  • And so bringing all that together we can work out an equation to give us the duty cycle for a given angle First will normalize the angle according to its range.

  • That's angle divided by angle Max take angle men, given that angle could be positive and negative.

  • This could give us a value between minus 0.5 and plus 0.5, so I'm going to offset it by 0.5 to bring it between zero and one.

  • I now want to scale that to the applicable duty cycle range, which is simply duty max minus duty men.

  • But the minimum value we can give it is duty men.

  • So I need to offset all of that by duty minimum going back to a blank embed program.

  • I'm going to start writing the code for the robot arm.

  • Good to set up the hard work first, so I know I need all six p W M pins labeled Pin 21 through to 26 to be configured as Peter.

  • We went out on in into Maine The first thing I'm going to do is specify the period of the PW m for each of those pins.

  • In this case, 20 milliseconds, 50 hertz.

  • In my main function, I'm going to want a loop that doesn't end.

  • But this time I'm going to want to do things inside the loop on the two main things I want to do are going to be read from the U art and right duty cycle two pins.

  • I appreciate not all of these air that visible.

  • I do apologize again, but because I see this is being the start off several robotic arm projects.

  • I want to create a class that represents the joint.

  • And given that this is a C plus plus environment, I can do just that.

  • Now, all of my servo motors have the same physical restraints on the duty cycles regarding the P W M.

  • So I'm going to store those is constant in this class on, you may notice if your eagle eyed enough that these values don't reflect what we've just seen on the data sheet.

  • Don't forget these are percentages off.

  • The period, not times directly on DSO hour period was 20 milliseconds This is 11% of 20 milliseconds, which is about 2.2 milliseconds.

  • And that's implies that this one is indeed 3% of 20 milliseconds, which is about 0.6 milliseconds for our servos.

  • I worked out these values by driving a servo to his extremes and just backing itself a little bit.

  • And I think that's a good lesson for any embedded systems design.

  • Don't ever assume anything.

  • If you need to do an experiment, do it in my joint class.

  • I also want to store some values that represent the status of the joint, So I want a target position.

  • Where is the joint moving to the actual position?

  • Where is the joint?

  • Currently on dhe?

  • Some, maybe some constraints on the minimum of maximum angles.

  • That that joint can be set to the first method I'm going to add to the class is set target, which takes a floating point angle in degrees.

  • Aunt clamps it according to the Joint men and Joint Max variables on just for Kicks on, because I like the abuse in the comments, I'm going to add a get target, too.

  • Next, I'm going to add a function that returns the duty cycle for a given angle.

  • Given the constraints that we have.

  • And I showed you the mass for this a minute ago.

  • This means I can know how to constructor, and I'm going to have a constructive that takes some default values in this case, a minimum angle, a maximum angle on a default position on I'm also oddly for now going to add an update position function on All this is going to do for this video is take the position on set it from the target so the user will use this joint class by setting the target, updating the position on, then calculating the duty cycle based on that position.

  • The reason I've added this inn is I think, in the future I want to play with slightly more complicated trajectory planning based upon what's his requested of the servo on.

  • I'd like the microcontroller to handle that rather than the host needing to calculate it all.

  • But since this is a very simple video, I'm just going to set the position directly to the target.

  • In our main function, I'm not going to create an array of six joints and again the experimentation I've determined that actually, you don't want them all.

  • A zero.

  • When the robots starts up, it starts up in a rather strange pose.

  • Instead, I've determined that these values are quite useful for making the robot straight vertically up right.

  • And this is where the physical dynamics of the robot are coming into play.

  • Not everything is ideal in the real world, and so sometimes there are bits of noise on.

  • There are some offset, particularly offsets with how I assembled the servos because I had no realistic way of lining up with servers were without them being powered.

  • So once I've read the commands, fear that you are, I want to update all of the positions of my joints on.

  • Ultimately, I want to write those to the P W M pins.

  • So just exactly how are we going to communicate with our robot arm?

  • Given the simplicity and low speed connection of our you are, I want communication to be a simple as possible and uses few bites as possible.

  • But I also wanted to be self synchronizing, and that's quite an important thing.

  • When you're a hobbyist developer, things crash, things go wrong.

  • Power supplies explode components burnout, which means very quickly a system becomes out of sync.

  • On as you can tell, I'm speaking from experience.

  • There's nothing more infuriating than needing to start up your experiment or your build in a particular order in order to get things to talk.

  • So one of the things I always try to do is make sure that communication is a asynchronous in a way, so it doesn't really matter what order things air powered up in on.

  • We should also be sure that any data that is left in any buffers anywhere isn't going to cause any problems.

  • We could have a sequence of bites that represent an instruction.

  • So perhaps we specify a joint number followed by a command followed by a value.

  • This is a valid option.

  • Why not?

  • So we specify.

  • We want to open the claw.

  • We want to, in this case move because we may have different move options later down in the line on, we want to specify a particular angle, all of which represented as three bites on paper.

  • This is excellent, but in practice does suffer from some problems.

  • Let's assume one of the bites didn't make it across the communication, perhaps because the device has been powered up at just the wrong time.

  • If our program on the microcontroller is always expecting three bites to occur in a particular order, it will naively just assume that those bites are correct.

  • Even if they actually started here with the Move command, there's two scenarios here that can play out.

  • Firstly, this third bite might never be received, so the microcontroller simply stalls.

  • Secondly, and perhaps even worse is this move.

  • Command could be interpreted as a joint number on the value could be interpreted as whatever symbol was used to represent the move command.

  • So certainly we've got a situation which is quite unsafe.

  • We could either stall the microcontroller by starving it of data or send it commands that interprets but the quite dangerous commands to actually execute.

  • So it's worth spending the time to think about what is it that your application actually requires?

  • So for my robot up, I've devised a to bite protocol.

  • The first bite that gets sent is going to represent the joint number on the second bite that gets sent, is going to represent the angle for the target of that joint.

  • I'll call that joint theater, but I'm going to explore the nature of what the data in these bites is going to represent.

  • I know that my joint angle could only sensibly represented by minus 90 two plus 90.

  • I'm going to do something a bit strange here.

  • Having a negative number means I might have to worry about sign bits and stuff like that.

  • So I'm going to offset all of this by 128.

  • That really means I have an effective range off 218 as a maximum on 38 as a minimum.

  • It's very easy for me to subtract 1 to 8 from this to get back to the original 92 plus 90 but this also gives me something interesting.

  • It means I've got space either side of this range with nothing in it.

  • Burr with me.

  • I've only got six joints in the system, and so my 026 value never overlaps with the range required by the Joint Theater.

  • This means I can do a check for every bite that comes in.

  • I can check if the bike's value is less than 10 for example, then I know that I'm representing a joint number, but if it is greater than 10 then I know I'm representing a joint theater this way.

  • It doesn't matter really what bite the system receives first because it let's say it receives a joint angle that's going to be greater than 10.

  • It's just going to reject it.

  • So just by examining the data, we've come up with a way to make it robust against starter border.

  • Yes, bites might go missing, but ultimately it's not going to damage your stall.

  • Our system win win.

  • The embed has access to the U R two pins directly, but you really want to use them directly, probably always want to run them through a buffer first, just in case you embed is doing something else and can't respond to the pins being activated for you.

  • Our transfer.

  • So I'm going to use a library that's provided by some other person in the embed community, and that's one of the brilliant things about the embed community.

  • But to handle that buffer for me.

  • So I'm going to go to my robot arm Project Import Library on go from Import Wizard, which pulls up this window and in here.

  • The lively that I'm after particularly was going to type in ur and click Search and we'll see what it comes up with on the 1st 1 comes up is buffered serial, so I'm going to use that on to select it and click import now.

  • The nice thing about the embed environment is that it's basically also get in the background so all of the libraries and things can be updated automatically.

  • And if somebody else in the community changes their lively, I get a little notification in here that says This is ready for update.

  • But the buffered serial Libby has given me two files dot h and dot CPP, So I'm going to include the dot h file at the top on.

  • I'm going to specify a buffered serial object.

  • I'm simply going to call it you art on DDE.

  • I'm going to pass to that the two pins I'm using for receive and transmit.

  • I could also specify to use the USB connection, too, but you need to download a driver for that.

  • But in this case, I'm going for two regular pins because I'm just going to connect those pins directly to the Bluetooth module by default issue.

  • Art is already configured with a board rate off 9600 an eight n one protocol, as is the Bluetooth module.

  • So I need to do nothing else in order to use it.

  • So I'm going to go down to my in Maine and start filling in how we read from the U R.

  • Firstly, I'm going to create a temporal variable called Target Joint on I'm going to interrogate.

  • Are any bites available in the buffet for my you art?

  • And that's done with the readable function.

  • If there is a bite available to read, then read it.

  • Please answer.

  • Get, see if the value of C is less than 10 then we know that that's our target joint.

  • And if it's not less than 10 we know it represents a joint theater.

  • So I'm going to take the joint object for the target joint we've just temporarily stored on Dhe set its angle remembering toe offset by minus 128 to bring it back down to a minus 92 plus 90 range.

  • And that's really it.

  • That's how simple our embed program is going to be.

  • Obviously, having a microcontroller unit and Bluetooth module on their own is not going to do anything very useful.

  • We need to somehow connect them together.

  • And to do that, I'm going to use prototyping bread board.

  • This heap of spaghetti is the bread board.

  • The diver pre wired, ready for arm.

  • If you're not familiar with bread boards, the way that it works is all of the dots.

  • A longer particular row section are connected.

  • So these these are all connected and these are all connected and these are all connected.

  • But as you go down the columns, they're not connected.

  • And this allows you to conveniently create quite complicated circuits where multiple wires are connected to single locations.

  • Now the Bluetooth module lives over here, so I'm gonna make sure that this red wire, which is my VCC the power for the Bluetooth module is connected to the same row as the power in on the Bluetooth module.

  • So I'm just going to push that and the big, empty space in the middle here.

  • His worthy embed is going to sit.

  • It's it's this way around on.

  • If you remember from the car, all of the people you ever show the car.

  • All of the P W M signals are along the bottom right off the module.

  • The little pink box there.

  • It's not visible on the camera, and they correspond to these six cables here.

  • So I'm going to make sure that that's pushing properly on the lined up.

  • Yeah, almost were.

  • Click.

  • So the people you M is now coming out of the module on going to this header Here, this is on an eagle 2.54 mil pitch header or 0.1 inch to you Yanks on.

  • I'm using this to connect to the individual server connections.

  • I have six servos on each server has a feat pin connector.

  • So here I've got 18 pins.

  • The correspondent in orders repeats of sequence off signal followed by power, followed by ground signal power, ground signal, power ground, etcetera, etcetera all the way to the end.

  • And I'm taking the Paran grounds directly from the input somethingto power this board with a six volt power supply and that gets split from here so the power of the grounds go straight to the servos.

  • Andi.

  • Then it's also split to the embed modules, the embed models being powered off six faults, too.

  • But it's okay with that.

  • The module itself will provide a three vault three output for me to power the Bluetooth module because I don't want Thio overpower the Bluetooth model, even though it says it is parable by six faults.

  • If I have any problems with it, perhaps I can power the Bluetooth module directly off the supply to however, the servo supply is likely to be quite noisy and unstable simply because it's got motors attached to it.

  • Given that I know nothing about the quality of the servos for the motor aficionados out there, I don't really know if they have any capacity for handling back drives.

  • So if something some inertial load drives the server, I could quite easily see my power supply rail spike quite highly here.

  • And I don't want that spike to propagate onto the Bluetooth module.

  • No, that's got a maximum of six votes.

  • So I'm using the regulated supply off the embed to provide food bought food.

  • Nice, nice and isolated from the rest of the system.

  • Here is one of the connections from the server on orange was signal Reddy's power brown his ground so they're just going to connect directly onto these three pins like so So here you can see it fastens thesis circuit board to the side of the road water because the cables aren't quite long enough on it's still that the USB attached you to the moon.

  • But I'm also now just going to switch on the power head out that way because if you remember, the first thing that's our embed is going to do is settle the target positions to someone in zero of the range reaches the servos.

  • There we go.

  • That's quite exciting with it.

  • Let's not work on making the host application on.

  • We're back in familiar territory now.

  • This is a pixel game.

  • Engine instance were constructed to 400 by 400 pixels, where each pixel is to screen pixels wide.

  • So it's only going to be a small window.

  • But I've got overrides for the unused create function and on news update on, I've also added one for unused destroy, which, if you didn't know, already exists.

  • It's therefore closing up when you click the close button on.

  • I'm not going to dwell on this too long, really.

  • I'm going to be quite quick going through the code.

  • What I want to do is present a series of sliders that control each joint, and to do that, I'm going to do a first for the channel.

  • I'm going to use some third party code on this is a gooey library extension created for pixel game engine by a member of the disco community called Sleeping Bear.

  • He also has a YouTube channel, and I'll put links to both this code on his channel in the description below on This just allows me to quickly throw some familiar gooey components on the screen.

  • So I'm going to add, on instance, off his gooey container object and in my own use a create function.

  • I would add six sliders, one for each of the joint, so I'm specifying the X and Y location of the slider on its length, and I'm also going to specify some default values.

  • Now the sliders in this naive implementation go from 0 to 100.

  • Regardless, the length is the physical length on the screen, so I'm going to take the 0 to 100 on convert that to minus 92 plus 90.

  • So the numbers on the screen are accurately gonna reflect what angles the joint a rat.

  • But all I'm really after here is a quick slider in on news update.

  • I need to tell the gooey components to update themselves.

  • And then I'm going to clear the screen to Walgreen in this instance on, I'm going to tell the jury to go and draw itself.

  • So the gooey extension is really quite nice.

  • Andi encapsulated like that.

  • I don't have to do anything else.

  • It's all going to look after itself, but it's in unusual update.

  • I also want to do some interesting things.

  • So the first thing I want to do is get the angles from all the sliders.

  • Well, I've got six sliders, so I'm going to create an array of six floats, which represents the angles I'm interested in on.

  • Once the jury has been updated, I'm going to iterated through all six sliders, get its value on scale it to between minus 90 and plus 90.

  • But what we're really interested in doing here is transmitting this value to our embedded system on this is where things are going to get a bit Windows e.

  • I'm afraid it is a similar process on Lennox with syntax is a bit different, given that I've included as part of the pixel game engine windows dot age.

  • In this instance, I've got access to various operating system file routines on opening a Comm Port is really simple, in fact, to your program is just going to look like a regular file stream.

  • So I've created a handle h common.

  • Set it to Noel Pointer on din on user create.

  • I'm going to open the com port now.

  • My system.

  • The com port is calm.

  • Three.

  • It will be different on different systems.

  • You'll have to look at device manager or similar to work it out.

  • But creating the compost is actually quite simple.

  • It's done in a single line of code.

  • I'll talk you through it so it's the create file function and you pass to It's the address of the file.

  • In this case, what we want is calm.

  • Three on we tell it, we want to build to read and write to it.

  • We're not actually going to read from it in this particular application, though, if we wanted the embedded system to return information to us to display, we would want to read to it, so I'm going to leave that there.

  • And then we specify typical file attributes and parameters particularly want to open existing.

  • We don't want to try and create a new com three part.

  • If that fails, it doesn't manage to create it.

  • We just want to return.

  • False at this point in the application will exit.

  • So that is it.

  • That is all that's required to open the com part.

  • We just treat it like a file specifying the properties of the U.

  • R requires the use of the rather curious D C B structure.

  • I'm not sure what that stands for if you know, please enlighten me, but I'm going to assume it's something like Device Control, buffer or device control block.

  • But anyway, this structure contains the properties that we need to set to specify the you are now.

  • The compote will already have some properties associated with it, So I'm going to grant those using the H com handle that we created earlier on.

  • I'm going to overwrite the properties that I'm interested in setting from my system, namely the board rate of 9600 the number of bits in our bite a stop bit on the fact there's no parity.

  • This is the eight and one specifications.

  • Then I'm going to rewrite this structure back out to define how that comport should communicate.

  • When you're done using a comm port, you probably do want to close it.

  • This is very simple.

  • It's just a call to the clothes handle function.

  • There'll be an equivalent set to all of these functions on Lenox.

  • Writing the command via the com Port is quite simple.

  • We've got six joints, and we know that our protocol is going to be two bites per joint, so I'll create a character buffer 12 bytes long on.

  • I'm going to populate that buffer with all of the information required.

  • So the first bite, all of the even bites, including zero are the joint number.

  • The odd bites starting from one of the joint angle, offset by 128 because remember, that's what our protocol requires.

  • So this will give us a buffer off joint number, joint angle, joint number, joint angle, joined number Joe angle all the way for all six joints.

  • I then want to periodically right this buffer to the system now on user update is going to run very, very quickly, Far faster than the rate are you art can communicate at.

  • So I want to do something on a particular tick.

  • I don't want to do it every frame on.

  • I like to do this by accumulating f elapsed time.

  • So our creator variable called f accumulated time on Only when that accumulated time variable is over a fixed amount.

  • Do I want to write anything to the hard work?

  • Remember this point toe Also, subtract your weight amount from accumulated time So this gives you a very precise tick regardless of the frame rate of the application right into the device is very simple.

  • I need a tempera value, Kel, be w which is going to represent the number of bites that have been successfully written by the following command, which is right files.

  • This is a standard file, right command on windows.

  • It takes the handle of the com port.

  • It takes the buffer, how many bites we want to write, and it will return to us.

  • How many bites it successfully written.

  • Now, if I was doing this with the professionalism of somebody that works in industry I would check to make sure that the number of bites written is actually how many I think it is on.

  • If it hasn't been, let's say it only written five bites out of the 12.

  • I would then try and call us again, starting from the fifth position on working my way through the buffer.

  • However, I'm reasonably confident it's going to successfully right all 12 bytes.

  • This is not a particularly large demand.

  • So in the name of clarity, I've not put in any book for checking here, and that's fundamentally our program.

  • We get values from sliders that are going to be on the screen.

  • We create a command string from the values of those sliders and the angle of our joints on.

  • Then periodically, in this case, every 50 milliseconds, I'm going to write that command string to the hardware.

  • So I've just pounded the robot and you may hear a faint buzzing noise in the background.

  • That's the servos.

  • I'm now going to run the application that we've just created on, we can see sort of jolted into position.

  • That's okay, that's all of our slider values being centralized.

  • So I'm going to start at the top with the claw.

  • Second, move the slider on.

  • I get an instant response from a clock.

  • The next joint down rotates the claw.

  • The joint after that is like a wrist joint that could move the core backwards

Hello for this video.

字幕與單字

單字即點即查 點擊單字可以查詢單字解釋

B1 中級

為無線機器人手臂編程 (Programming a Wireless Robotic Arm)

  • 7 0
    林宜悉 發佈於 2021 年 01 月 14 日
影片單字