SamuZai
Pybricks
Pybricks

patreon


Preview & request for comments: Beginner's guide to robotics and coding

Besides new features, we are often asked about tutorials and user guides. And this is of course equally important! To make it easier to get started, I've started on a brand new beginner's guide to learning coding and robotics.

Instead of being a technical reference, this guide is intended more like a book that you can read from cover to cover, or starting halfway to match your existing skills. We'll use Pybricks of course, but the guide aims to go much farther, so that it can be an introduction to robotics and coding more generally.

I would be very curious for your suggestions and ideas on topics to cover.

As a starting point, I've included a draft outline below. The video above is a preview of chapter 1, which is almost complete. Everything else is yet to be written, so it can still be completely adapted based on your suggestions. Each chapter will also include challenges to practice your skills and go beyond what you've learned.

1. Getting started

This chapter is all about preparing the tools you need to get started. What is a hub, motor, or sensor? You’ll also prepare your computer or tablet and install Pybricks on your LEGO hub.

You’ll learn how you create, save, and run programs. Without diving into the details of each block just yet, you’ll learn how to use the coding interface effectively, which is a big help once you create bigger programs later on.

2. Building a robot

A great way to learn robotics and coding principles is to build a basic vehicle robot. It’s a fun way to dive into the action right away, while getting to know all the elements and coding techniques one by one.

We’ll show you how to build such a vehicle. You can use either SPIKE Prime, SPIKE Essential, Mindstorms Robot Inventor, Technic, City, or BOOST. Once you’ve attached some wheels to the motors, it turns out they’re all pretty much the same.

You can also use your own robot if you prefer, by adapting the provided coding examples to your own design. For example, you might have to adjust the wheel diameter parameter if you use differently sized wheels.

3. Basic robot navigation and output blocks

Now it’s time to make the robot come alive! You’ll learn to use the output blocks to make your robot move, play sounds, and blink lights. Naturally, you’ll make a “Hello, World!” program too!

4. Waiting, repeating, and tasks

Robots rarely execute a long, fixed list of actions from start to finish. This chapter shows you how to wait between actions, or repeat several actions multiple times. You’ll also see how you can run multiple actions in parallel, or how to group frequently used actions together in a dedicated task.

5. Making decisions with sensors

Robots don’t operate in the world all by themselves, so they need to observe their surroundings to decide what to do. This chapter shows you how to use sensors to make decisions. You’ll use the distance sensor to get started, and make your robot drive around while avoiding obstacles.

6. Using logic to make combined decisions

A single sensor is quite easy to use, but most robots use several sensors at the same time. How do you combine all the sensor information to do something useful? And how do you avoid missing important information? You’ll find out in this chapter. You’ll use the buttons on the hub as additional sensors, so that it can not only detect objects, but also where they are encountered.

7. The color sensor

This chapter shows you how to measure light intensity and color. Your robot can use these measurements in many ways. For example, you’ll learn how to make your robot find the brightest spot in a room, and how to make it follow a line on the floor. You’ll also learn to calibrate the color sensor to make it work reliably by adapting to your environment.

8. Using motors effectively

Rotating a motor might seem like a trivial task, but there are many factors that influence how it moves. This chapter dives deeper into the motor blocks and its various configurable settings. You’ll learn how to adjust motor speed, acceleration and control how the motor stops. You’ll also learn why some of these techniques are useful in different scenarios.

9. Navigation with the gyro sensor

In addition to using the position sensors in the motors, you can use the gyroscopic sensor in the hub to navigate more effectively. This chapter shows you how this works. You’ll also learn about practical aspects of using the gyro sensor, such as calibration or combining it with other navigation tasks. We’ll also discuss the pitfalls to watch out for when using the gyro in a robot competition.

10. Creating and using variables

So far, you’ve made your robot respond to its environment right away by adjusting what it does based on the sensor values at that moment. In some applications, you’ll want to remember certain values so you can use them later on in your program. You’ll learn to do that using so called variables.

11. Creating and using tasks and functions

In earlier chapters, you’ve briefly explored the use of tasks to group portions of code that could be reused repeatedly. This chapter dives deeper into the use of such tasks, also known as functions. Not only will they execute things for you, but functions can also calculate things for you and give you the result to use as an input for another block.

12. Using lists and iterations

A variable can store a single value, but it can also store a list of multiple values. For example, you might have a list of target angles that the motor should go to, one by one. This chapter shows you how to create, and modify such lists. You’ll also learn how to iterate through the list. This lets you execute some actions for each value in the list.

13. Wireless communication

At this point, you’ve mastered nearly all of the blocks on the block palette, but the fun doesn’t end there. In this chapter we’ll show you how you can send values between two or more LEGO robots. This lets you build a bigger robot, or make multiple robots work together.

Comments

Hi, I’m a new user of Pybricks block. I’m trying to create a color sorting project using Pybricks. Is there any tutorial on how to do color sorting?

Siti Mariam Sahar

Thank you for upgrading your membership! I think this will be focused quite a bit on competitions like FLL, covering many of the required techniques. It will start off with blocks, but maybe we can explore Python from there.

Laurens Valk

Have you thought about a variant focused on first Lego league? I would be interested in helping. Is the book focusing on Python, blocks or both?

Herodotus

As soon as the files for the localization are ready, I volunteer for the Italian translation of the blocks and this guide.

Daniele Benedettelli

Omg yes! All the things! This type of guide will be great to get started!

Chris


More Creators