Programming Remote Control - Robotics with Python Raspberry Pi and GoPiGo p.4

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

Key Takeaways

This video demonstrates how to control a GoPiGo robot remotely using Python, Raspberry Pi, and Tkinter for GUI and key presses, with tools such as Gooey Desktop, xrdp, and Remote Desktop Connection for remote desktop connection.

Full Transcript

what's going on everybody Welcome to part four of our robotics with the raspberry Pine tutorial Series in this part we're going to build on our last script uh our last script from tutorial 3 was the following it just basically moved our our robot forward and back we can run that again real quick just a really simple script that just ran it forward and backwards now what we're going to do is create a full kind of user controlled scenario now in order to do what I want to do we're going to need access to the kind of gooey Des desktop or what's called X now there's a couple of ways that we can do this but the the way to do it remotely is either with a VNC or with something like xrdp which is sort of a VNC but we can use that with windows so windows isn't really the most VNC friendly operating system but with the remote desktop we can do it really simply so if you're on Windows what you might be able to do or get away with is to do pseudo apt get install xrd and P and run that now I already have that so nothing's going to happen if for some reason it says you know uh cannot find this package or something's going wrong make sure you run a pseudo app to get update and also do a pseudo app to get upgrade uh and that and then try to run it one more time otherwise uh you you might not be finding your packages for a different reason now um in this tutorial what we're going to do first is I'll wait for this stuff to kind of go away uh but once you once you add um actually I can probably connect now but my processor is probably uh in use but anyway if you're on Windows and you've installed xrdp all you do is go to your start bar and go to remote desktop connection if you don't if you can't find it just literally search for remote desktop we'll click on that and up Pops this and then in here is where you put your local IP address to the Raspberry Pi now mine's on uh 192168 0109 so that's where I'm going to connect so I'll hit connect it might be pretty slow again because the pi is doing stuff but anyway you'll probably get this little you know uh check thing to see if you really want to connect to that yes and then here you'll log in you already know your information Pi raspberry is probably your password and then you'll kind of connect it might take a second again for me because my Raspberry Pi is doing these updates but um this will load and then it basically loads into the desktop version of the Raspberry Pi so there we have it now you might actually have a different background than me I started with a default raspian image and I installed the uh the Goyo software but if you started with the their Dexter Industries Goyo uh image you probably have a different background now once you get here um we're going to go ahead and just set this kind of aside for now but you need to make sure you can actually achieve this kind of desktop connection but I'm going to move it over for now and now what I'm going to do is tutorial 3 right click and I'm just going to duplicate it you can do whatever you want but I'm just doing that to make a new file and we'll call it tutorial 4py yes you'll probably have to enter your password again I didn't I guess cuz I have it saved anyway open up tutorial 4 and now you're ready to rumble now what we're going to do is I'll just remove all this and we're going to need the following we're going to import tter capital T as TK and then from go pyo import all again and in this tutorial we're going to cover going forward backwards Left Right rotate stop grab the distance from the distance sensor and also move the servo if you don't have a distance sensor just don't worry about it don't code that part right uh if you don't have the servo don't worry about it don't code that part everything else will work just fine so uh first we're going to uh have a little bit of a constant up here it'll be Servo range and that's going to equal a list of values 2 3 4 5 6 7 and eight I'll explain that when we get there to the to the actual code down at the bottom now uh at the very very bottom we're going to say command equals uh tk. TK pay attention to the casing there and then we're going to say command. bindall and then in quotes here key with those brackets and then key input okay and then finally we run command. main Loop and all this does is it this is going to open up a basic tenter window and then it's going to start tracking all the key presses that we press and for every key press that happens it's going to run key input with that key vent so key input doesn't exist yet so we're going to write a uh the key input function now so we're going to Define key input and the uh event will just call that literally event now to find out the key that was pressed we're going to say key press equals events. key SIM for key symbol. lower just in case uh caps come into play and then we'll do print key press like that so we'll go ahead and save that for now and let me make it small enough to make sure that went over and then what we'll do is let's bring over the remote desktop thing now and let's double click on LX terminal and when that pops up we need to navigate our way into the um the Go Local but I'm also going to make my font larger so everybody can see it really well awesome okay so now LS here CD into desktop Go py Go Local list out the stuff there's tutorial 4 so I'm going to go pseudo Python tutorial 4. piy hit enter and hopefully yep there's our tner window now as long as we're active in this window we'll click on that and I can press keys right WS d a d space uh U or no I hit I and so on it's a very simple kind of single key at a time logger okay so we're that far that was successful and now what we can do is assign functions when various keys are pressed so moving this aside we we'll keep printing the key press just so we can see it um and let me move this down a little bit so now that we've got that what we can start asking is just a bunch of if statements so we can say if key press equal equals uh W what do we want to do well we want to run FWD simple enough then we can go uh L if key press equals s what do we want to do well if it's an S we want to go backwards so bwd and then we'll keep this going so I'm instead of typing L if and equals all the time I'm just going to paste paste paste a space pce paste a few in there we might not I don't think we'll use all of those but it'll save us some time so we want to handle for WS a d q e and space and then the letter U and we'll leave this one for now empty okay so going back up ws and then a uh we want that one not be backward a will be left D will be right Q will be left rot for left rotate e will be right rot for right rotate and then the space key will be to stop whoops to stop the bot and then U will be for the distance sensor so if you don't have a distance sensor just get rid of this right but if you have one we'll use youu and the U is just for ultronic distant sensor um that's going to be the following we'll just we'll just print it out for now this will just be the distance so print and then us uh for Ultrasonic sensor disc and then you give the pin number if you plugged in the ultrasonic distance sensor by their uh instructions the pin you plugged it into is probably 15 so there's that now uh what we're going to do is I think we we'll just leave everything now so that should do for all the things that we need so we'll save that we'll come down uh back to our guey bring that over here apparently I am lost on here I got like off the screen I guess there we go rerun that and then the uh tter window should pop up there it is and then now let's just try for forward command so you should see that the wheels on mine are spinning and yours should be spinning too let's try backwards sure enough now it's going backwards let's try a rotate um so I'll hit q and then now they should be spinning in opposite directions let's try e now they should spin in the other opposite direction now let's try to stop this thing space cool so now we can actually remote control our La our laptop remote control our gopy go with our keyboard now before we go on to the next tutorial I do want to show the servo as well so what I will'll do and if you don't have a Servo then you can pretty much just jump to the next tutorial but if you do have a Servo or you want to know how we're going to handle for the servo here's all we would do it's pretty quick code so we're going to say l if keor press. is digigit because the key press is coming through as a string but what you can do to find out if a string is actually a number that's in a string format you can just ask is digit that it's a booing so it comes through is either true or false so if you've got if the D if the you know the string is five and you say if five. is digit even though it's a string it's going to come back as a true because yes five is a is a digit so if the key press is a digit the next thing that we're going to ask is if in if the integer value of the key press is in our Servo uncore range we're going to enable the servo cuz otherwise it's not going to be enabled and then we're going to go we're going to say Servo and then we basically want to set the servo and you set it to a value and this value is going to be the integer value of the key press times 14 this just worked out for my Servo it just seemed like a good number and basically this will be to the point where 5 * 14 so 70 is the center point basically for the servo about depends on how well you screw the servo in mine was a little crooked so your number might be a little different but um you do that and then 2 to8 will be kind of sweeping motion and again depending on how well you hooked up your Servo and how long your camera if you have a camera on there uh my main issue was that the camera cord basically is not very long so if you rotate all the way over in One Direction you basically run out of camera cord and you're pulling on that cord and so I didn't want want to do that but if you don't have a camera you can actually rotate this thing around quite a bit anyway we set the server to that number and then we'll go ahead and disable the servo now yours might be a little different I don't know but for some reason it I just enable the servo set the servo and disable it because the servo like it'll just keep kind of like wiggling a little bit if you don't disable it so I disable it to shut it up and stop it from wiggling so much but I think part of that is because there's a little bit of resistance that is coming from that camera module so I think that's why it's doing it so disabling it seems to help a lot but uh again yours might defer from mine so anyways we'll save this and I'm actually done there so I'm going to move that out of the way and um this logged my my key anyway uh we're going to close this and have to rerun it so it's running the new version of tutorial 4 okay so now it's up we can go forward stop and then now you can start pressing your s or your buttons for the servo range and you should see that the servo actually moves now we probably should have added a slight time uh cuz now like like this is two and then eight I'm pressing eight but it takes a few presses to get it over so actually maybe what we might want to do is give it a slight sleep maybe uh time do sleep one let's just try that real quick I'm not sure that I'll uh I can't remember if the servo will just keep running or not but we'll find out in a moment so that pops up let's try two yeah there we go so 8 five now that yeah so with that 1 second that's enough time for it to actually get to the point where it wants to be and then you can actually I can hear it you probably can't hear it on the mic but I can hear it kind of wiggling and then it's disabled and shuts up but anyway so now you can control the servo position with your keyboard so that's pretty cool um so anyways that's that for this tutorial now we're able to control our robot move forward backward I pressed way too many keys it's going crazy move forward backward rotate uh we never checked the distance so I'll hit you and now you can see the distance is 677 CM from the point of fire which is going basically all the way across my room so yeah that makes a lot of sense so that's it for the basic control of your gopy go in the next tutorial we're going to be talking about controlling the missile launcher on our go so that'll be very exciting if you have any questions or comments up to this point please feel free to leave them below otherwise as always thanks for watching than for all the support and subscriptions and until next time

Original Description

While it is not our final stop, learning to control your robot remotely can still be fun. Who doesn't want to sometimes turn on the camera, arm the missile launcher, and shoot friends, family or significant others from time to time? We'll make use of Tkinter's event handling for key presses to let us program our robot to be controlled remotely by us. Text-based tutorial: http://pythonprogramming.net/remote-control-robot-programming-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 control a GoPiGo robot remotely using Python, Raspberry Pi, and Tkinter, covering key press handling, GUI programming, and servo control. By following this tutorial, viewers can build their own robotic projects and integrate AI with robotics.

Key Takeaways
  1. Install xrdp on Raspberry Pi
  2. Connect to Raspberry Pi using Remote Desktop Connection on Windows
  3. Import Tkinter and GoPiGo libraries in Python script
  4. Define key_input function to handle key presses
  5. Assign functions to various keys for robot control
  6. Use ultrasonic distance sensor for distance measurement
  7. Control the servo position with the keyboard
💡 The GoPiGo robot can be controlled using a keyboard with forward, backward, rotate, and stop commands, and the servo's position can be set using the Servo.set() function.

Related Reads

📰
How I Built a Free Online Image & PDF Processing Platform with Vue 3 + FastAPI
Learn how to build a free online image and PDF processing platform using Vue 3 and FastAPI, and discover the benefits of combining these technologies for efficient file processing
Dev.to · IAMUU
📰
I Built a Free AI-Powered YouTube SEO Toolkit With Zero Budget. Here’s What Actually Happened.
Learn how a solo dev built a free AI-powered YouTube SEO toolkit with zero budget and the lessons they learned from the experience
Medium · Startup
📰
How to Create a Second Version of Yourself Inside Obsidian Using AI (Step-by-Step Guide)
Learn to create a second version of yourself inside Obsidian using AI with a step-by-step guide
Medium · ChatGPT
📰
How to prepare for Spain civil service TIC exam using AI in 2026
Learn how to prepare for the Spain civil service TIC exam using AI in 2026, boosting your chances of success with technology-driven study techniques
Dev.to · David García
Up next
I Asked Gemini to Build a Dashboard... I Didn't Expect This
Patech
Watch →