# Sinkhole Patrol

<figure><img src="/files/qrG2DkUm4Z5eZwyTzCND" alt=""><figcaption></figcaption></figure>

### Rewards

* :trophy: **350 XP**

**\[Zoe Foxlin]** OOF. I'm so sorry. 😮‍💨 I wasn't looking where I was going. Gotta run, we've got a situat— oh, it's you! You have no idea how glad I am to see you, and - ugh, this RAIN! Look, just run with me and I'll explain.

Stardust Springs was a mining town back in the day. There are old mining tunnels everywhere under the industrial district. Nobody's supposed to worry about the tunnels. "Don't worry about the tunnels." Turns out we should've worried about the tunnels.

This storm has opened up a sinkhole right next to a scrap storage building. And it's growing. Like, faster than my laundry pile.

<figure><img src="/files/iZ9nPKHzr2dUDfrWFGI8" alt="" width="563"><figcaption></figcaption></figure>

Scrap is starting to wash into the sinkhole. Once it's down there, we can't recycle it. It'll be lost forever in the tunnels, polluting the ground for decades.

The good news: I've got a team of robot battlers coming in as fast as they can to break down the scrap before it washes away. The bad news: they can't get through this storm. They won't make it until tomorrow morning. By then it'll be too late.

We need a robot to buy us some time. A vehicle that can patrol around the edge of the sinkhole all night to prevent scrap from getting washed in. Like a guard dog for scrap.

You've been working on crafting a robot, haven't you? That may be our only hope. Bring it. I'll help you program it to patrol the sinkhole. Just make sure it has wheel motors, like the [Purrmenator](/tutorial/your-first-robot.md). And double check that the left motor is plugged into port A on your hub. Otherwise our program will crash.

<figure><img src="/files/XP2OMm0JkaTlHjGn2C3G" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="/files/cr4uiaxfgkU9CKKwdhC2" alt=""><figcaption><p>1</p></figcaption></figure>

## Bad at Coding

Oh wow, this sinkhole is even worse than I thought. We don't have much time to whip up our code.

Here's a secret. Come in close. I'M BAD AT CODING! Here's another secret. WHO CARES! It's never ever stopped me from programming my robots to do exactly what I want.

It's like... okay, you know how some people are good at making sandwiches? They can slap one together in 30 seconds. Other people have to spend 5 minutes looking up recipes and arranging all the ingredients. Well, both methods end up with a sandwich! One's not more "sandwich-y" than the other.

Coding is the same way. If you're good at it, you can do it fast. If you're bad at it, you might get stuck sometimes and have to search online for answers. That's fine! As long as you're creative, you'll always get there.

You don't have to be a chef to make a sandwich, and you don't have to be a "coder" to code a robot. I'm NOT a coder. I just use code sometimes to make my robots do awesome stuff. This is one of those times! We'll get it done together.

## Rotaaaaate Motor

Before you start cooking, you have to decide what you want for lunch. (I'M HUNGRY, OKAY?) And before you start coding, you have to decide what you want your robot to do.

I'm thinking if we just get one wheel motor to rotate, that'll make the robot drive in circles around the sinkhole. Let's do it. Rotate motor.

Start by bringing up a blank program in Pybricks. Visit [code.pybricks.com](https://code.pybricks.com/) using Chrome or Edge.

Pybricks uses a programming language called Python. :snake: And now\... to code!

Rotate motor. Rooootaaaaaate motor. Aaaand I'm stuck. No problem. That's what the internet is for.

I searched online for "pybricks rotate motor example" and found this code.

```python
# Set up controller
controller = XboxController()

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

# Set motor speed
speed = 20

while True:

    # Rotate motor
    motor.go(speed)
```

Does it work? Bro, I don't know! Let's load it up and see what happens.

1. Hover over this code and click the "Copy" button.
2. Paste it into Pybricks.
3. Load the program onto your hub. If you forgot how, see [Custom Controls](/coding/custom-controls.md).
4. Connect your controller to your hub. If you forgot this too, see [Controlling Your Bot](/tutorial/controls/controlling-your-bot.md).

<figure><img src="/files/cr4uiaxfgkU9CKKwdhC2" alt=""><figcaption><p>2</p></figcaption></figure>

Okay, the controller is connecting, and...

STOP THAT SPINNING ROBOT! Pounce on it before it falls into the sinkhole! Press the green button!

<figure><img src="/files/cr4uiaxfgkU9CKKwdhC2" alt=""><figcaption><p>3</p></figcaption></figure>

Close call there. We wanted a rotating motor, and we got a rotating motor. But I don't know if it's rotating with enough speed. We're making a scrap fighting machine, not a microwave.

## Comments

Let's take a look at the code and see what's going on. That way we can figure out what to change to make the motor rotate with more speed.

Here's the very first line.

```python
# Set up controller
```

This is a **comment**. A comment begins with a hashtag `#`.

Imagine you're baking a cake, and you have a recipe with steps to follow. Someone wrote a little note in the recipe: "Be careful not to spill the flour!" That note isn't part of the recipe. But it's very helpful, because it makes the recipe easier to follow.

Comments are just like that. They're useful for explaining what code does. They make your code easier to follow.

You can write anything in a comment. They're only for humans. The computer completely ignores comments when running the program. Just like I ignore Insta comments from my ex. (#sorrynotsorry)

Let's look through the other comments in this program. Maybe we can find a hint about increasing our motor's speed.

```python
# Set up controller
controller = XboxController()

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

# Set motor speed
speed = 20

while True:

    # Rotate motor
    motor.go(speed)
```

## Tinkering

Well this one looks promising.

```python
# Set motor speed
speed = 20
```

This comment helpfully explains what the next line does. Spoiler alert: it sets the motor's speed.

I bet we can make our motor rotate faster by increasing this number. Try changing it from `20` to `100`. Load the new code onto your hub and turn on your controller again. This time, maybe hold onto your robot first...

WOW. Now we're cooking. Press the green button to stop the program before we plow through a wall or something.

When I'm not sure what code does, sometimes I just tinker around. I'll change a number and see what happens, like we did here with the speed number. It's a great way to figure out how things work.

Speaking of tinkering... there's just one more problem. This robot is driving backwards! We need to make the motor rotate in the other direction. We can do this by adding a minus sign. Change the number from `100` to `-100`. Like this.

```python
# Set motor speed
speed = -100
```

The full code should look like this.

```python
# Set up controller
controller = XboxController()

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

# Set motor speed
speed = -100

while True:

    # Rotate motor
    motor.go(speed)
```

Now set your robot up on the edge of the sinkhole and try running that program.

<figure><img src="/files/cr4uiaxfgkU9CKKwdhC2" alt=""><figcaption><p>4</p></figcaption></figure>

## Scrap Scoop

YESSSS. SUCCESS!

If you want to make this robot an even better scrap defender, craft an arm for it that drags along the ground and pushes scrap away from the sinkhole. You can sprinkle some spare scrap around it to test if the arm works.

<figure><img src="/files/cr4uiaxfgkU9CKKwdhC2" alt=""><figcaption><p>5</p></figcaption></figure>

Once you're satisfied, fire that robot up and let it patrol! We'll check on it after the storm is over.

## Finale

IT WORKED! I can't believe it. Sinkhole patrol robot saves the day. And look, here come the other robot battlers to break down all the scrap!

Next time you need to make a motor turn, you'll have an example to copy from. You'll make that sandwich — I mean program — even faster. Stop by my garage any time if you ever need more coding help.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://play.robobattles.com/adventure/quests/sinkhole-patrol.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
