SPIKE 2.x PID Balancer with Scratch for SPIKE Prime / 51515: Gyro Girl

Creator Academy Australia · Beginner ·🧒 Coding for Kids ·6y ago

Key Takeaways

Building and coding a PID balancer robot called Gyro Girl using SPIKE 2.x and Scratch for SPIKE Prime, with a provided PDF guide and optional Python solution for Robot Inventor

Full Transcript

hey guys today we're going to talk about gyro boy well not the classic diary boy from ev3 but the new Jerry boy which I am calling gyro girl because this is the younger lighter sibling of gyro boy this is built with Spike Prime and if you've seen this video I compare a lot of the advantages of spike prime over a v3 and one of the big things was the the squareness of the motors and the hub and it really shows how important that is with a build like this because we can build this gyro balancing robot in about a dozen pieces it's really quite impressive so today we're going to split the video into a few sections you can check out the description if you want to skip to the right section for you ok we're going to start off by building gyro girl and then I'm going to give you a little bit of pseudocode on the balancing code okay go talk about something called PID and then I'm going to show you the actual code that I used in that balancing video full disclosure I haven't played with this robot a lot but can tune it a lot more but I'm going to teach you how to do some tuning yourself so that you can make sure that your robot works in the kind of okay [Music] [Applause] [Music] [Applause] [Music] [Applause] [Music] [Applause] [Music] [Applause] [Music] [Applause] [Music] okay so now that we've built er a girl let's talk a little bit about the pseudocode okay so what are we trying to do to balance this robot well you can think about it as a few different layers okay at the very simplest we are using the onboard gyroscope okay the onboard gyroscope what are we wanting it to do we wanted so that when we are tilting over this way to rotate the motors that way right to rotate so that we move our wheels under where it's four right and then when it's tilting the other way we rotate the wheels back towards where it's falling so far so good right but it turns out that with a very unstable build like this one that you might have seen the test lab robot the test lab robot is a lot more stable because the the weight is between the wheels it's a lot lower and then if it's fallen over there's a better better chance for you to write it back up well for this build it's a little bit different because it is very unstable all right for example if I if I started off lying down it doesn't have enough power to put it back up right so it's very mechanically unstable so if I want to make it so that it starts off balance and I'll need to make sure that I have to stand okay so I need to stand it very close to being balanced before I run the code because that way the and the motors will have enough power to actually correct itself before it falls past a certain point where the motors won't have enough strength to write itself back up okay so the first bit was easy right it's it's almost an if-else statement if it is falling this way we want to move the motors that way okay to go under it it's falling the opposite way we rotate the motors the opposite way pretty simple right but then there is a catch the catch is the motors need to move proportionally to how much it tilting okay because if it is not tilting very much the motors shouldn't have to move very much at all does that make sense whereas in as it was tilting more then the motors will also need to move more so this is called proportional movement okay that means that when we are tilting more we need to move the motors more okay and that puts the P in PID PID of course is proportional integral and derivative controllers okay we did a great video we using a motorcycle example using bike prime over here so check that out if you haven't seen it before but with a proportional part of the code it means that the more that we are off the the target the more we are going to move the motors that makes sense right and a lot of the time that is all you'll meet is to make it so that you are moving proportional to the error but then we have another problem yeah another problem is that we are need to also take into account the momentum of this shift because if I started off upright then I suddenly got knocked and then I suddenly switched over to this side if I just use the normal proportional code it's not going to be enough power right because there is some momentum from the movement of being knocked out knock around or maybe there's a slight breeze or maybe there's a slight bump that moves my robot to tilt more than normal right and that's where we use the integral of the PID controller okay the integral is taking into account the previous readings of my error so that's the integral so the integral is to count how far we are off okay off the target but then also work out the history of how how far we've been off the Italian so that if I was shifting really really quickly then we would also compensate for that by increasing power to the motors more then normally what we would have if we had just used a proportion controller and sometimes the proportional and integral is all you'll need for your robot but then what you'll find is that there'll be a third problem the third problem is that after you have corrected your movement you will overcompensate and then you'll have some wiggle okay and then to smoothen out those those wiggling movements where your robot or your controller is overcompensating then you will need to add something called a derivative which is dpi D and what that does is that smooths out the the compensation so that so that the movement is a lot so that is the pseudocode and hopefully I have made PID a little bit clearer if you want to see more about PID then check out the description underneath because there's plenty of other many more much more technical aspects of PID which I'm definitely not covering off right now but let's have a look at the code for this particular robot okay so you see here that this is the code so here are a bunch of things that I've created a bunch of variables and when the program starts I turn on my smiley face and then I wait for three seconds just to give us enough time to balance out our robot and then I'm setting something called a roll tag because that is the gyro roll setting that that I find is as close to balanced as possible okay so eighty eight point nine five degrees is all this robot going to be very close to being balanced then the power setting is going to be our multiplier for our motor power and then KP ki and KD these are what's called gain values okay gain values are what we use to choose the PID controller yeah so even if you don't have anything else and you just put the shell of all this code in for any of your PID controllers then it will almost always work you just need to tune these these numbers and that is probably the most tedious part of doing a balancing robot like this so these are are the numbers for KP ki and KD their gain values for my balancing robot on Capet if I wanted to make this balance on a table or on wood or on glass or metal then you would probably need to tweak these numbers how do you tweak these numbers well first of all what you do is you'd set everything to 0 okay and then see if it works and then you increase your p-value again your KP which is your your proportional controller and then you'll see that it will start to compensate for your errors and then you keep on increasing it until it looks like you're just going to overcompensate and then you increase your I've al use okay and then after you K and I are almost done and your robot is bouncing quite well then you tweak your D balance okay well I find that that's that's working for me but a lot of people like to do do it using KP first and then KD and then ki it really depends on the robot houghton how what its tendency is to shift around and what its tendency is for Corrections and then I set integral to zero because I find that if I don't set it to zero then he'd always keep storing the value then we set the motors to e plus eight and then this is the forever loop or a PID controller so I set the error to be my roll target which was the a 0.95 - my roll angle which is the the gyroscope inbuilt in my machine and then we set the integral to be the integral plus the error multiplied by 0.25 then the derivative is going to be error minus previous error remember we are trying to find the gap in that error and then we're setting the previous error to error over here and then we set the result which is the actual power that we are going to well part of the actual power that we're going to pump into the wheels to the error x KP this is the proportional part of your PID and then plus I which is integral x ki which is your value of your PID and then derivative x KD your daddy and then finally we just set the motor power or result x power which is our power multiplication Wow power multiplier here there you go this is the code for Shiro girl and a very brief explanation of Choji I'm definitely not doing it justice by explaining it in one video but if you won't want to find out more then make sure you check out all right until next time I'll see you

Original Description

SPIKE 2.x Required PDF building instructions: https://creatoracademy.com.au/collections/files/products/gyro-girl-pdf-instructions Learn how to build and code the successor of Gyro Boy from EV3: Creator Academy's simple balancer robot Gyro Girl! For the Python solution on Robot Inventor, see: https://youtu.be/Yc_FEriEmQ8 In this video, we cover the build of the robot as well as explain how PID works in a balancer robot like Gyro Girl. You can also build the model and code it using LEGO Mindstorms Robot Inventor 51515. 01:50 - Building Gyro Girl 05:40 - PID Pseudocode Explanation 11:40 - SPIKE Prime code For more in-depth science, building and coding on this subject, visit www.creatoracademy.com.au For more technical explanation of PID: For an explanation of PID, check out https://youtu.be/wkfEZmsQqiA LEGO® is a trademark of the LEGO Group of companies which does not sponsor, authorise, or endorse this video.
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Creator Academy Australia · Creator Academy Australia · 50 of 60

1 LEGO Wedo 2.0 Kangaroo and Joey Demonstration
LEGO Wedo 2.0 Kangaroo and Joey Demonstration
Creator Academy Australia
2 LEGO Wedo 2.0 Koala Demonstration
LEGO Wedo 2.0 Koala Demonstration
Creator Academy Australia
3 LEGO WeDo 2.0 Eagle vs Rabbit Demonstration
LEGO WeDo 2.0 Eagle vs Rabbit Demonstration
Creator Academy Australia
4 Animatronic Australia: The Kangaroo
Animatronic Australia: The Kangaroo
Creator Academy Australia
5 How Semiconductors Work: 3D Animation
How Semiconductors Work: 3D Animation
Creator Academy Australia
6 LEGO Wedo 2.0 Koala
LEGO Wedo 2.0 Koala
Creator Academy Australia
7 First impressions and unboxing First Lego League: Into Orbit 2018
First impressions and unboxing First Lego League: Into Orbit 2018
Creator Academy Australia
8 FLL Into Orbit Team Ranking Gears talks about Artificial Gravity
FLL Into Orbit Team Ranking Gears talks about Artificial Gravity
Creator Academy Australia
9 FLL Into Orbit team Ev3lution discusses isolation in space
FLL Into Orbit team Ev3lution discusses isolation in space
Creator Academy Australia
10 PI3-BOT (Pie Bot) Prototype
PI3-BOT (Pie Bot) Prototype
Creator Academy Australia
11 Dynamic display stand for LEGO Bugatti Chiron (preview)
Dynamic display stand for LEGO Bugatti Chiron (preview)
Creator Academy Australia
12 Creative Kids TV announcement featuring Creator Academy
Creative Kids TV announcement featuring Creator Academy
Creator Academy Australia
13 LEGO WeDo 2.0 Guided Lesson: Milo
LEGO WeDo 2.0 Guided Lesson: Milo
Creator Academy Australia
14 LEGO SPIKE PRIME: Turtle Prime Demonstration
LEGO SPIKE PRIME: Turtle Prime Demonstration
Creator Academy Australia
15 LEGO SPIKE PRIME "Wheelchair Prime"
LEGO SPIKE PRIME "Wheelchair Prime"
Creator Academy Australia
16 10 Reasons why EV3 is SUPERIOR to SPIKE Prime
10 Reasons why EV3 is SUPERIOR to SPIKE Prime
Creator Academy Australia
17 Your first launch after installing Python: Python for Kids Webinar Highlight
Your first launch after installing Python: Python for Kids Webinar Highlight
Creator Academy Australia
18 What is "Sharpening the Saw": Python for Kids Webinar Highlight
What is "Sharpening the Saw": Python for Kids Webinar Highlight
Creator Academy Australia
19 Why We Use Comments: Python for Kids Webinar Highlight
Why We Use Comments: Python for Kids Webinar Highlight
Creator Academy Australia
20 Build a Scratch Dinosaur Park (Full Lesson)
Build a Scratch Dinosaur Park (Full Lesson)
Creator Academy Australia
21 Scratch 3.0: Cat and Mouse Game Stream (Krunal)
Scratch 3.0: Cat and Mouse Game Stream (Krunal)
Creator Academy Australia
22 Python Tutorial: Make a Toilet Paper Calculator (Full Lesson)
Python Tutorial: Make a Toilet Paper Calculator (Full Lesson)
Creator Academy Australia
23 Scratch 3.0 Tutorial: Making a chatbot that plays 'heads or tails' (Full Lesson)
Scratch 3.0 Tutorial: Making a chatbot that plays 'heads or tails' (Full Lesson)
Creator Academy Australia
24 Getting Started with MicroPython on SPIKE PRIME (old)
Getting Started with MicroPython on SPIKE PRIME (old)
Creator Academy Australia
25 Easter Egg Game Tutorial in Scratch (Full Lesson)
Easter Egg Game Tutorial in Scratch (Full Lesson)
Creator Academy Australia
26 Accessing Weather API with Python (Highlights)
Accessing Weather API with Python (Highlights)
Creator Academy Australia
27 Accessing Translate API with Python (Highlights)
Accessing Translate API with Python (Highlights)
Creator Academy Australia
28 Scissors, Paper, Rock with Scratch 3.0 (Highlights)
Scissors, Paper, Rock with Scratch 3.0 (Highlights)
Creator Academy Australia
29 Making a really scary game with Scratch 3.0 (Highlights)
Making a really scary game with Scratch 3.0 (Highlights)
Creator Academy Australia
30 Making a Lemmings game with Scratch 3.0 (Highlights)
Making a Lemmings game with Scratch 3.0 (Highlights)
Creator Academy Australia
31 Space Navigation Game in Scratch (Highlights)
Space Navigation Game in Scratch (Highlights)
Creator Academy Australia
32 Scratch Supercat Game (Full Lesson)
Scratch Supercat Game (Full Lesson)
Creator Academy Australia
33 Introduction to Robots with LEGO Wedo 2.0 (Full Lesson)
Introduction to Robots with LEGO Wedo 2.0 (Full Lesson)
Creator Academy Australia
34 Getting Started With LEGO Spike Prime (Full Lesson)
Getting Started With LEGO Spike Prime (Full Lesson)
Creator Academy Australia
35 Scratch Walk Cycle Animation Tutorial (Full Lesson)
Scratch Walk Cycle Animation Tutorial (Full Lesson)
Creator Academy Australia
36 Building a Scissor Lift with LEGO Simple Machines (Highlights)
Building a Scissor Lift with LEGO Simple Machines (Highlights)
Creator Academy Australia
37 EV3 datalogging RPM challenge (highlights)
EV3 datalogging RPM challenge (highlights)
Creator Academy Australia
38 Learning about buses with LEGO (Full Lesson)
Learning about buses with LEGO (Full Lesson)
Creator Academy Australia
39 Make "Flappy Bird" in Scratch 3.0 (Highlights)
Make "Flappy Bird" in Scratch 3.0 (Highlights)
Creator Academy Australia
40 "Memory Arrows" game with Scratch 3.0 Lists (Highlights)
"Memory Arrows" game with Scratch 3.0 Lists (Highlights)
Creator Academy Australia
41 Learning about Gear Ratios with LEGO Simple Machines (Highlights)
Learning about Gear Ratios with LEGO Simple Machines (Highlights)
Creator Academy Australia
42 Scratch 3.0 Bouncing Ball with Stretch, Speed and Acceleration (Full Lesson)
Scratch 3.0 Bouncing Ball with Stretch, Speed and Acceleration (Full Lesson)
Creator Academy Australia
43 LEGO SPIKE Prime Order Tracking Robot (Highlights)
LEGO SPIKE Prime Order Tracking Robot (Highlights)
Creator Academy Australia
44 Scratch 3.0 Race Guesser (Full Lesson)
Scratch 3.0 Race Guesser (Full Lesson)
Creator Academy Australia
45 How Banks Work - a quick explanation for kids
How Banks Work - a quick explanation for kids
Creator Academy Australia
46 SPIKE Prime Safe + importance of passwords (Highlights)
SPIKE Prime Safe + importance of passwords (Highlights)
Creator Academy Australia
47 Combination Safe Coding Guide with LEGO SPIKE Prime
Combination Safe Coding Guide with LEGO SPIKE Prime
Creator Academy Australia
48 LEGO SPIKE Prime Parcel Scanning Robot
LEGO SPIKE Prime Parcel Scanning Robot
Creator Academy Australia
49 Building "Addy" the Addition Chatbot
Building "Addy" the Addition Chatbot
Creator Academy Australia
SPIKE 2.x PID Balancer with Scratch for SPIKE Prime / 51515: Gyro Girl
SPIKE 2.x PID Balancer with Scratch for SPIKE Prime / 51515: Gyro Girl
Creator Academy Australia
51 What is Procedural Programming
What is Procedural Programming
Creator Academy Australia
52 Zombie game in SCRATCH (plus horrifying zombie facts!)
Zombie game in SCRATCH (plus horrifying zombie facts!)
Creator Academy Australia
53 Swarming Bugs Scratch Game
Swarming Bugs Scratch Game
Creator Academy Australia
54 LEGO Mindstorms/SPIKE Prime Scanner and Printer
LEGO Mindstorms/SPIKE Prime Scanner and Printer
Creator Academy Australia
55 Fishing Game with SCRATCH (For Fathers Day!)
Fishing Game with SCRATCH (For Fathers Day!)
Creator Academy Australia
56 Measuring Paper Plane Speed with SPIKE Prime Line Graphs
Measuring Paper Plane Speed with SPIKE Prime Line Graphs
Creator Academy Australia
57 Comparing Mindstorms Robot Inventor and SPIKE Prime
Comparing Mindstorms Robot Inventor and SPIKE Prime
Creator Academy Australia
58 Code a 'Knock Knock Joke' game in Scratch 3.0
Code a 'Knock Knock Joke' game in Scratch 3.0
Creator Academy Australia
59 Creator Academy Australia Live Stream
Creator Academy Australia Live Stream
Creator Academy Australia
60 Discovering LEGO Mindstorms/SPIKE Gyro Pitch Deadzone
Discovering LEGO Mindstorms/SPIKE Gyro Pitch Deadzone
Creator Academy Australia

Learn to build and code a PID balancer robot called Gyro Girl using SPIKE 2.x and Scratch for SPIKE Prime, with a focus on kids coding and robotics concepts. The lesson includes a PDF guide and optional Python solution for Robot Inventor.

Key Takeaways
  1. Build the Gyro Girl robot using the provided PDF instructions
  2. Code the PID controller using Scratch for SPIKE Prime
  3. Test and calibrate the robot's balance
  4. Optional: Write Python code for Robot Inventor
💡 Using PID controllers and Scratch programming can help kids develop essential coding and robotics skills, while building a fun and interactive project like Gyro Girl.

Related Reads

Chapters (3)

1:50 Building Gyro Girl
5:40 PID Pseudocode Explanation
11:40 SPIKE Prime code
Up next
Robotics Workshop at IST Hyderabad | Coding to Real-World Applications | Intellipaat School
Intellipaat
Watch →