arduino 90 degree turn
After seeing a friend have one and how nice of a robot, it actually makes, unfortunately, I’m not really interested in the educational Bo e stands for Board of Education. Bot – and I guess, students that take college classes will buy this kit for about 200 bucks and take the University class and then either go on into robotics or computer science, or they will decide it’s not for them and they wind up selling the kit. Now the kit, like, I said, it’s about 200 bucks. I found this online on eBay. It was Craigslist. I have a program that does a universal search, a nationwide search on Craigslist, and I think I got this for about 40 bucks, which was a very good deal. It was brand new only been used for by this one student for a university class and they decided not to move in or move on to doing a robotic education, so they sold it now. These kits are different prices. They range from I’ve seen it as cheap as 35 40 bucks, all the way up to 140 dollars, there’s other modules that come with it like this, some sort of feeler gauge here whiskers, they call it this kit didn’t have any of that. It came totally complete. I have the whole box there’s, even some of the LEDs and sensors that haven’t even been opened. Yet it uses a different coding, environment or coding program to upload code to the the PC board I’m, not interested in learning that code or actually, I said even using this board, it’s kind of limited and the parts are pretty expensive.
If you want other additions or add ons, the Arduino is definitely a better way to go, or maybe even the raspberry. If you want to go that route, but the Arduino is ideal for this, and so I’ve been looking for awhile and I finally bought one, and so let me show you what I actually. Let me show you what I actually bought. This is the kit here, and this is the actual bot that came with it. It cut like I said it comes with a motherboard. It came with two servos in a battery pack. It came with an extra servo which is kind of nice. These are continuous servos for the wheels it has the metal frame. This is a standard servo so and then all the wires and connections to make it work. The only problem is and I’m going to use my Arduino mega to control it because I’m, using the uno for a different project, is that the the Uno doesn’t really screw into the base and so that’s kind of a problem there. Their parallax, which is the company that makes this, does make a an additional little module. That looks like this and basically, if the holes here match up on the holes on the top of the computer of the the robot of the robot and then the Arduino mounts underneath this board and the pins come through here and you can access them and then Do what you want with them, so actually the the module the Arduino would be underneath like this and then the pin outs would come up through the top.
Well, as you can see, the this is 40. I am going to put another 40 into it. This is the top view of the little board it’s ideal. If I could find one use for five or ten bucks. I’D definitely pick it up, but for 40 and I’m gon na sink that much money into it. But this is a nice little clean solution. So, depending on how much I actually put into this this project, I may wind up buying it anyway, just to make it cleaner, but for right now what I’ve decided I’ll show you what I’ve decided to do is I take the I take this off and unscrew. This and I take off the breadboard – and I turn this upside down and just put the screws back in here and use the board upside down and I’m, using some velcro here to hold the breadboard and to hold the mega and for the most part, while I’m Doing prototyping this will be fine and I think for right now, it’s on there pretty good good enough. I also had a servo module here that is it’s a clamp that holds a servo. I mounted that to the front of the bow bot, because I had the kit included an extra one, so I will put a ultrasonic ping module on there and have it rotate around and use the small micro breadboard for connecting things so for right now. I think this will work well.
This actually plugs in here. These are the servo connections here, and I need to connect these to the breadboard and and use it that way. So that being said for 40 bucks you get through, I got three servos and some nice wheels and a really nice metal, robotic car. So I wouldn’t spend much more than 40 because, like I said I’m, not going to use the the actual PC board that controls the car or the software or the other little kit. So for me, 40 bucks is pretty much the limit. If you can find one. This is in brand new shape if you can find one. My friend picked one up for five bucks at a local college. So if you get lucky like that great and this robot car kit is really a nice one, it’s very durable, it’s expandable. It has all these little places where you can mount other components. I highly recommend trying to get one. The servos drive the wheels very nicely, and I was really impressed with my friends so that’s. What compelled me to get one so, given that this is the start and I’m gon na start adding modules and increasing the capability this, and I will document it as I go along diagram. It has a ping module Bluetooth, module, an MP – u 60, 50 plus three servos. I have a separate C battery pack for the servos and nine volt for the mega. Here I have the robot car doing a series of five rights and five laps.
Each turn is calculated using the NPU 6050 chips yaw feature. Even though the chip is a six degrees of freedom, it has pitch and roll and yaw in both directions. I always use the yaw for left and right and then, since that’s the case then y’all counts. Clockwise, zero to 179 and then counter clockwise from zero to negative 179. So you have to account for this difference in numbering when you calculate your left and right turns in this case it works very well. So here we have the hyper terminal view of a right and left turning only test that I did. I wanted to show how the cart turns right, using the guidance system that’s provided by the MP? U value, and now it goes from 0 to 90 to 179. Back to 90, then back to 0, and here it’s, just doing a bunch of writes about five of them and a bunch of laughs forget about five of them and writes again and what’s. Interesting. To note here is the NPV MPU value counting towards the heading value and then once it meets that heading value within plus or minus ten counts, it stops and then does the next turn. In this case, it would be multiple right, small s, because servos don’t track evenly I’ve written code to slightly adjust, left or right the Bobeck cars direction so that the MPU value and the heading stay equal. I have the hyper terminal capture from the bluetooth of the robot car, doing a micro adjust left and right and eventually it does a right turn here.
If the robot car driving on the floor – and I test the left right forward and reverse capabilities of it – I’m, just using a simple paper plate to kind of act as a barrier so that it, the ping, comes back and can work correctly with the received data. But basically it’s pretty straightforward, just wanted to kind of show how it moves about and how quickly it turns. So this sketch that controls the robot car that I purchased was fairly complex and I have quite a few notes. So what I want to do is I want to start off by giving the notes that I used right here to configure the car and do some analysis and some background education for myself, and I also want to give some verbal notes that I took while making This project, often in the projects I do, I write down, notes and kind of sideline information, and I want to give kind of a background to this this project because it was pretty complex. Basically, what we have is a arduino mega and it’s controlling three servos there’s, a right wheel, a left wheel and then a center ping servo for judging distance to objects. In addition to that, there is an mp3 I’m, not a mp3 but MPU, which stands for motion processing unit 6050. It has six degrees of freedom, it does a pitch up and down it. Does a roll left over right and then it also does a yaw turning left and turning right.
So those are the six degrees it’s a gyroscopic accelerometer. It does quite a bit and it wasn’t very expensive. I got it at banggood, it was maybe five or six bucks and I think they’re basically used in segways to keep them upright or if you’re doing a two wheeled stand up robot, you would use it also there which I might make in the future. Overall, it was a very cool project. What I wanted to do was I wanted to just use the portion of the of the sensor, the leftright kind of like a compass, but I didn’t really want to do a compass. I don’t really need to know true, north or true, east or west or south. Every time you turn on the MP you 6050. It starts out at heading zero, and so this bow bot is basically a line following robot. However, there’s no line it uses the the heading signal from the MP: u 6050, to keep it on track. If it’s going forward, it’s initially set to zero and it will try to keep the MP – u 60 50 heading at zero. I do micro adjustments left and right because servos are not as precise as they could be, and so it bumps it back into line when it goes to do a turn left or right. I set the heading to 90 and I turn until the MP. U 60 50 reads 9 D and matches up with the heading, so I’m always constantly matching the heading and the MP: u value, which is the get value I use to find out what angle I’m aiming at so that they match up now.
Something’S interesting, the MP? U, 60 50. If you go, clockwise goes from 0 to 179. If you go counterclockwise, it goes from 0 to negative 179. So you have to account for for that, and what I do is I convert everything to an absolute positive, so it’s a if it goes right: it’s 0 through 179, if it goes counterclockwise it’s, 0 through 179, and it basically if it if it continues to go In the right direction it go, it would go from 0 to 90 to 179 back to 90 back to zero and the the reverse is is the same, so you got to kind of keep the direction that you’re going, keep keeping tabs on that and all the Different angles, so it was, it was a tricky calculations to do so, but basically I’m using the MPU 6050 as a guidance system. And basically I I took or used some of the code or most of the code that was produced by a gentleman by last name. Berg under a program called processing plain code. I have it up here in the notes. You could look for it and kind of look at it yourself, but it gave you the yaw pitch and roll I discounted 23 of it. All I wanted was the yaw value and what it does is it would take values from the Arduino and then graphically using the processing program graph it like a plane in three dimensional space.
So, as you rotated the the the the chip, you would see the plane move in the same correlation, and so I initially wanted to be able to take the information from the Beaux bot via bluetooth and that’s. Another bit of hardware that’s on this car is, I also communicate via bluetooth. I want to capture that Bluetooth, information and graphic three dimensionally on the screen. However, I couldn’t get an answer from the processing folks to be able to convert that data to three dimensional graphic image without shutting off the Bluetooth connection. So I never got that to really work in that fashion, which may be in the future. I will try, so we have all those devices and then so the servos require a lot of a lot of power. I kept running out of the double a batteries that worked underneath the chassis, the four of them that came with it. I kept on even replace so so I got a little tired of that and I upgraded to four C batteries, and then I used a 9 volt battery just to control the the the Arduino mega and that seemed to be the best. However, it’s not the prettiest, the car doesn’t look the greatest but it’s pretty solid. It worked pretty well so let’s see whether their notes do. I have here. One thing that was very difficult was having. I had difficulty with the wheel speed each wheel of the servo one on the on the on the right was as you’re looking at cuz.
You can either look at from the back and for the front, but as you’re looking at from the front. In this case, the right wheel actually would run, I believe backwards, and then the left wheel would run forwards when you’re going forward. Stop was not actually 1500, but it was actually 1492 for both wheels, that’s, where it actually stopped the wheels from moving and then reverse. As you’re looking at the left, wheel went backwards at 2300 and the right wheel went backwards at 11 and the reverse is the same for forward. The right wheel went forward at 2300 and the left wheel went forward at 1100 a good forward, speed that seemed to keep the wheels as even as possible so that attract in a fairly straight line. The right wheel, speed I found to be 1700. I guess these are in microseconds and the left speed was 1200 and that seemed to work pretty well for me with the servos I had your servos made may also change. So one thing I also want to do since I upgraded the power supply. You got to keep the power supply, definitely in the middle of the car. I tried hanging the power supply off the back and it would lift up the front and it didn’t really steer very well one downfall of the MPU 6050 on occasion randomly it will return. A very large heading – or it will lock up and so you’ve got to kind of keep on top of that to make sure you’re constantly pulling it or you.
Don’T have too long of a delay because that NPU 6050 will shut down or stop or give you a bogus number and then your numbers get off now I didn’t do any error, correction or detection on that. I could have probably pulled it twice and taken or three times and taken the two numbers that were the same and use that I didn’t do that. But if you’re doing something that’s much more critical, you might want to try doing that. Let’S see what else I wanted to slow. I had to slow down the MP you 6050 from 115k ba down to 96 Bob that also caused some problems. So when you start slowing it down, it starts to hang and give you bugs. So I kind of tried to minimize the code to get it to process as quickly as possible. So I did mention that the heading starts at zero. You have to allow some time for the servos to kind of stabilize and also you have to allow the MP. U 60 50 to stabilize. I only allow it to stabilize a little bit less than 15 seconds, but it could take as long as 40 seconds that’s just something to keep in mind. There was some C other than that. I think that’s, probably all the notes that I had on the side, so let’s look at the code here and go into it. So these are the notes I used for searching for information here’s, the name of the sketch right here you can find at codebender under user fish.
I also have other YouTube videos if you search scott mod on youtube, here’s, some information that came with some code – I’m, leaving it in there I didn’t actually use it here – are my notes on the servo 1 and servo two, how they the forward and backward direction For the wheels here are all the libraries I used and up above you can download whatever you need like this one here up above, I always put in pragma once because that stops multiple openings of the same dot, H files. That seems to help – and here I configure the NPU 60 50. This is some information that was with Berg’s code, so I left it. I created my own MP, you value and I hear some a negative if the value is negative. I need that information because when I count to the counterclockwise I need to convert and but remember that it was negative, so I know which way to turn this ypr is yaw pitch and roll. This is part of Berg’s code, so I left it again same with this here’s heading. Basically, the MPU value and the heading you’re always trying to match those up, and you only change the heading in in very key subroutines or functions. You don’t want it changing all over the map because pretty soon you’ll lose track of where your heading is. I set the speed to forward. I initialize the word stop to this this number here.
This is for doing some mathematics of down, below which I will describe and then here’s the heading counter for turning this dump data ready. I did not generate it’s, basically part of Berg’s code for the mpu 63 60 50 and you need his code it’s. Definitely the way to go here. I configure the ping module very standard, trigger, pin on nine echo, pin on eight and then a max distance of 200. I think those highs for, but I just did two here. I configure the servos left wheel right wheeled in Center ping. The distance is so that and then a limited distance of 10. So if I get within 10 centimeters, I guess it is here in this case it it stops and starts to calculate which direction to go. Here I set up the sonar and for new ping setup. Four pins and maximum distance and the actual setup portion of the code right here, let’s see some of this is put this excel. Mpu excel off cell offset is part of the MP. U code that you need. These are the numbers that came preset with it. I used a calibration program which I will include it’s up in the notes up above that you can download, and it will give you a little bit better numbers here for so that you get truer more accurate results with your particular MP. U 60 50 and I did adjust them slightly here’s an interrupt. Do you have to have you, try to take the interrupts out and it stops working, so you got to leave it in here I attached the wheels and the center paying to the servos.
I just stayed here: I have them, you know setting them the servo in the center two to two to the center and stop the wheels so that we’re ready. I give it a few seconds because I need to set it up and push the reset and connect a bunch of stuff, so it takes a little bit of time. Plus you want a little bit of time for the MPU sixty fifty to initialize and the servos to initialize the heading set to zero n pu values set to zero so that you’re starting off in a forward direction and then here’s the loop. And this is the main portion of the program. Obviously we come into the singer: ping Center ping. We initialize looking straight ahead using the center servo. I display the wheel informations on the on the screen I’m, using that with bluetooth and the serial monitor, and then I go forward and I’ll show you the code, the functions down below when we get there. Next, I get the MP. U value check to see if we’re varying left or right, because you want to go in a straight value and, like I said, servos are slightly different and over a long distance it will start to deviate, left or right you and make sure you’re on a straight Heading I take the absolute value of that head of that value, whether it’s negative counterclockwise or positive clockwise, and if it’s different, not equal to zero heading.
We check the heading and under check heading it. It modifies a does a Ana, just right or adjust left dependent to get the heading and value and P you value to match up again, I display that information. Otherwise, if they are the same, we go. We check the center distance, see if there’s an obstacle at our limit. This is standard code I had in my other car, robotic car code, but if the distance is greater than this, we go forward. We check the center again else. We stop the left and right wheel. We give it a few seconds to stop. We get the distance right, we get the distance left if right is greater than left and right is greater than limit distance. We go ahead and turn we Center it and turn right. We Center the the ping module and then turn right else if left is greater than the right distance and left is great at a limit distance north to turn left Center, the ping module turn left else. We reverse that means there’s, something on the left and something on the right. We reverse, and basically, after all, that we get the next npe PU value and the whole process starts over and that’s the end of the loop and so we’re constantly getting this NPU value to make sure that we’re heading whatever direction. We’Re heading we’re always heading on that line that guided line provided by the NP you 6050, so here’s the code for the right eye shows it makes a right turn.
You got to align it line it with the heading. It cycles degrees of NP. U NP! You! Never has 180 or 360 degrees that’s key to know so you got ta came you got to be able to cycle that information, but not get to that. Those numbers must taking the count at the turn left prior to a right turn or if it turned right, must take into account if it turn left prior to a right turn or if it turned right prior to a right turn. So I’ve said going in the right direction, or is it going left right left right and that’s? You got a hand in the oils a little bit different. So this gives me a little example. I want us to want to remember and that’s how I decide whether it’s a zero 91. 70. 990. 0. As a remainder that I checked the division – and I checked the heading – and I check the remainder in the code down here – and that gives me allows me to calculate this next number. So in the right turn. I print right – and I said, heading counter – equals heading counter, plus Snyder. So if I was doing 0 I’m now doing a 90 degree for a right turn and I take the remainder and I take the division and then I make a comparison and if it’s not zero, then the remainder is 179. If it is 0, then remainder equals.
Then the remainder equals 0 and then I set the heading to the remainder, because if you know it’s, the remainder it’s really all the values I want. After that, I get the MPO value. I display the wheel information and then, while the MP you, you value, is not equal to heading because we’re, starting to turn now we’re going from 0 to 90 right here and it might be from 90 to 180 or 179. So it depends on what you know. If you’re going right right right and then what I do is right, wheel, right position and the position is from stop, I keep adding, which is 1492, I add 15 degrees or units or counts, and I turn the right wheel and then I turn the left wheel. The same amount because it’s going in Reverse – and I give it a little bit of time to do that and I get the value to see – have we gotten to these two numbers being equal? In fact this case, I actually give it a little bit of a buffer of 10 clicks or 10 counts either. Side, so does not be exactly 90. It could be 95 or 96 so that, because the wheels don’t turn as precise as I would like – and I also didn’t spend the extra time to get it to land precisely it’s really difficult. You could just move slower, you know until it actually lands on it, and then you get a much more.
Accurate 90 degree turn. So it was what it was. It worked fine for me, basically let’s see where do we go from here? So after we finish here at one time, I had a for testing. I had a bailout to get out of a loop but looks like I don’t need that anymore. So I got I’ll get rid of that. So once we once these two numbers meet. Oh whoops, I see there’s the bailout. Yes, I’m. Sorry, I need to point out something here. We stay in this loop and we keep doing this, but once this is true, we go to bailout and otherwise it’ll just keep testing and testing and testing it’ll just it’ll. Just cycle over and over and over, I did not code this as well as I should have. I could not seem to figure out how this this, while loop could keep going and when I meet a certain buffered area or boundary area between of the heading to end this while loop, so even a do until or maybe a do until might have worked. Maybe I could have just done. Do I don’t know? I never really got this to work so well, so I used a go to which is not too good, but so then you go to bailout once this is true and then you stop and you set the right wheel and left wheel to a stop. You give a little bit of time and then once it’s stopped, you start moving forward again and that’s the right turn.
The left turn is exactly the same, except you deduct 90 degrees and other than that does exactly the same thing all the way down here. You you, you keep doing this loop until mpu value, while NPU value doesn’t equal the heading. You keep doing this, you keep going going going and then eventually the NPV ump you value, will land in between heading 10 and heading 10, which case you blow out of it, go to bail out again and again, like I said I’d like to code, that a Little bit better, you stop set the wheel, speed, wait for it then go forward and that’s the end of the left. So now that we’re we’re going left, let me go down here to the forward, which is way down here forward. Is you set the right wheel? Speed bad left, wheel, speed that and you just go ahead and do it and that drives you forward reverse. This is the these. Are the backup values for the wheels the reverse values you’ve set them. You delay a little bit of time to back up. This is the amount of time you back up, then you stop so that’s, basically the reverse, so that those are all the different directions: go back down now getting the NPU value. What exactly does the that do this calculate the mpu yaw value? This value is used as a straight line to follow the value it’s established when the unit is first turned on.
So while there isn’t an interrupt and I’m not familiar with this code, so much, I reduced it down quite a bit because a lot of it I didn’t need. But basically you need this you’re setting up some sort of buffer him packet size. Then you got to reset it here when the as the buffer gets filled up you’re putting the value. This is so that it can actually be kind of sent to the processing program which I don’t even use. I try to remove what I could and basically I set the mpu value right. Well, I set it here and then I check to see if it’s negative, in which case I said it true if it is, and then I take the absolute value, not concert bits convert that spellcheck convert to positive. So this is his code Berg’s code. I just kind of reduced it down because it works so well after you get the value you want to check your heading and if it was negative, then we adjust the the bot right else. We can adjust it left and this is for keeping it on the heading check to see the robot cars veering off the NP. You 6015 heading value, ie 0, 90, 180 degrees adjust from from looking from rear of the bot car. This is looking from the back of the car, so when you just right it’s, actually the left wheel that you’re adjusting so you’re going counterclockwise.
Thus, if it’s a negative, you just write else. If, if it’s positive, you just left again you’re looking at the right wheel, so I probably could have reversed this or done this a little different. But it was just easier to see it. My mind’s eye, instead of looking at the front of the car I’m. Actually, looking at the back and car having it adjust right or left, and then we set the value negative back to false and that’s that that’s the only place we set it defaults so other than the setting at the top, where it’s initialized initially so that’s. The check heading and so we’re constantly checking the heading, comparing the the NPU value to see that we’re online with the heading, so the adjust left and the adjust right are very similar. If the robot car starts to drift right, adjust the direction back towards left. This adjustment is viewed from behind the car here. I say i proud a little message, so i know what’s going on here. I have a value in this case on the left. I add an offset and I keep deducting that offset to slow down the wheel or speed up the wheel, and here it speeds up the the left wheel so that it starts to turn left more quickly and I slow down the right wheel. So it starts to pivot and then once it gets to this value, this is the minimum value I want to get.
I just set it back equal to that. I don’t want to exceed the maximum speed of 1100. Doesn’T really do any good and I didn’t want the wheel speeds to start getting crazy here. 1500 is darn near stop, and so once it gets past that I wanted to keep moving a little bit, I go ahead and activate the servos, and then I display the wheel information. The adjust ride is exactly the same, except I did. I handled it a little bit different in the fact that here’s the value I initially started using that, but then I thought for the right. It was easier just to set actual values for turning, and that worked the best for me, I tried these different values and this one was the best. So this really is not necessary anymore. I could actually take that out. Then once it’s turned to the right and the heading up above says that are equal, you know, then I stopped calling adjust right and I want to display the wheel information to the console, the console so that the Bluetooth or the serial monitor will tell me what’s Going on so, the next function is get distance right. This is real simple. You just set to ten look right using a servo. Give it a second to do that. Get the distance return that value same with get distance left turn it to the left one. Seventy give it some time get the distance, give it some time to get that return.
The value and the center is that 90. Here it was, I put it to 500 to get it so that I can speed up the code as much as possible. These delays, you probably could reduce a little bit in order to speed up the code, but I didn’t need to so here’s the delay. If the value is zero, I set the value to 200 cuz that’s infinite. We don’t have a distance of zero. Sometimes zero comes back if it goes off to infinity, so I just said it’s 200 or max value, and then I return that value forward already told you about reverse. I told you about here’s get distance, get distance. Basically is a standard ping code. A lot of folks use it it’s readily available I’ve used in another ping projects. So you do a sober pay, a sonar paying you calculate the ping value if it’s zero. I said to two hundred and then I return that value else. I return the actual ping value. How close is it to something? Lastly, here’s display wheel information I set the display with the right is at the left is at the NP? U value is at and the heading and that’s, basically it so that, in a nutshell, is the code. I hope this is helpful. It’S, not the most beautiful coding, I’ve done and the project was pretty difficult. Actually, with all the functionality. I really wanted to be able to run the car autonomously, let it just run and have it graph the information, the the car turning left and right in the processing program and see that in real time and I’m still trying to work on that.
But, unfortunately, I’m. Not getting a whole lot of help from the processing folks so far and I can’t get the processing program to run the same time. I have Bluetooth running on the serial port, so that’s to be determined in the future. I hope you enjoy this. The sketch in this program, please share it. Please give me the thumbs up if you like it please.
arduino 90 degree turn Video
arduino 90 degree turn news
Posted on Wednesday July 31, 2019Ping-Pong Ball Makes Great PID Example Hackaday … Continue Reading »
Posted on Friday August 30, 2019Your Arduino SAMD21 ADC Is Lying To You Hackaday … Continue Reading »
Posted on Thursday October 03, 2019Drone Technology Proliferation in Small Wars smallwarsjournal … Continue Reading »
arduino 90 degree turn Social
🔬 Now that you’ve gotten your feet wet, dive into the kit and enjoy all nine experiments. Order yours today: http://bit.ly/2MnQ7fr