Hello and welcome to the second part of my lego scratch tutorial that you can use
for the lego mindstorms robot inventor set, for the lego spike prime set and for the lego mindstorms EV3
sets. Basically for all of the sets with this or a similar software. In the last part, we discovered the basic layout of the software and the programming environment.
In this part I will give you some general tips for coding and we will make our first tests. I've got the default models that I suggested you to build in the last part.
I will use the robot inventor hub and software for most of this tutorial
because I think that most of the viewers will use this software. But this tutorial can be done the same with either the lego education spike prime kit
or with the retail and the education version of the lego mindstorms EV3. You can use this tutorial for all of the sets but I will stick to this software for most of the parts because I think that it's
the most useful solution for most of my viewers. Now, we can write our program. I will make a quick test
with a simple movement block. I tell the robot to move forwards for 10cm. Now we can take a look.
I'll start the program. It drove forwards but I don't think that it drove complete 10cm.
The distance that it actually drives depends on the diameter of the wheels. It doesn't have to be
10cm in your case. It always depends on the actual model and that's a very important lesson.
Often, there is a big difference between theory and praxis. Maybe now you want to do something else.
Maybe you want the robot to make sounds or stuff like that. Then you have to get another start block
"When the program starts". Both of these blocks will be triggered when the program starts.
Both will be executed as soon as we start the program. Then we can make our "playlist of commands".
These programs usually are "playlists of commands". You have the start point and
then you can add one command after another. They will be executed one after another. We can put a "start animation" block below this one
and then it will start here
and then it'll do that. But we wanted to make a noise... or show something on the screen and you can do it this way. But I highly suggest you to avoid parallel tasks as long as possible. There are some cases where they make sense but
I think that for most of the beginner programs, it makes more sense to make one row of commands and not to use many start points.
There are some cases where you might get weird errors/behaviour with parallel things.
We will discuss that later but for now try to stick to one "program".
Often, you can turn on the LEDs. It will execute one command after another but this command takes a few ms to run
so you won't notice the delay of this command. You'll have the impression that both of these commands
will be executed at the same time while in reality, they are executed one after another but it's
with a very short delay so that you won't notice it. Generally, you should test your programs very often because we can put many blocks
after the first ones. But then I might loose the overview. I can try it and it may not work and now I don't see why it doesn't work.
I don't see the point where it stopps to work. That's the reason why you should try to change 2 or 3 blocks max,
see how it reacts and try to understand why it reacted how it did if it didn't do what you wanted it to do. Normally, you made some thinking mistake - and that's completely normal because you have to learn to think like a
robot or a computer does and that's not easy. You might make some mistakes and that's normal but you should try
to find out where the problem was and why it existed in order to understand it and to avoid it in the future.
It's also important that you come up with your own tasks/ challenges. This tutorial series will only cover a few specific programs. Maybe you want to build your own model and then you want to program it
and it should do something that wasn't covered in this series. It's important that you try to come up with your own programs
to get a certain amount of creativity when it comes to programming. Only then you'll be able to code independently.
These are too many blocks to add at once. There is yet another thing I want to tell you.
Often, there are assumptions made. I mean the following by that. I told the robot to move but I didn't tell it which motors it should use. It can have up to 4 motors that are exactly the same so it might not know which motors it should move.
It might make the right assumption because in my case the motors are on matching ports A and B but you might use all 4 motors for this set or 2 other motors with another set.
Then it might not know which of the 4 motors you want to use to drive.
For that reason it's important to tell the robot the right port, the right plug that you plugged the motors into
for the task that you want to do. In this case, the motors for driving are on ports A and B.
I can use these setmovementmotors blocks to A and B to tell the robot that I want to use the motors on these ports to drive. That's a pretty simple thing to do.
You should try to remember to do it because it might avoid problems later down the line.
But make sure that these ports are correct. The motors that you want to use for driving should be on these ports. That was it for this part, thanks for watching.
In the next parts we will cover more interesting programs that move the robot for longer time periods. Thanks for watching this part, see you in the next part and bye.