Autonomous NERF Robot controlled by LIDAR

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

James Burton posts the coolest robot builds!

👍︎︎ 4 👤︎︎ u/RaidenHero137 📅︎︎ Jun 02 2020 🗫︎ replies

Well that's cool, like a better Terrascout.

👍︎︎ 4 👤︎︎ u/[deleted] 📅︎︎ Jun 02 2020 🗫︎ replies

I so want this, nice job!

👍︎︎ 4 👤︎︎ u/xfoxgames 📅︎︎ Jun 02 2020 🗫︎ replies

I think it would have gone over better with a single stryfe, rewired to accept the 12V running off a 35 drum.

Cool build.

👍︎︎ 2 👤︎︎ u/horusrogue 📅︎︎ Jun 02 2020 🗫︎ replies
Captions
today I'm going to be looking at this lidar unit and this is a laser scanning rangefinder that does a complete 360 sweep of the environment and they'll tell you the distance to the nearest object so I'm going to be looking at what this is useful for and also building a really simple robotics project that uses this as a sensor so I got hold of the RP lidar a one from slam tech which is a budget model I bought it from cool components in the UK and it was about 100 pounds there are plenty more expensive models out there but this looks like a good starter for simple projects there's some software from slam take that will do mapping and navigation it looks pretty comprehensive although it doesn't actually appear to do very much unless you have one of their mobile robot hardware platforms it looks like this third-party plugins support but I can't see how you can do this it looks like it's possible to write extensions but I can't find any documentation on what you actually need to do to add anything into the software there are also ROS libraries and there are a few videos about using existing roles modules for mapping location and navigation I've never used roles before though and it's something I need to spend some time on getting up to speed so today I'm gonna try something a bit simpler but I'll put some links in the descriptions of this video from these videos where you can see this lidar in action with rolls so here it is it's the RP lidar a1 and it looks like this so call this rotating piece on top which appears to have a laser in there somewhere and some sort of sensor so I'll send the laser beam out and then presumably measure the time of flight to measure the distance so that thing rotates all the way around it's got a little motor that drives it there and it's also got an interface on the bottom and it's not much else to it really it's got these standoffs and a couple of circuit boards but that's about is there is an Arduino library for this lidar though that allows us to connect over serial and get all of the data and that's what we're going to do today to build a simple robotics project just before that low is a quick add for ways you can support the channel and that really makes all the difference to the projects I have patreon and YouTube channel membership and patrons and YouTube channel members can get access to all the videos up to a week earlier which probably means all being well they've already got next week's video also have a merchandise store where you can get t-shirts bag socks stickers and various other things with designs on of things that I've built over the years including all of the robot dogs and it's awful robots also have some affiliate links in the description and if you use some of those links it won't cost you any more but I'll get some money right let's have a look at this lidar so I've connected this up to an Arduino mega because the mega has multiple serial interfaces and I've connected one of those interfaces to the lidar I've also connected power which is five volts and ground and also an additional five volt pin and that goes to the V moto pin which is actually an independent pin to spin the motor because otherwise nothing happens now if we look at the bottom of this you'll notice it's also branded as Robo peak and if we look on the Robo Piku github repository we can find all the open source code for it including the Arduino library with some examples so the examples pretty typical for Arduino libraries we include the library of course and create an instance and also we've opened a serial port hole which is connected to which is serial to and another one for debug that's another pin I forgot to mention which is the motor pwm pin and that seems to be written to the max value anyway which presumably just makes the motor spin full speed and then we can just go and get the data from the lidar and that's all it does really and there's four bits of data the distance the angle the start's bit are not quite clear what that does it says whether this point is belonging to new scan but I haven't quite experimented with that and also the quality of the scan and then we just dump those out to the serial terminal so let's have a look at the data so my lidar is happily spinning away there as you can see it's connected to the Arduino and I've opened a serial terminal to get all the data here which is happily spinning past so let's just pause that for a moment and it looks pretty random so the first column is the angle here in degrees the second one is the distance so it's just measuring the distances at each angle around in a 360 degree sweep and the last one is the quality which seems to range from between 0 and 60 something let's just have some more data yeah so it looks pretty random there's no particular logical order to this obviously the angles are random it's probably polling whenever it can and then just telling us the distance at wherever it is in its rotation cycle so let's try something slightly different now I've just made one change to the code to see if the angle is smaller than 3 and bigger than -3 so basically if it ranges from minus 3 to 3 in that 6th degree segment then tell me the distance and tell me the quality of why's don't tell me any data so we should be to pinpoint a particular point around zero to see what the actual distance is somewhere we can measure easily sorry this exhibit more promising the data looks a lot more consistent obviously I'm only looking in front of this scanner here within plus minus three degrees and zero seems to be right in the middle at the front so we've got a ruler here that set up on the bench so we can see the distance on a box measuring the distance the moment is about 300 mil and that seems to give us the right readings now if I move this closer then we should see that that goes down about 174 which is about right and this seems to be measuring to somewhere within the actual scanner here so the rule is not quite in the middle and it's not quite on the edge so it's probably where the laser and the receiver is mounted in the edge of this piece that's spinning so it seems pretty accurate though if we go out to five hundreds then we should get yeah roughly five hundred right there so of course this is just like using an array of sensors and we can measure any angle we want there and see what's there and see what the closest object is now the minimum range here is about a hundred and thirty if we go lower than that then we go zero and we also get a zero quality rating which is quite useful and the maximum range seems to be around seven meters we're exactly the same thing happens so probably the best way to combat that is to realize that if we've got a zero reading with zero quality it's bigger than seven meters and just make the robots basically bigger than 130 from where the sensor is so that we never get a reading that low otherwise it's pretty tricky to work out whether something's really close or whether it's really far away so we can deal with this just as if we had a whole array of objects on ik rangefinders or infrared range finders and we could put those all around in a circle I knew we've got it all in one sensor here we can query that one sensor to find out what's going on in any direction and now obviously the smaller the range we look at in degrees the less data we're going to get and I guess the more expensive lie does give you more data faster but this one's OK for a small project we could easily divide up 360 degrees into 36 10 degree segments and we'd still get plenty of data like we did the example where with a sixth degree segment so now I'm going to build a small robot that uses this as a sensor and we'll see what we can get out of it practically [Music] [Music] so we've got a pretty simple Drive mechanism I've got some gearhead motors here these are from Gibson robotics and these are the thirteen point seven to one version of these motors they're 12 volts they've got a pretty hefty planetary gearbox on and a I think it's a twelve mill shaft with a flat on there so what we're gonna do is have a 3d printed gear on there which has got a grub screw in so that I can attach that securely to the shaft there's a motor mount that each motor fits in and that's going to drive the wheel with another gear ratio now my wheels have got ninja flakes tire on that's pretty thin but that'll allow it to grip the ground and each one's got eight millimeter internal diameter skate bearing on and that's going to make up the drivetrain okay so I've assembled my base I've got two halves here which hold those wheels and then hold the blocks for the motors and there's some twenty twenty extrusion that holds the two halves to give and allow us to mount the rest of the chassis so that seems to be working pretty well those gears turn okay and obviously that gives us differential drive on one side here I've got cast the wheel mounted on a block so that's fine to stop you tipping one way and that will just cast around as the thing moves we do need to do something about it falling this way but also we don't want it to get grounded so there's a lump in the ground on the cast has come off the ground then that means one drive wheel comes off the ground so we need to put the next one on some sort of suspension arm so that's the other caster wheel and that one is on a suspension arm so I've used the pivot point from the axle for the main drive wheels there's a piece of bungee underneath this brings it back again and that's the bit of bungee cord there that acts as a spring so now if it goes over a bump it should have some suspension and that's the next stage on top which has the lidar on at the moment the Arduino is just floating around but that needs a proper mount and obviously I think this is going to work quite well with that suspension arm but you've seen the thumbnail and you've seen the CAD so let's see what's going to go in this big gap in the middle yep it's a pair of nerf n-strike stripes and these are the electric blasters which have a switch to turn on the motors and then once I pull the trigger which shoots out the darts and I've already modified these so I can trigger them remotely so I've got a servo down here which pulls the trigger and it's got a little spring so I don't overstrain the servo and then I've basically hacked into the motor so I can just turn them on so there's a five volt regulator down here is one of these turnigy backs that I think it's six folds to power those motors directly and also powers the servo so my connector I'm basically just taking power which is 12 volts and the servo PWM signal from an Arduino to turn the servo and pull the trigger yep PIR I fitted those in there nicely and those can be picked up slightly and adjusted at the moment they're pointing up slightly so that hopefully the darts converge with the level of the laser scan but we'll see how that works out at the back these are on a pivot point on the back of the frame here so that they pivot and on the front here they're resting on another piece of studying so I could block that up to change the height of them and also I can lift them up to get out the clip on the side we now have an electronics box for the Arduino mega that's going to control everything a 5 volt voltage regulator and 2 motor drivers to control each motor I've got a big switch here and that's gonna serve the purpose of arming the robot when we're ready for it to go autonomous and on the back corner here is a relay module and we're gonna use that to turn on and off the blaster motors so they're not just running all the time so avoiding the power and we've got the battery in the regulator there to give us 5 volts with white in those relays which gives us 12 volts by the regulators to the Nerf blasters and I've wired in the servos and we already have the lidar connected so now we can do some testing to see if we can actually trigger the Nerf blasters when something comes into range so for the first thing I'm going to do is just take a 10 degree segment of the front of the lidar and then we'll see if something comes into range then so if we can get the blasters to fire now 10 degrees is quite wide so what I'm gonna do is take an average reading from that segment and then we'll see if the average changes and then we'll know something's come into range so as before I've carved out a portion here which is plus -5 degrees and I check the qualities at least 15 which seems to be pretty average and says that we've got good readings I've also constrained the reading here and I've got a minimum the maximum distance specified which is at the top so that's 15 centimeters and 2 meters so the data is always within that range and it doesn't measure all the way up to seven meters anymore obviously we can adjust that they liked on a filter and this is a bit like a running average but it makes the data nice and smooth because it's quite choppy depending on what's in front of it and what the measurements are within that 10 degrees so obviously we can have some objects summer far away and get lots of mixed measurements so let's have a look at what we get out of this filter in a serial plotter so if I wave my hand in front of it here we should be to see the blue line is the actual data we're guessing within that ten degrees and the red line is my nice smooth filtered line and that's basically doing an average reading that seems to run there and that seems to work pretty well obviously if it's a hard surface we get a more stable reading anyway but for something organic like my hand moving it does a nice smooth filter so then we need to make the blasters fire and my code is multitasking which means this loop is continually running and I've used the system of flags so that we can see where we are and have conditions also based on timers so basically we want to leave some time for that filter to settle and again average reading and we'll need to do this on all of the 36 10° segments so first of all we look for the button to be pressed that I've mounted on the front of the robot and then we increment the flag we then reset the clock as well and we wait for time to expire so basically we bookmark the time and we check the thousand milliseconds later which is one second and if the flags been incremented if those conditions are met and we can then bookmark the filtered value and that means that the filters settled and we can then see what that average of value was we reset the clock again and increment the flag and then we go to the next stage so basically this loop is still running so we'll run past all of these but it will only do this one because the flag is two at this point and it's not any other value so effectively it waits although the loop is still running so it's not actually like a delay that pauses the code at that point if the distance filtered is smaller than the bookmark distance by 200 millimeters so basically something is coming to range closer than 200 millimeters it then starts to do the firing sequence that turns on the relays which go and turn on the motors and the servos on the Nerf blasters and we need some time to power those up before we pull the triggers so then a thousand seconds later and provided the flag is 3 we then go and fire the first blaster and we do that by activating the servo to pull that first trigger we then go to the next stage and we give you 700 milliseconds and then we pull the other one and unpause the first one and another 700 milliseconds later we let go both triggers and then we give it 500 more milliseconds which is half a second so that we can unpause both triggers before we actually go and switch the relays off and kill power to the blasters and then at that point of course it turns the motors off so this is powered up and we've got the serial terminal there so you can see the data that's gained typed out in terms of the range and all those other bits of data so if I press the switch on here that should arm it and then it waits a second and then it should give us the value that is found the average for and probably be longer than a second because that all means you've got time to run away when it eventually does a 360 scan but the moment it's only looking right in the middle so if I then go and make a distance shorter than that it should power up the guns fires two shots and at the moment it goes back to the beginning there's only six shots in each blaster so eventually we'll count this six times and then it'll be activate but for now it's right back in the beginning so if I now go and give another distance that's shorter than 1343 by 200 millimetres and fires two shots and goes back to the beginning and then the moments I'll just keep doing that so the next thing to do is to try and power up the wheels so that we can scan 360 degrees then we can try and get it to turn round to point in the right direction however in order to turn the robots at the right position we need to measure how far these wheels are turning so I left provision here to put wheel encoders on the motors which look like this and these are six hundred counts per revolution quadrature encoders I've got a little flexible coupler that we can put onto a bit of stainless steel that I've push fitted into the motor gear so that I should fit on just like that and then that will turn and we can measure the counts and we can work out how far the robots rotating or make it rotate to a specific angle to read the encoders I'm using code from the Arduino playground website and this example is the encoder interrupts on both pins so on the maker we've actually got six interrupts the example so one encoder using pins 2 and 3 which you find on an uno or whatever but we can read up to three encoders I guess with Omega so my encoder interrupt service routine code is all on the bottom and basically looks at which way those quadrature encoders are turning based on which phase is triggered first so now if we look in the serial terminal we can see we've got our values of zero zero and if I go and turn the robot we should find one goes positive and one goes negative and the other way round and if we move it forward they both go positive and so on so that now allows me to measure the motor positions and then I can turn the motors so they get to a certain position I've now widen my motors and I'm running a PID controller against each encoder so we can specify how far we want that wheel to move and it will try and match it against the encoder value from the demand position so that means we can turn it or drive it forward and backwards by specific amount course that doesn't take into account we all slip but the wheels are pretty grippy and as long as it's on a reasonable surface it should work okay for our purposes and I've now divided up the lidar into those 36 10 degree segments so that we can decide where an item is getting triggered I've also widen this LED strip so the LEDs are blue when we turn it on if we armed it they turn amber it waits 4 or 5 seconds for that filter to settle and to bookmark the values and then it's armed and they turn red and now we can trigger it by putting something in the way of that lidar and it should turn and fire and for now I've taken the Nerf darts out but let's see if it works in real life [Music] [Music] [Music] the light is green the trap is clean and that means we're out of shots and it's safe again and it's time to reset and of course reload so remember what we're doing here is dividing up that lidar data into 36 10° segments looking the average value in each one bookmarking it and seeing if it changes sometime later if he does we rotate the robots of that angle and obviously unleash the Nerf blasters now I'm going to pull the cutting code in the descriptions of this project there's a link to my github where you can find all of the resources for this project and lots of other projects so if you'd like to support me on patreon or for a YouTube channel membership then you can and most of the products I do are open-source so of course there is some error with this which is basically they're ready looking at 10 degree segment so sometimes it's not totally accurate sometimes one nerf blaster dart hits the mannequin head and the other one doesn't sometimes they both hit it so that could be drastically improved with some better software what about if it can actually roam around at the moment this has got wheels to drive but I'm only really using them to rotate I could have just put this on a rotating base but what I want to do in the future is after this actually seek-and-destroy by driving around perhaps using the lidar obstacle avoidance and then using something more complicated perhaps the Jetson Nano which I've been playing with which will do vision recognition and it could identify where there are people and it does work on mannequin heads as well and a thousand other objects are already pre trained in a deep learning model we could having actually hunt out specific objects and shooter them so that's something that I might tackle in the future I'm certainly going to be using that technology in other projects alright that's all for now [Music] [Applause] [Music] you
Info
Channel: James Bruton
Views: 111,104
Rating: 4.9437919 out of 5
Keywords: lidar, automomous robot, nerf robot, nerf turret, tracking nerf turret, NERF project, 3d printing nerf project, machine vision, rplidar, arduino lidar project, how to build a robot, how to build a ner
Id: r3hmUBtxNZ4
Channel Id: undefined
Length: 20min 57sec (1257 seconds)
Published: Mon Jun 01 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.