Weaponizing our Robot - Robotics with Python Raspberry Pi and GoPiGo p.5

sentdex · Beginner ·🛠️ AI Tools & Apps ·10y ago

Key Takeaways

This video demonstrates how to control a USB missile launcher using a Raspberry Pi and GoPiGo, with Python programming, to create a robotic system that can aim and fire foam missiles. The project utilizes various tools and techniques, including keyboard input, control buttons, and potential future integration with Open CV for image recognition.

Full Transcript

What's going on everybody? Welcome to part five of our robotics with the Raspberry Pi tutorial video series. In this part, we're going to be talking about how we can control that USB cannon. Now, uh if you don't have the Canon, you want to get one, I'll put a link to it in the description so you can check that out. Otherwise, let's get to it. So, first of all, uh there is some sample code uh that came with the GoP to work with the Canon. You'll need you would need a uh USB mouse connected to the Go Pi or the Raspberry Pi itself in order to make it work. But instead, I'd like to do this and be able to control that cannon remotely. And then eventually we we just want to be able to get comfortable with it so that we can write code and logic that can control this cannon all on its own. So first of all, let's check out the code uh that that came from Go basically. So we can go to homepi and then go into gopy go software python examples and then we're looking for the office cannon. So we'll double click there and here's office cannon v1.py. So let's go ahead and open that up. And in here we can see that we've got all these imports. Most of these basically all these you should have besides the USB uh stuff. So, uh, just for the record, I think if you get this from if you get the card from GoP, uh, you will already have PI USB. Otherwise, you're going to want to come over here and if you haven't already done pseudoapp get update update and then go ahead and do pseudoapp get uh, install python-pip. And then once you've done that and you have uh pip do pip install pi USB, install all that and you should be all set. So now we have the uh code here. And what we're going to go ahead and do is basically we'll take this and copy that and then come all the way down here and we'll at least copy down to here. We'll copy that. Let me set this aside for now. Um, actually we might have to recopy that. But, uh, go over to homepi desktop goal. And I'm going to go ahead and rightclick here, duplicate. And I'm going to duplicate this to tutorial 5.py. And then I'm going to open that up. And then we've got our key input here. I'm going to do enter enter. Just a few enters here. And let's uh come back over to the original script here from Office Cannon. Rightclick, copy, and then we'll just paste all that in there. Uh now, control. We don't really need uh well, we're going to leave that there for now. And then coming down here, we can see there's some basic code here. Uh and this is we basically want all of this for sure. So, we'll take that and we're going to go ahead and copy that starting code and we're going to come over here above the command stuff and we'll paste and then highlight that block of code and then do control open square brackets two times. Get that to come on over. Now, uh we have the basic setup here. Um I'm trying to think of anything will cause problems. I believe probably the only thing that'll cause us trouble at the moment is going to be maybe time delay, but we should be all set. So, I'm going to go ahead and move this over. And now what we want to do is we want to add controls for the actual um for key input here. So, we've got all this stuff here, and this is to control the Pi. But now, we've got this stuff for the missile launcher. So now we want to add in some controls for the missiles. So let me make the size a little bigger. And I'm going to pull this up. And so we're within the key input function. So coming on down after our definition basically of the let me do this um of what we're going to do with the servo. Let's make some [Music] space. And what we're going to add here is first of all the fire. So we're going to ask uh we'll use the control buttons for fire since space is occupied as stop. So we're going to say uh l if key press double equals control_r or key press equals uh control l. If either of those is the case, then we want to we'll go ahead and print fire rockets. And uh just moving I'm you don't have to bring yours over, but um let me do control F rockets. There we go. So to fire the rockets, just looking at the code for the office cannon that we took. Uh this is basically because we were you can use your mouse to do it, but we're not going to worry about that. Uh, so the command to actually fire the rockets is uh run command fire and then t delay, which I'm not sure this we're probably not going to have that, but we'll go ahead and copy that. Come down here and then bam. Run command fire and then t delay. So now we're going to check out run command. Um, and in fact, let's go ahead and uh let's global t delay here. And actually, let's see where is Let's find the time delay. Anyway, um figure out. Yeah. So, it it's right here. Uh let's go ahead and just actually let's take this cut and let's just put that at the very top of our script. I'm just going to paste it here. Okay. So, put time delay there. If you if you couldn't find it, just search for t delay. Uh and you just you're looking for when it's actually defined. Um, so mine's here, but you'll you can find it and it'll actually be in one of your functions there. So just take that and put it to the top. That way you can reference time delay uh in the rest of your script. So then coming down here. So that was to fire and we're we're saying the fire is going to be with one of your control keys. Now what we want to do is actually be able to control because the the missile launcher itself is on a sort of turret. So what we're going to do is we're going to define all the controls for like moving the turret around. So, for example, we can do that with our arrow keys. So, we're going to say l if key press equals uh left. What we're going to do is we'll just print out left rockets. And then we do run command. And the command we want to run is left for the rockets. And then we want to delay it with time delay. Okay. And now we're going to go ahead and copy that and paste it three more times for the other controls. So copy, paste, paste, paste. So we've got left, right, right, and right. And then we're going to have up, up, up, and then down, down, and down. So then these are the commands that we'll hopefully be able to pass to our uh missile launcher with the on the turret there. So let's go ahead and save that. So that's tutorial five. And we'll bring over our remote desktop here. We'll open up the terminal. And let me make that terminal full size for everybody. And then we're going to navigate to uh where we're writing the script which is cd into desktop. I'm in go pi go local and you see tutorial 5. So now pseudo python tutorial 5.py. We'll go ahead and run that. And it takes a little bit to first set up, but you can see that it's running that initial code there to move the turret at least. And we know it's set once this TK win window comes up. So the reason why I just moved just then is that initial setup here. So that sets up the USB there. We run this code and then we run this command zero and then 100 there. Interesting. Skype is hacking me apparently. So anyway, run command 0 100 and then we're stopping and and like waiting for more commands. So that's just that's built in. that was part of the uh go pi go. So we can literally check for zero here, right? So run command zero. Basically all this does is moves our cannon down and to the left by this much. So um just keep that in mind. Now uh I'll save that. But we should be able to run now. So first we'll check forward. Okay, stop. Backwards stop. And now we can test our arrow keys to hopefully move our missile launcher left. We'd already moved all the way left, so now we're moving it right. No problem. We can move it up, down. Awesome. Move it around. And then now we'll try control to actually fire the cannon itself. Sure enough, I just shot myself. Awesome. Hit me right in the back. All right. So, uh, now we're able to actually control our robot with our keys. And what's nice about that is now that we can control it with our keys, that also means that we can actually start to build Python logic to start to control our uh, go and then eventually we can make it fully autonomous and then we can make it shoot stuff based on logic and we don't even have to do anything. So, um, hopefully you guys got to that point. the uh USB missile launcher. I think it's just super cool. I realized it was $45, but uh the cool factor is just so high for me. And I love how you can move it up, down, left, and left and right. And probably what I'll end up doing is maybe even taping or something the uh Raspberry Pi camera module to the uh missile launcher to actually see where we're going to fire. Uh the distance sensor we may leave it on, but it would also be nice to have the distance sensor on the missile launcher because then you can actually do the calculation of how far is the target and then we can kind of move the turret up to account for, you know, making that distance, but that'd be really complex. We'll probably keep it a little more simple than that. We're already going to try to do image recognition with Open CV, so we might avoid doing that. But anyway, pretty cool. I love the little cannon. I love that you can like shoot it and it actually shoots pretty far. I mean, this this will actually get across my room if I fire this. I mean, that goes all the way across my room. My room's not huge or anything, but pretty cool. So, anyways, if you guys have any questions or comments up to this point, please feel free to leave them below. Otherwise, as always, thanks for watching. Thanks for all the support and subscriptions, and until next time. Oh, and I forgot to mention uh how I actually mounted the missile launcher on there. Really simple. I just used uh some tape and made it double-sided tape, stuck it on there, and that works good enough. So, anybody who is curious how I did that, that's literally all I did. You could glue it on there if you really wanted it to stay, but I didn't. I just used painters tape, honestly, and made a little loop, stuck it on there, and uh that was more than enough to keep that thing steady. So anyway, figured people might be curious how it actually got on there. Anyway, till next time.

Original Description

Using our USB missile launcher, which can be found here: http://amzn.to/1JcXKwY We can add this into our program to allow us to also aim and fire some foam missiles. Text-based version: http://pythonprogramming.net/usb-foam-cannon-robot-gopigo-tutorial/ http://pythonprogramming.net https://twitter.com/sentdex
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from sentdex · sentdex · 0 of 60

← Previous Next →
1 Matplotlib Python Tutorial Part 1: Basics and your first Graph!
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
2 Python Encryption Tutorial with PyCrypto
Python Encryption Tutorial with PyCrypto
sentdex
3 Python's Logging Function
Python's Logging Function
sentdex
4 wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
5 wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
6 wxPython Programming Tutorial 3: Menu Bar and Menu Button
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
7 wxPython Programming Tutorial 4: Panels
wxPython Programming Tutorial 4: Panels
sentdex
8 wxPython Programming Tutorial 5: User Input Saved To Variables
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
9 wxPython Programming Tutorial 6: Multiple Choice Input
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
10 wxPython Programming Tutorial 7: Adding Static Text and Colors
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
11 wxPython Programming Tutorial 8: Custom Button Images
wxPython Programming Tutorial 8: Custom Button Images
sentdex
12 wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
13 Basic PHP Tutorial 13: Multi-dimensional Array
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
14 Basic PHP Tutorial 15: Functions and Global Variables
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
15 Basic PHP Tutorial 12: Associative Array
Basic PHP Tutorial 12: Associative Array
sentdex
16 Basic PHP Tutorial 14: Foreach loop
Basic PHP Tutorial 14: Foreach loop
sentdex
17 Basic PHP Tutorial 16: Include and Require
Basic PHP Tutorial 16: Include and Require
sentdex
18 Basic PHP Tutorial 7: Assignment, comparison and Logical operators
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
19 Basic PHP Tutorial 4: Variables and Comments
Basic PHP Tutorial 4: Variables and Comments
sentdex
20 Basic PHP Tutorial 11: Arrays part 1, basic array
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
21 Basic PHP Tutorial 6: If else and else if conditionals cont'd
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
22 Basic PHP Tutorial 1: Intro to PHP
Basic PHP Tutorial 1: Intro to PHP
sentdex
23 Basic PHP Tutorial 3: HTML with PHP
Basic PHP Tutorial 3: HTML with PHP
sentdex
24 Basic PHP Tutorial 9: While Loop
Basic PHP Tutorial 9: While Loop
sentdex
25 Basic PHP Tutorial 10: Switch Statement
Basic PHP Tutorial 10: Switch Statement
sentdex
26 Basic PHP Tutorial 2: Print and Echo
Basic PHP Tutorial 2: Print and Echo
sentdex
27 Basic PHP Tutorial 5: If else and else if conditional statements
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
28 Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
29 Basic PHP Tutorial 17: User Input Form Example / String Manipulation
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
30 Basic PHP Tutorial 18: HTML Entities and forms cont'd
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
31 Basic PHP Tutorial 19: Finding words in strings
Basic PHP Tutorial 19: Finding words in strings
sentdex
32 Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
33 Basic PHP Programming Tutorial 22: Hashing part 2: salting
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
34 Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
35 Basic PHP Programming Tutorial 21: MD5 Hashing For Security
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
36 Basic PHP Programming Tutorial 24: String similarity
Basic PHP Programming Tutorial 24: String similarity
sentdex
37 Basic PHP Programming Tutorial 25: Time and Time stamps
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
38 Basic PHP Programming Tutorial 26: Die and Exit
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
39 Basic PHP Programming Tutorial 27: MySQL Databases Part 1
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
40 Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
41 Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
42 Basic PHP Programming Tutorial 30: MySQL database in Use
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
43 Django Tutorial Web Development with Python Part 1: Installing Django
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
44 Python Tutorial: File Deletion and Folder Deletion / directory deletion
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
45 Python Tutorial: How to Rename Files and Move Files with Python
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
46 3D Graphs in Matplotlib for Python: Basic 3D Line
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
47 3D Plotting in Matplotlib for Python: 3D Scatter Plot
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
48 3D Charts in Matplotlib for Python: Multiple datasets scatter plot
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
49 Sikuli Tutorial 1: Visually programming in python!
Sikuli Tutorial 1: Visually programming in python!
sentdex
50 Sikuli Tutorial 2: Program visually in python!
Sikuli Tutorial 2: Program visually in python!
sentdex
51 Sikuli Tutorial 3: Program visually in python!
Sikuli Tutorial 3: Program visually in python!
sentdex
52 3D Bar Charts in Python and Matplotlib
3D Bar Charts in Python and Matplotlib
sentdex
53 3D Plane wire frame Graph Chart in Python
3D Plane wire frame Graph Chart in Python
sentdex
54 Raspberry Pi Part 1 Introduction
Raspberry Pi Part 1 Introduction
sentdex
55 Raspberry Pi Part 8: First Download and Update! (Firmware)
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
56 Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
57 Raspberry Pi Part 11: Remote Desktop
Raspberry Pi Part 11: Remote Desktop
sentdex
58 Twitter Analysis: How to rank a user's influence
Twitter Analysis: How to rank a user's influence
sentdex
59 GPIO Tutorial for Pi Part 2 - Programming the GPIO
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
60 GPIO Tutorial for Raspberry Pi Part 1 - Setting up
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex

This video teaches how to create a robotic system using a Raspberry Pi, GoPiGo, and Python to control a USB missile launcher, with potential applications in autonomous systems and image recognition. The project demonstrates hands-on skills in device control, programming, and system integration. By following the steps outlined in the video, viewers can learn how to design and build their own robotic systems.

Key Takeaways
  1. Copy sample code from GoPiGo
  2. Duplicate the script to create a new file
  3. Paste code into the new file
  4. Add controls for the missile launcher using keyboard input
  5. Define controls for moving the turret around with arrow keys
  6. Run command fire and then t delay to fire rockets
  7. Move the turret left, right, up, and down with arrow keys
  8. Test arrow keys to move missile launcher left, right, up, and down
  9. Fire cannon with control key
💡 The video demonstrates how to integrate a USB missile launcher with a Raspberry Pi and GoPiGo, showcasing the potential for creating complex robotic systems with Python programming.

Related Reads

Up next
What is OAuth 2 0 Explained with Examples
VLR Software Training
Watch →