Programming for Robotics: Getting motion | Zoe Lambert | Skillshare

Programming for Robotics: Getting motion

Zoe Lambert, Programmer, Maker

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
10 Lessons (59m)
    • 1. Introduction

      2:02
    • 2. Materials

      1:16
    • 3. TinckerCAD Circuits

      5:50
    • 4. Arduino Software Installation

      3:13
    • 5. Getting Motion: Servo

      12:58
    • 6. Getting Motion: Motors part 1

      12:05
    • 7. Getting Motion: Motors part 2

      12:36
    • 8. Good programming practices

      2:42
    • 9. Troubleshooting

      4:17
    • 10. Conclusion

      1:39

About This Class

369b8dfc

In this course, you will learn how to program an Arduino to get things moving and good practices to be using when programming for robotics. This course is good for beginners, who have little experience using an Arduino and programming to get motion. This is a good place to start if you are looking to build a robot army or want to create a robot friend.

The programing language that will be used in the course is the Arduino programming language, which is based on c/c++. If you already know some of the Arduino programming language or some c/c++, then you are already off to a great start. If you don't know any programming, Then that is alright also because this course covers the basic of what you need to know.

While it is useful to have the items from the materials list to work on the course project and try the different demos demonstrated in the course, it is not necessary to participate. In the course, You will learn how to take advantage of a free program called tinkercad circuits (https://www.tinkercad.com/circuits) that allows you to program an Arduino and simulate running it without actually having to own one.

0d9f67e7

Music in my course is from:

Fretless

Music from https://filmmusic.io:
"Fretless" by Kevin MacLeod (https://incompetech.com)
License: CC BY (http://creativecommons.org/licenses/by/4.0/)

Fireflies and Stardust

Music from https://filmmusic.io:

"Fireflies and Stardust" by Kevin MacLeod (https://incompetech.com)

License: CC BY (http://creativecommons.org/licenses/by/4.0/)

Relaxing Piano Music

Music from https://filmmusic.io:
"Relaxing Piano Music" by Kevin MacLeod (https://incompetech.com)
License: CC BY (http://creativecommons.org/licenses/by/4.0/)

Transcripts

1. Introduction: Hello. My name is Zoe Lambert. I am a programmer and the maker who has a passion for robotics. Welcome to my programming for robotics Course. For this course, you don't need to have any experience. You can learn the concepts without having to own any of the materials, and this course will help you get started building robots in no time. The course objectives are for you to learn some good programming practices, gain knowledge on the basics of programming in our greenoe, to move a motor in the servo. And for you to understand how to find and fix problems that you may encounter when pursuing these kinds of projects, the videos in this course will cover what materials will be used. How do you stinker cat circuits? Software installation for programming? The urge we know getting motion from your motor and servo, an overview of good programming practices and how to troubleshoot your projects. I hope that you enjoy the course. This is where the amazing world of robotic starts using the concepts that I will be teaching in this course. There's an endless amount of possibilities for what you can build. Make sure to try the class project at the end of the course and share with the community what you come up with 2. Materials: in this video, we will be going over the materials that are used in the course. You do not need to own all of these materials to be able to participate in the activities. Some of the basic components that you will need are a computer with Internet and our Guerrino and the Arduino programming cable. For the getting motion examples, you will need a servo, an H bridge motor controller, a DC motor, a nine volt battery jumper wires and the bread board. 3. TinckerCAD Circuits: in this video, I will be explaining what Tinker Cat Circuits is and how to use it. Tinker Cat is a free program that allows you to simulate circuits made up of basic components. This is great for seeing your ideas come to life without having to buy any equipment. To get the Tinker Cat circuits, open up your Internet browser and go to tinker cat dot com slash circuits. There will also be a link in the course description. If you would like to just click on that once you get to the Tinker Cad circuits page, scroll down to the launch Tinker Cat circuits button. Click it and you will be prompted. The sign it. If you do not already have an account, then you will need to make one. Once you are signed in, you'll be brought to this page, which shows you all the previous circuits that you've seen. If you haven't made any yet, well, this page is gonna be blink. So to get started on a new circuit, you go to this button that says create new circuit and it brings you to the simulation software. Now when you sign in, it may automatically bring you to this page with a random name for your project. I'm gonna go ahead and change this project, to be example Project. So that way I will be able to find it easily later. Tinker Cad Circuits has lots of components available to you over here on the components bar . There's many things for you to choose from. If you go to all, you will be able to see everything that's available to you, including general categories for them. So let's go ahead and try out an example in Tinker Cat circuits. We're just going to get a motor to spin using a battery. So I'm going to go to the output section of the components panel and grab a hobby gear motor. Then I'm going to go to where the batteries are, which are under power. Down at the bottom. I'm gonna grab a nine volt battery and place it into my workspace. Now I want to connect this part of the nine volt battery to this part of the motor. To do that, I just click where I want a wire to start, and I can click in every spot that I want it. The wire to bend until I make it over to where I want to connect it to. This little red box will pop up when you can connect that wire there and ended Now, I just connected the negative on the battery to the negative on the motor, and that is usually represented for the black wire. So that's what I'm going to do now. I'm gonna connect the positive on the battery to the positive on the motor, and I'm going to make that wire read. Now, this components bar over here is kind of in my way. So I'm going to go ahead and close that using this arrow. Now we can hit the start simulation button up in the top right corner. As you will see, our motor has started spinning and were given the rpm's of the motor, which is how many times the shaft of the motor is rotating per minute. Lastly, what I want to cover is how you would program something if we brought in a Arduino and we wanted to use that well, we can program in Arduino so we click on code and I like to use the text code. So I change it to text. It gives you a warning that your blocks are gonna be deleted. But that's OK. So now this code is already written for us because this was a pre made circuit and ah, we can just start the simulation. But this is where you would normally type your code for whatever circuit that you made. So this code just makes us led Blink on and off. That has been a basic overview of what? Tinker Cad circuits. It's we'll be using Tinker Cat circuits in this course for both e getting motion from a servo and getting motion from a motor. This way, no matter what, you'll be able to participate. I will also be showing physical demos of both these activities. So that way, if you do have the parts in real life, you can do it that way. Also 4. Arduino Software Installation: to be able to To be able to program your Arduino, you will need to download the artery. No, I d software. Do you have the software? You're gonna need to go to the Arduino website. I have provided a link in the course project description. Under resource is, once you have gotten to the page, you will scroll down and you will see download. There'd be no I d click on the download that is for your computer. I have a windows computer, so I will Duthie Windows installer. It will ask if you want to contribute and you can do that if you would like. And if you wanted to, you could say, contribute and download. You also can just down with this software without contributing at by clicking the just download button. It'll ask if you want to save the file Click Say file. Once the file is saved, click it. It will start installing the Arduino I D on your computer Agreed to the license agreement. Click next and choose where you want your Arduino software to get. I am good with that, so I'm gonna click Install. It's going to go through the installing process so you might have to wait for a little bit for this to finish. Once it has completed its set up, you click the close button and you can open up your heart amino software. Now, once it is finished, you can open up your Arduino software and you will be met with an empty sketch. This is where your programs will go next. What we need to do is configure our Arduino. To do this, you will first need to plug the Arduino into your computer. Once you have your Drina plugged in, go to tools board and make sure that it says the board that you are using. I am using an Arduino uno, So that's the one that I want. Then go to port and make sure you click on the com port that is popped up that your Arduino uno is connected to. Now you're ready to start programming 5. Getting Motion: Servo: it is finally time to get things moving. In this video, we will be creating this circuit and making this code that makes a serval move between it to end positions for one second. Here is what you're several will be able to do by the end of this video. It may not look like much, but it's the beginning to a great start in robotics. We will start by creating a new project and tinker cat circuits. Let's name our project something that we can remember. I'm going to name this project kidding Motion service. Next, we need to pull in our components from the components board that we will be using. For this example, we only need two components in Arduino and a micro servos. First, let's pull the Arduino in. I'm rotated to be in a more desirable position. Next, let's bring in the micro server. I am also going to be rotating this to be in a more favorable position. Now we have all our components laid out. We can close our components panels and start wiring up our circuits to wire up our servo toward. We know we need to connect three cables from the servo 23 pins on the Arduino. Our servo has three wires, a ground wire, a power wire and a signal wire. The ground wire on the servo will connect to one of the G N D. Pins on the Arduino. You have three options. Go ahead and pick one. I'm going to pick this one right here to connect these two. I'm just going to run a wire toothy. Other pin ground is usually represented with a black wire. So that's what I'm going to use next. You want to hook up the servers? Power wired. We wanna I hope this wire up to the artery knows five gold pin. This is what's going to give the servo power to be able to move this wire. I'm going to represent with Red. Lastly, we have our signal wire. This wire is what communicates between the Arduino and the servo. What position to move the server warm too. This will need to go into one of our digital pins on the Arduino. The digital pin needs to be a pete of you lumping. So we're going to use one of the pins that has a tilda in front of it. I am going to be using pin 11 now. Our circuit is complete and we can move on to programming it to program the servo. We will go toothy code editor and go to the text option. I'm going to get rid of the code that is inside the set up and be like functions because we do not need it to program the servo theory. No need to special library that tells the urge. We know how to control the server to use this library, we say pound include servo dot h. The s in servo needs to be capitalized because this is the name of the library that we're importing. Next, we need to give our servo winning. I'm going to Neymar servo servo one. And to do this, we have to first say servo and then specify the name Servo. Once our next bed, IFCO will go into the set up function. The set of function is only Ram once when you first start the program. So we only wanna put code in here that we want to be ran once at the beginning of the program for their Drina to know what then controls the servo we need to tell it. That's what we're doing in the set up function. We are telling the yard we know that our servo is connected. Depend 11. When we tell the old we know what pain are servo is on. This is cold. Attaching the servo to attach the servo. We need to say our servers name, which is servo one dot attach and then specify what pin were using. We're using pin 11 so we'll tape 11 Now we will move on to the loop function the liver function. We'll run over and over again until the simulation has stopped or until it reaches code. That exit salute. Yeah, in the loop function. This is where we're going to put our code that tells the servo to go to position 1 80 wait for one second, go to position zero and then wait for one more second. You'll start by telling our servo to go to position 1 80 that for us to tell the Arduino to set the servo to physician 1 80 we need to tell it are servo name and what we want to do, which is right to the service we are writing to the servo 1 80 because that's the position we wanted to go to next. We need to add in a delay. The delay tells the servo how long to hold the position for? So we want to stay at position 1 80 for one second to do this, you tape DeLay 1000. The delay function Nard, we know is done a milliseconds. So 1000 represents one second and 500 represent half a second. Now we need to tell her servo to go to position zero and wait for one second. This code will look very similar to our code that sets the servo to 1 80 because it exact because it is exactly the same. Except for we put zero in the right function instead of 1 80 Don't forget to add in the dally to make a wait at position zero for one second that our code is now done. If you click on the start simulation button, you will see the servo move from position 1 82 Position zero with a one second delay between we can now move on to creating this circuit in real life and getting our real life servo to do the same thing. Go ahead and grab your servo, or do we know and a few jumper wires? If you're going to be doing this activity in your life, your wires do not have to be the same colors as mine. I just used what I could find. Go ahead and hook up your servo to the Arduino in the same way that we hooked them up in Tinker Cat. Make sure that your signal wire is going to the correct pin. Your ground wire is going to the ground pin and your power wire is going to the five Volts pic. No, Instead of programming the servo from scratch, we can go ahead and just copy and paste the code we already created in our project on Tinker Cut and put it into the artery. No, I d. Here I have a brand new Arduino I d sketch. I opened it up by thing file. No, you can get rid of the code that is already in there and just paste in the code that we created on Tinker Cat. Make sure your Arduino is hooked up to the computer. Once you have your Arduino hooked up to the computer all you have to do. If it's the upload button, save your sketch. And now your servo should be moving once the code is uploaded to yard Reno and it says done uploading Congratulations. You just got your servo moving using an Arduino. 6. Getting Motion: Motors part 1: getting motion from a motor is a vital part of robotics. There are many ways that this can be done in this video will be covering one of them. We will be creating a circuit using an H bridge, motor driver and an Arduino. Get a motor moving. To be able to understand the circuit that we're creating in this video, you first need to understand what the l 293 D H Bridge motor driver is. The H Bridge motor driver is a chip that helps the Arduino controlled the motor. Without this chip, the art arena would only be able to control the motor at one speed and in one direction. This is not very useful when it comes to robotics. The H Bridge motor driver can run the motor in both directions and at varying speeds. It can also control either to D C Motors or one stepper motor. This chip has 16 pits where each pin has a job that it needs to dio First pins that we're going to look at are the enable pins. The enable bins hook up to a Pete of, um, signal on the aired. We know and allow you to control the motor speed. There are two enable pins one for each DC motor that the H bridge motor driver can control . Next we'll look at the inputs. The's inputs are connected to the Arduino. This is what we set too high or low to tell the motor which direction to spend Input wanted to goto one motor input three and four go to another murder. Next we have the output pins. There are four l put pins. I'll put one and to go to one motor. An output three and four Go to the other motor. The l put pins are what Connect to the motors terminals and allow the urge we know to be able to move the motor. Next we have our ground pins the's air what connects to the ground of the Arduino or the bread board that we have the pin connected to. Lastly, we have the VCC one into all this is is a power input where you would connect your battery if we take a look at the chip Weaken Split it right down the middle where the left side controls motor one and the right side controls motor too for our circuit. We will only be controlling one motor, so we will only be working with the pins on this side of the chip. Except for the ground pins, all the ground pins will need to be connected to the circuit board. Now let's get the circuit wired up. Let's take a look at the circuit and code that we will be working on in this video. Here is a circuit that will be creating the code that we will be making will turn the motor in the positive direction for five seconds. Then it will turn the motor in the negative direction for five seconds. Thes two motions are the basis of every robot that you've seen being able to get a motor to move in the direction that you want it to. If we click the start simulation button, you will see this working. Currently, the motor is trying to spin at 50 rpm's. Let's go ahead and get started. As always, we're going to create our circuit and tinker cat circuits first. So open up a new Tinker Cat circuits project. Make sure to name it something that you can remember. I'm naming mind getting motion motors, the components that you'll need for this activity are and aren't we know? Ah Hobby Gear, Motor Bread board and a H bridge motor driver. Make sure to place the H bridge motor driver in the center of your bread board. The pins of your H bridge motor driver should be on opposite sides of the center line of the bread board. This way, we can make sure they're not connected to each other. Now that we have all our components were ready to start wiring up our circuit, I'm going to start creating this circuit, the first connecting the Arduino to the fretboard. I'm going to connect the or greenish ground pin to the ground bar on the right board. I'm going to make all the ground wires in the circuit black. We also need to connect the ground on one side of the Red board to the ground on the other side of the bread board. I'm going to hook up the five volts on the Arduino to the positive line on the bread board . I'm going to do the same thing that I did with the ground and connect the left side of the bread board to the right side. Next, I will be hooking up the able pin from the chip to the urge we know over using Pin nine on the Airdrie. No for this and using the wire color green. Now let's fire up the two inputs of the chip to the Arduino. Let's wire input one to pin five on the Arduino. I'm going to make this wire yellow. Next, let's wire input to to pin four on the Arduino and I'm going to make this wire. I'm going to wire up all the ground and power pins to the chip thes four pins in the center of the chip. I need to go to the grounds on the bread board. Power one needs to be hooked up to the power bar on the bread. We have one more component that we need to bring into our circuit, and that is our nine volt battery. The negative on the nine volt battery. We'll go to the ground far on the red board. The positive on the battery will go to power to on the chip. The nine volt battery is what will be providing power for a motor to move. The last thing we need to do for this circuit is hook up our motor to our chip. We will be using the two output pins on the chip and connecting them to the pins on the motor. The negative pin on the motor will be going. Teoh output one. I'm going to mark this but the yellow wire Because that pain is controlled by input one which is also a yellow wire. The positive terminal on the motor will be connected to output to And I won't be making this wire blue since Output two is controlled by the input pin too, which is represented with the blue wire. Now our circuit is ready to be programmed. 7. Getting Motion: Motors part 2: to begin coding, we'll need to open up the code editor and change it to text. Get rid of the code that's within the loop and the set up functions. We'll start out by giving names to the pins that were using on the Arduino. This makes it easier for us to tell which part of the chip were telling to do what When giving pins names be, use the pound the fine term. We then specify the name that we want to give it on. What planet is connected to. So to name are three pins that we have connected on the Airdrie. No, we have input, one input to and enable. So that's what we're going to name them. Input one. We have connected to Penn five on the Arduino input to we have connected to pin four on the Arduino and our enable pin it's on is connected to pin nine. Now we need to tell Thea are Guerrino what each pin is doing? Whether it's an input or an output, this is done in the set up function. This tells the Arduino whether it's going be reading in information or sending out information to set what each pin is doing. We use the term pin mode m promote you say the name of the pin that you were trying to set comma and then output or input in all caps. All of our pins are going to be outputs for this project. - Now we can move on to the fun part of the coat, actually getting the motor to move in the directions that we wanted to and for how long we wanted to. The code, though we're going to be making will run the motor at 50 rpm in the positive direction for five seconds. Then it will rotate the motor in the negative direction at 50 rpm's for five seconds. We start this off by telling the enable pin how fast you'd like the motor to spin. We do this by saying analog right then our pins name which is enable comma How fast we want the motor to spin. We wanted to spend 50 rpm to control the direction that the motor is spinning. We will set one input pain toe high and the other input toe low. This will Spain in one direction. If we wanted to spend the other direction, we flipped. Which pain is sent high in which pin is sent low. First, we're going to set our motor to the positive direction. To do this, we will use did it? All right. They say the pens name. We'll start with input one comma. Hi. Or look to get the motor to spend in the positive direction we will say low for input one. Make sure this is in all caps. Now we repeat that for our input to pin. Except for this time we're going to say input to too high before we move on, go ahead and click the start simulation button and see what the code that we have currently does. Looking at Water Motor currently does. It is just spinning in the positive direction, trying to maintain 50 rpm. That's all we're telling it to do right now. But that means our code is working and we can continue. We only want the motor to spend in the positive direction for five seconds, so we need to add in a delay to do this. We say DeLay 5000 which will give us a five second delay. Now we want to set the motor to spend in the negative direction. After the five seconds is up, we're going to be writing the same code that we did for making it spin the positive direction. But our input one an input to will be set to the opposite settings, so we'll use digital right and put one. But this time we will be setting it, too. Lo and we will be setting input to to hi and adding in a five second delay again. So that way we only go this negative direction for five seconds. Is this done the same way that we did it the first time? DeLay 5000. Now you have created the same circuit that we saw at the beginning of the video Click on start simulation, and you should see your motor move in the positive direction for five seconds and then the negative direction for five seconds. Going 50 or P. M. Good job. Your circuit is now complete. We can now attempt to do this with a real components. Let's see this motor moving in real life. Grab your components if you have them to create this circuit, create the same circuit that we made in Tinker Cat after you have everything connected. Need to copy and paste the code from our kicker cat circuit simulation into a new artery. No sketch. Make sure you're Do we know it's hooked up to your computer and hit the upload button? Make sure to save your sketch, but the name that you will remember so you confined your code later and safe. Once your sketch has uploaded and it says, done uploading down in the bottom left, your motor should start moving. You are now ready to start making some awesome robots by being able to control both the motor and a servo. There's endless possibilities for what you can create. 8. Good programming practices: Let's go over programming practices there. Good to keep in mind for your projects that you're working on now and in the future. First, make sure to give your projects names that specify what they're for. This is important, so that way you confined your projects later. If you do not give them a name that you will remember or that tells you what they are, then you might not be able to find it in the future when you were looking for it. Here's the code from the servo example. See how my program is named Sketch. May 12 C. That's not something that I can remember easily. It is much harder fine the servo program than it is the motor program we go to file and open. I can easily find the getting Motion Motors program, and I know exactly what that does is getting motion from motor. But Sketch made 12 C fits in with all the other random sketches that I have and doesn't tell me anything about what that code does. So I have no idea if that's the project I want or not, and I may end up going through A B and C before I figure out which one I actually want to use. Add comments to your coat if you noticed throughout the activities that we did, I put comments in the code that said, with the line of code A that followed the common. This makes it so you can look back at your code later, after you have finished your project and know what each part. This also helps as your code becomes more complicated because you will be able to know what each section does. Lastly, make sure to give the objects in your code names that makes sense. When we were working on both the servo motion and the motor motion, we made sure to Neymar with names such a servo one or input one, and input to this told us exactly what they did and what they were used for. And this made it easy for us to identify how we wanted to write her code and what was doing . What keep these practices in mind. As you move forward with your robotics projects, they will help you not only with these activities, but every activity that you do in the future 9. Troubleshooting: Now that you've learned how to get motion from your servo and your motor, let's talk about how to find em. Fix some problems that could be going on with your circuit and your coat. We'll start off by looking at Are getting motion servos circuit on Tinker Ket. The process of finding and fixing problems that you encounter when working on your projects is called troubleshooting to start the troubleshooting process first, you wanna look at your circuit, make sure everything is connected. The way that you want it, in this case, are servo is connected exactly how we needed to be connected. Next. You want to make sure that you're using all the correct vents, so our servo is connected to pin 11 on where you're connected to pin 11. I've modified the code since the last time you saw it in order to show what happens when there is an error in the coat. So I'm going to go ahead and start the simulation and it's not going to run. We have a few problems. The heirs that we have in our code are pointed out down here for us to look at. It looks like there's an error where a semi colon is expected. A saying that serve a warm was not declared in the scope and that our server library has no member, right? So let's start with that semicolon problem. It says It's INL. Avoid set up function. Ah, there's only one thing in our avoid set up function. So it's easy to find where the Sem ical and it's supposed to go Click start simulation and now we're done too. Two errors. This is telling us that both these errors air in the void function. So I'm going to go to that function. Are lines or even highlighted where it thinks that the problems are first problem is online . 15 and it says that Server one was not declared in this scope. Well, I know that server one was created cause that's the name that we gave our servo. Let's go back and look at it. Ah, are servo. One name has the lower case us, and I put it in uppercase us here. So let's go ahead. Make that lower case and they start simulation again. And now we're down toe one air Where doesn't have the name right. We have another capitalization air, right? It's supposed to be lower case now if we soon back out our servers now, doing what it's supposed to do. This may seem like simple things that could go wrong, but they honestly happen pretty often. It's hard to remember what things need to be capitalized or what pins we've connected to. So it's always good to check. This strategy for troubleshooting is the same. Whether you're doing this on Tinker Cad circuits or with a real life, or do we know and using the Arduino i D to program troubleshooting is an important step to completing projects like these. While you may be able to minimize the amount of time that you spend on troubleshooting by maintaining the good programming practices, it's where that you will never have to troubleshoot it all. And everything works the first time. So don't get discouraged if you have issues and your projects don't work the first time, it happens to the best of us 10. Conclusion: you did it. He reached the end of the course. I hope you learned some valuable skills. And this course you learned what materials you would need to complete these kinds of projects. How to use tinker cat circuits. How to install the Arduino i. D software on your computer. Most importantly, you learned how to get motion from a servo in a motor using an Arduino. Make sure to keep those good programming practices in mind that we went over during the course. If you have issues, make sure to look at the troubleshooting portion of the course. But don't be afraid to ask questions in the community section off the course for the course project. I would love to see you guys get a motor moving, using either Tinker K circuits or using a real Arduino. All you have to do is follow the steps from are getting Motion Motor example that we did earlier in the course. I hope you enjoyed the course. Make sure to follow me to be notified when I post courses in the future. Make sure to share what you created for the course project, and don't be afraid to ask questions. Also leave a review to let everyone know what you thought of the course. Thank you for joining me. And I hope you check out my other courses in the future.