LogoLogo
Follow Us
  • Introduction
    • Overview
    • Welcome
      • Create Your Character
      • Visit the Garage
    • Get Parts
  • Tutorial
    • Your First Bot
      • Parts
      • Chassis
      • Decoration
    • Controls
      • Install Hub Firmware
      • Load Program Onto Hub
      • Using Your Controller
    • Next Steps
  • Battle
    • Rules
      • Crafting Rules
      • Battle Rules
    • Build Your Arena
  • Adventure
    • Quests
      • Sinkhole Patrol
      • Dance Video
      • Martinez Twins vs VentureState
      • Big Break
    • Lore
      • Places
        • Stardust Springs
        • Zoe's Garage
        • Bot Battles Stadium
      • Characters
        • Lily Ishii
        • Zoe Foxlin
        • Ethan Hill
Powered by GitBook
On this page
  • Rewards
  • Best Recycler Takes It
  • Variables
  • Objects
  • Xbox Joystick
  • While Loop
  • From the Top
  • Make it Pop
  • Fire
  • Legend
Export as PDF
  1. Adventure
  2. Quests

Dance Video

PreviousSinkhole PatrolNextMartinez Twins vs VentureState

Last updated 3 months ago

Rewards

  • 🏆 250 XP

[Stewskee] WHAT. IS. UP! YOUR BOY STEWSKEE HERE WITH THE COLLAB Y'ALL BEEN BEGGING FOR. THAT'S RIGHT. I'M HERE WITH THE CREATOR OF THE SINKHOLE PATROL BOT. WHAAAAT.

Psst... hey... lean into this shot for the intro. Look real serious. Yea alright. Got it. Appreciate it.

You want a selfie or something? Wait. You don't know who I am? FOR REAL? Braeden? Braeden Stewart? @stewskee? 2 million followers? I guess you're not one of 'em.

Check this out. So I'm livestreaming during that insane storm. I turn a corner and there's this GIANT SINKHOLE. And this bot is RIPPING circles around it. WHAT.

Chat goes nuts. The clip blows up. My followers DOUBLE. Everyone's DM'ing me about this bot.

The algorithm's begging for more sinkhole bot. Gotta get more content out of it. So I got this idea.

DANCE VIDEO.

Picture this. We drop a track. Your bot dances to it with its signature spin moves. ARE YOU KIDDING ME. 5 million followers EASY.

You'll do alright too. You'll get your name out there. Launch your bot crafting career. Inspire more builders to get started.

Meet me here tomorrow and we'll shoot. Actually - this background is TRASH. Meet me over there instead. Just one thing. Make sure your bot can spin with the beat. The dance has gotta be perfect.

Best Recycler Takes It

[Zoe Foxlin] Bot code? For a dance video!? With Stewskee!?! Omg yes. I'm fangirling right now.

Just like last time, make sure you've got a bot with wheel motors, like the Purrmenator. The left motor has to be plugged into port A.

Let's start with the old code we found online for the sinkhole bot.

# Import modules
from pybricks.hubs import TechnicHub
from pybricks.pupdevices import Motor
from pybricks.parameters import Button, Color, Direction, Port, Side, Stop
from pybricks.tools import wait, StopWatch
from pybricks.iodevices import XboxController

# Set motor power
power = 20

# Set up controller
controller = XboxController()

# Set up motor
motor = Motor(Port.A)

while True:

    # Rotate motor
    motor.dc(power)

We turned this into a mean patrolling machine by changing its motor direction and power. But for a dance video, you don't need a self-driving bot. You need a bot you can steer with your Xbox controller to make it whip back and forth with he music.

Variables

We'll need to understand more about the code so we can figure out what to change.

Last time we just changed the power number. What's actually going on when we do that? Let's look at the line.

power = 20
  • power is a variable. A variable is like a box for storing things.

  • = tells the computer to store something in the box.

  • 20 is a number. 🤯🤯🤯

So this line stores the number 20 in a variable named power.

🤔 If we're bothering to store that number 20, it probably means we're using it again later. Let's look through the rest of the code. See if you can find another line where the variable power appears.

# Import modules
from pybricks.hubs import TechnicHub
from pybricks.pupdevices import Motor
from pybricks.parameters import Button, Color, Direction, Port, Side, Stop
from pybricks.tools import wait, StopWatch
from pybricks.iodevices import XboxController

# Set motor power
power = 20

# Set up controller
controller = XboxController()

# Set up motor
motor = Motor(Port.A)

while True:

    # Rotate motor
    motor.dc(power)

There it is, right at the end.

    # Rotate motor
    motor.dc(power)

Thanks to the comment, we know what this line does. It rotates the motor. And it uses our power value for the rotation power.

Any time we write the variable power, the computer uses the value stored inside it. We know that power is storing the number 20. So when we write...

    motor.dc(power)

... the computer basically does

    motor.dc(20)

Objects

What's up with this motor thing? Where does it come from? Let's look earlier in the code. See if motor appears anywhere else.

# Import modules
from pybricks.hubs import TechnicHub
from pybricks.pupdevices import Motor
from pybricks.parameters import Button, Color, Direction, Port, Side, Stop
from pybricks.tools import wait, StopWatch
from pybricks.iodevices import XboxController

# Set motor power
power = 20

# Set up controller
controller = XboxController()

# Set up motor
motor = Motor(Port.A)

while True:

    # Rotate motor
    motor.dc(power)

There it is.

# Set up motor
motor = Motor(Port.A)

Looks like motor is another variable. But instead of storing a number like 20, we're storing something else: Motor(Port.A).

  • Motor(Port.A) is an object. It represents the motor plugged into hub port A.

So this line stores a motor object in the variable motor. And we use this motor variable later on to actually rotate the motor, just like we did with the power variable.

Xbox Joystick

We want our Xbox joystick to control the rotation power. So instead of storing 20 or 100 or whatever in the power variable, we want to store the joystick's position.

First we'll need to set up our controller. That was already done in the code we found online. Check out this line.

# Set up controller
controller = XboxController()

Looks a lot like the line where we set up the motor. And it works almost the same way.

  • controller is another variable.

  • XboxController() is another object. This one represents our controller.

So we've stored the controller. Hmm, how do we get its joystick position? Joystick position. Joyyyyyystick position. I'm stuck again.

Oh wait, I think I've done this before! When I get stuck on a coding problem, I try to remember if it's something I've coded before. That way I can look at my old programs, instead of trying to find a random example online.

I've definitely written joystick code for other bots. Let me dig through some old files. There it is!

# Get joystick's vertical position
controller.joystick_left()[1]

Good thing I left a comment. Thanks, old me. 🤝 So this code will get the joystick's vertical (up/down) position from our controller.

On the line where we set power, let's replace the 20 with my joystick code.

# Set motor power
power = controller.joystick_left()[1]

The final code should look like this.

# Import modules
from pybricks.hubs import TechnicHub
from pybricks.pupdevices import Motor
from pybricks.parameters import Button, Color, Direction, Port, Side, Stop
from pybricks.tools import wait, StopWatch
from pybricks.iodevices import XboxController

# Set motor power
power = controller.joystick_left()[1]

# Set up controller
controller = XboxController()

# Set up motor
motor = Motor(Port.A)

while True:

    # Rotate motor
    motor.dc(power)

Load the program onto your hub and turn on your controller. Once your controller connects, try moving the left joystick up and down.

And away we gooooo.... hmm. It's not working.

While Loop

What the heck. It really seems like this should work.

When I can't figure out why my code isn't working, sometimes I ask an AI chatbot. I pasted in all the code, and I asked:

why can't I control the motor power?

It said:

power is only being set once, right when the program starts. Move it inside the "while loop" so it's set continuously from the joystick.

Ah ok! Good chatbot. 🫳🐶 Take a look at these lines at the end of the program.

while True:

    # Rotate motor
    motor.dc(power)

This is called a "while loop." The line while True: starts the loop. The code inside it will run over and over. It repeats until humanity goes extinct. Or until your hub runs out of battery. Whichever comes first.

The chatbot says we need to set our power variable inside the while loop. Let's move it inside.

while True:

    # Set motor power
    power = controller.joystick_left()[1]

    # Rotate motor
    motor.dc(power)

Note that all the lines inside the loop are indented. That's not an accindent. 😂 The indents tell the program that these lines are "inside" the while loop.

The full program should look like this.

# Import modules
from pybricks.hubs import TechnicHub
from pybricks.pupdevices import Motor
from pybricks.parameters import Button, Color, Direction, Port, Side, Stop
from pybricks.tools import wait, StopWatch
from pybricks.iodevices import XboxController

# Set up controller
controller = XboxController()

# Set up motor
motor = Motor(Port.A)

while True:

    # Set motor power
    power = controller.joystick_left()[1]

    # Rotate motor
    motor.dc(power)

Load it up. Connect your control, and give that left joystick a push!

From the Top

Remember when we first saw this program? It looked like gibberish. Well now it actually makes some sense! Let's look at it one last time from the start.

# Import modules
from pybricks.hubs import TechnicHub
from pybricks.pupdevices import Motor
from pybricks.parameters import Button, Color, Direction, Port, Side, Stop
from pybricks.tools import wait, StopWatch
from pybricks.iodevices import XboxController

Don't worry about these lines. They add modules. Basically premade code that lets our program work. Just be sure to paste them at the start of every bot program you make.

Next line. We know this. What does it do?

# Set up controller
controller = XboxController()

Next! What does this do?

# Set up motor
motor = Motor(Port.A)

Next again! We know these lines too. Remember what they do?

while True:

    # Set motor power
    power = controller.joystick_left()[1]

    # Rotate motor
    motor.dc(power)

That's the whole thing! We set up a few variables. We run the motor in a loop. Not so scary.

It's fine if you're still a little confused. The important thing is that the code works. And next time you'll be able to whip up your code even faster!

Now take this masterpiece back to Stewskee. I'll just be sitting here refreshing until the dance vid drops.

Make it Pop

[Stewskee] There it is, THE sinkhole patrol bot. I mean, the chassis SLAPS. But the decorations are kind of... basic? No offense. Just, my viewers expect a certain aesthetic.

Find some scrap and take a sec to decorate this thing. Don't go overboard though. Just give it a vibe. In a few minutes this lighting will be trash.

Fire

WHAAAAT. I can barely recognize it. That's FIRE.

YOU READY?

  1. Blast your favorite beats.

  2. Turn on your bot and connect your controller.

  3. Drop that signature SPIN. Move the joystick up and down to step back and forth with the beat.

  4. Got a phone? Shoot it, or ask a buddy.

  5. If you've got permission, POST THIS THING. #BotBattles

Legend

NO WAY. This is LITERALLY THE CLEANEST bot choreo EVER.

I'm dropping this tonight. The numbers are gonna be CRAZY.

Get ready. Your phone's gonna blow up. This time tomorrow you'll be a legend. Everyone in Stardust Springs is gonna know your name.

1
2
3
4
5
6
7
8
9
10