Let's Move
<h4><b>Lesson Objectives</b></h4>
<p><i>By the end of this lesson, students will be able to:</i></p>
<ul>
<li>
<p>Drive the mBot2 with precision.</p>
</li>
</ul>
<p> </p>
<h4><b>Overview</b></h4>
<p>Robots are autonomous machines that replace human effort; they can perceive their environment and perform computer programs to make decisions and take actions. A computer program is a set of instructions and conditions run by a computer to perform a task. You may think you have never seen or used a robot, but that chance is slim. Robots can take many different shapes and have different capabilities depending on their context. For example, robots are present in households, such as the vacuum cleaner robot or a lawn mowing robot; you can also find them in factories assembling products. We have even sent robots to other planets.</p>
<p> </p>
<h4><b>Focus</b></h4>
<p><i>By the end of the lesson, students will know:</i></p>
<ul>
<li>What movements can mBot2 do</li>
<li>What different programming blocks you can use to make the mBot2 move</li>
</ul>
<p> </p>
<p> </p>
<h4><b>Pre-lesson Checklist</b></h4>
<h4><b>What do you need?</b></h4>
<ul>
<li>PC or laptop (with USB output) with the mBlock software installed, the web version (also for ChromeBook), or a tablet with the mBlock app installed</li>
<li>The mBot2 with a CyberPi</li>
<li>A USB-C cable or Makeblock Bluetooth dongle</li>
<li>A3 paper</li>
<li>Pens</li>
</ul>
<p> </p>
<p> </p>
<h4><u><b>Activities</b></u></h4>
<h4> </h4>
<h4><b>Step 1: Warming up </b></h4>
<p>This step consists of two parts:</p>
<ul>
<li>Robots in everyday life</li>
<li>Getting to know the mBot2</li>
</ul>
<p> </p>
<p><b>1. Robots in everyday life</b></p>
<p>We have robots in many different places. Some people have them in their homes and others work with them every day. Robots can take many different shapes and have different capabilities depending on their context. Can you think of three robots that you have to deal with (regularly) in everyday life?</p>
<p> </p>
<p><img src="/api/storage/uploads/legacy-images/wyh1xjhharbyq6aplutnr9fd8v6u/2.jpg" style="width: 550px; height: 367px;" /></p>
<p> </p>
<p>There are probably many more robots that have been developed that you have never seen. Search the Internet for three more robots that you can use in everyday life.</p>
<p> </p>
<p>There is a good chance that you will have to deal with robots later on you professional or personal life. There are robots working in many different companies. Usually, these robots perform tasks that are repetitive, that need to be done with great accuracy, or that are dangerous. In this lesson we will be working mainly on programming a robot to move accurately. Can you think of three professions or businesses where it is very important for a robot to work very accurately?</p>
<p> </p>
<p> </p>
<p><b>2. Getting to know the mBot2</b></p>
<p>The mBot2 is a programmable robot equipped with different components that allow it to sense, act and communicate with its environment. The mBot2 is intended for students to learn about Computer Science and Technology, including ways that you can use a robot in real life.</p>
<p>The mBot2 can be programmed with the help of mBlock. In mBlock, programming can be as easy as dragging and assembling blocks. As you will see in this lesson, you can, for instance, program the mBot2 to drive through a maze - with your help (not autonomously). mBot2 comes with a pair of special motors, which can record the rotation of the axle and therefore the speed and distance the robot has travelled. They are called encoder motors due to the sensor that is built-in (encoder). This type of motors allows to control specific parameters such as the rotation angle and speed of the motors. You will learn how to make use of these motors in the following steps.</p>
<p> </p>
<p><img src="/api/storage/uploads/legacy-images/hjq38dgy6mqaq05q2a0ueiblw5fj/1%2C+3.jpg" style="width: 550px; height: 407px;" /></p>
<p> </p>
<h4><b>Step 2: Hands-on </b></h4>
<p>This step consists of two parts:</p>
<ul>
<li>
<p>Getting acquainted with the different programming blocks of the mBot2.</p>
</li>
<li>Recreating and testing some programming examples to control the mBot2.</li>
</ul>
<p> </p>
<p><b>1. Getting acquainted with the different programming blocks of the mBot2</b></p>
<p>As you observed previously, robots can be used in many different ways. If you have thought of a purpose for a robot, most likely it means that you know what the robot needs to do to help you, and some of these tasks might need to be executed with certain precision.</p>
<p>When you start programming the mBot2, you will notice that there are many different coding blocks you can use to make the robot move. You will find these blocks in mBlock 5 in the category 'Chassis'. These coding blocks are blue.</p>
<p> </p>
<p>Below you can see some examples of the coding blocks needed to make the robot move. Some of them look similar, yet they all do something different. For this lesson, we will work in Live mode. Make sure the correct mode is selected in the software. The differences between Live mode and Upload mode will be explained in lesson 2.</p>
<p> </p>
<table cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td valign="middle">
<p><u><b>Code block:</b></u></p>
<p> </p>
<p><img src="/api/storage/uploads/legacy-images/v4vg1kreddu67r8mykxfcyd9s8av/5%2C+18b.png" style="width: 503px; height: 76px;" /></p>
<p> </p>
<p>This code block allows you to move the mBot2 forward, backward, left and right at a specific rotational speed of the wheels and for a number of seconds.</p>
<p>The example below shows how you can make the mBot2 move for two seconds at a speed of 50 rotations per minute. This is useful, for example, when the mBot2 needs to push a load forward.</p>
<p> </p>
<p><img src="/api/storage/uploads/legacy-images/b8jrpx4dmxq8sigaat62wg1ep7rn/6.png" style="width: 503px; height: 141px;" /></p>
<p> </p>
<p> </p>
<p> </p>
</td>
</tr>
<tr>
<td valign="middle">
<p><u><b>Code block:</b></u></p>
<p> </p>
<p><img src="/api/storage/uploads/legacy-images/vjd1lau3viadjraf9is1qywb5fl5/7.png" style="width: 321px; height: 76px;" /></p>
<p> </p>
<p> </p>
<p>This code block allows you to make your robot stop moving. This can be a useful block during a testing phase. If a program does not work as expected you can use this block to make the robot stop immediately.</p>
<p>For example, you can make the robot stop when the A button of the CyberPi is pressed. To do this, use the programming example below.</p>
<p> </p>
<p> </p>
<p><img src="/api/storage/uploads/legacy-images/gugqahvsapsitm2q2y4ilz7fbvtb/8.png" style="width: 327px; height: 141px;" /></p>
<p> </p>
<p> </p>
<p> </p>
</td>
</tr>
<tr>
<td valign="middle">
<p><u><b>Code block:</b></u></p>
<p> </p>
<p><img src="/api/storage/uploads/legacy-images/vw0qcmy0bda9u0f637eqn8cw17ei/9%2C+18c.png" style="width: 361px; height: 76px;" /></p>
<p> </p>
<p>With this code block you can make the mBot2 rotate by a number of degrees, and you can choose whether the rotation should be to the left or to the right.</p>
<p>When the programming example below is set, the mBot2 can be controlled by using the arrow keys. When pressing the right arrow, the mBot2 will turn 90 degrees to the right, when pressing the left arrow, it will turn 90 degrees to the left.</p>
<p> </p>
<p><img src="/api/storage/uploads/legacy-images/smspvtjpwt4kzqrr53qusx81flig/10.png" style="width: 361px; height: 141px;" /></p>
<p><img src="/api/storage/uploads/legacy-images/6lhveb4v5hg3fe7g2rs8kae9qqp6/11.png" style="width: 375px; height: 141px;" /></p>
<p> </p>
<p> </p>
</td>
</tr>
<tr>
<td valign="middle">
<p><u><b>Code block:</b></u></p>
<p><img src="/api/storage/uploads/legacy-images/dx58nem9f8n7we8yinx6kawidz1w/12%2C+18e.png" style="width: 489px; height: 76px;" /></p>
<p> </p>
<p> </p>
<p>With this code block you can make the mBot2 move forward or backward a certain distance.</p>
<p>When you use the programming example below, the mBot2 will move 100 cm forward. To start this, move the joystick of the CyberPi upwards.</p>
<p> </p>
<p><img src="/api/storage/uploads/legacy-images/fmhnxhghndx219fwszy9csk3dftw/13.png" style="width: 489px; height: 141px;" /></p>
<p> </p>
<p> </p>
</td>
</tr>
<tr>
<td valign="middle">
<p><u><b>Code block: </b></u></p>
<p><img src="/api/storage/uploads/legacy-images/pu7iao2wg3azrfruy6tr7bfv87dg/14.png" style="width: 800px; height: 67px;" /></p>
<p> </p>
<p> </p>
<p>You can also control the motors of the mBot2 independently, and this is one of the blocks which you can use for that.</p>
<p>In the example below, the mBot2 will move in a curve for 3 seconds before it stops. Notice that the value for one of the motors is negative; this is because the motors are mounted in opposite directions, so in order to move the robot in one direction, you need to make one of the motors rotate the opposite way. What would happen if both wheels rotate at 40 RPM?</p>
<p> </p>
<p><img src="/api/storage/uploads/legacy-images/u66b711vghkpmluir2x89d7v1akv/15.png" style="width: 800px; height: 208px;" /></p>
<p> </p>
<p> </p>
<p> </p>
</td>
</tr>
<tr>
<td valign="middle">
<p><u><b>Code block:</b></u></p>
<p> </p>
<p><img src="/api/storage/uploads/legacy-images/og2okx2a4xynzv9tufyt1kk7cb04/16.png" style="width: 522px; height: 60px;" /></p>
<p> </p>
<p> </p>
<p>Because the motors of mBot2 can measure their speed and rotation, you can also read these values. The speed measured is the rotational speed in Rounds per Minute (360° = 1 round; in science, it is more common to use “degree per second” (1 RPM = 6° per second)). In mBlock 5, if you tick the box next to this block, you can read the values on the stage above the panda. The programming example below changes the values of the rotation back to zero, and then orders the mBot2 to move forward for one second. What value do you read on the stage after the robot moved?</p>
<p> </p>
<p><img src="/api/storage/uploads/legacy-images/g7fitcernphpn97dwzu1b5v0s9jw/17.png" style="width: 503px; height: 189px;" /></p>
<p> </p>
<p> </p>
<p> </p>
</td>
</tr>
</tbody>
</table>
<p><b>2. Recreating and testing some programming examples to control the mBot2.</b></p>
<p>Below you can see some pairs of blocks. Try out each pair side by side. What happens? What are the differences between the code blocks?</p>
<p> </p>
<table cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td valign="middle">
<p> </p>
</td>
<td valign="middle">
<p><u><b>Option 1</b></u></p>
</td>
<td valign="middle">
<p><u><b>Option 2</b></u></p>
</td>
</tr>
<tr>
<td valign="middle">
<p>1</p>
</td>
<td valign="middle">
<p><img src="/api/storage/uploads/legacy-images/mhmc5nhxb28n69sv7i84mnuvwdci/18a.png" style="width: 379px; height: 76px;" /></p>
<p> </p>
</td>
<td valign="middle">
<p><img src="/api/storage/uploads/legacy-images/e5mlclrgprbae9htbix8fw7dmogz/5%2C+18b.png" style="width: 503px; height: 76px;" /></p>
</td>
</tr>
<tr>
<td valign="middle">
<p>2</p>
</td>
<td valign="middle">
<p> </p>
<p><img src="/api/storage/uploads/legacy-images/mix8cj2sx1h9ec7yoxqqusrwobov/9%2C+18c.png" style="width: 361px; height: 76px;" /></p>
</td>
<td valign="middle">
<p><img src="/api/storage/uploads/legacy-images/9if1dq63zggnlrxe6j3fmqn59tiq/18d.png" style="width: 449px; height: 76px;" /></p>
</td>
</tr>
<tr>
<td valign="middle">
<p>3</p>
</td>
<td valign="middle">
<p><img src="/api/storage/uploads/legacy-images/7adoveyiruhqi2uzeuqnibzjdfo9/12%2C+18e.png" style="width: 489px; height: 76px;" /></p>
<p> </p>
</td>
<td valign="middle">
<p><img src="/api/storage/uploads/legacy-images/9zqcn7dht6frlez3re7w87akrwfu/18f.png" style="width: 800px; height: 62px;" /></p>
</td>
</tr>
</tbody>
</table>
<p> </p>
<p> </p>
<h4><b>Step 3: Trying it out</b></h4>
<p>It is now time to put your mBot2 to work. Take an A3 paper and draw a maze that your mBot2 has to drive through. Don't make it too complicated and take into account the width of the robot. The mBot2 doesn't have to find the right route by itself. The mBot2 just needs to drive the route that you program. Need inspiration? Below you can see an example.</p>
<p> </p>
<p><img src="/api/storage/uploads/legacy-images/upshg4i0wzwtf40ix3dhns9gaeuk/Untitled.jpg" style="width: 550px; height: 376px;" /></p>
<p> </p>
<p>Use the knowledge you gained in 'Step 2' of this lesson. Of course, you can do plenty of experimenting yourself with the different programming examples in mBlock5.</p>
<p> </p>
<p>When doing this assignment, it is helpful to use the following step-by-step plan.</p>
<p> </p>
<table cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td valign="middle">
<p><strong>Step 1</strong>: What do you want to do?</p>
<ul>
<li>What route do you want the mBot2 to drive?</li>
<li>What parts does the maze consist of?</li>
<li>How long are the distances the robot needs to travel?</li>
<li>Does the robot also need to make turns? Which way and by how many degrees?</li>
</ul>
</td>
<td valign="middle"> </td>
</tr>
<tr>
<td valign="middle">
<p> </p>
<p><strong>Step 2</strong>: What do you need?</p>
<ul>
<li>What do you need in addition to the mBot2?</li>
</ul>
</td>
<td valign="middle"> </td>
</tr>
<tr>
<td valign="middle">
<p> </p>
<p><strong>Step 3</strong>: What code blocks do you need to make the mBot2 drive?</p>
<ul>
<li>How are you going to make the mBot2 drive?</li>
<li>What code blocks will you use?</li>
<li>Make a brief description on how your program works (pseudocode/natural language, flowchart or UML)</li>
<li>If you need further explanation, you can discuss with your fellow students, the teacher, or do a research on the topic. There is help available for every code block in mBlock as well.</li>
</ul>
</td>
<td valign="middle"> </td>
</tr>
<tr>
<td valign="middle">
<p> </p>
<p><strong>Step 4</strong>: Testing and implementation</p>
<ul>
<li>Is the first version ready? Test it! During the testing round, write down areas of improvement.</li>
<li>Work on the improvement points until your mBot2 drives through your maze without errors.</li>
</ul>
</td>
<td valign="middle">
<p> </p>
</td>
</tr>
</tbody>
</table>
<p> </p>
<p>Is it possible to get the mBot2 to drive through the maze without a hitch? Then challenge yourself with a more difficult maze. Or have one of your classmates work out a route for you.</p>
<p> </p>
<p> </p>
<h4><b>Step 4: Wrap-up </b></h4>
<p>Did you succeed in driving the robot through the maze completely without error?</p>
<p>In this lesson you have been introduced to robots in everyday life and to the mBot2. You know how to control the movements of mBot2 and which programming blocks you can use for this.</p>
<p> </p>
<p>It is now time for a short reflection. Think on your own and discuss with the group:</p>
<p> </p>
<ul>
<li>What do you think turned out well?</li>
<li>What could be better?</li>
<li>Which parts of the lesson did you find easy and which did you find more difficult?</li>
<li>What would you like more explanation about?</li>
<li>Who could help you with that?</li>
</ul>
