Как да намерим настройката за завой на 90 градуса с двоично търсене Pro Preview

Как да потърсим и намерим неизвестна стойност с възможно най-малко опити.

  • #423
  • 27 Apr 2017
  • 6:27

Проблемът

Често ще се наложи да налучквате стойността за ротации на двигателите, за да постигнете желано крайно положение на робота. 
Процесът на търсене с налучкване би отнел твърде много опити и много време, ако не е структуриран правилно.

Подходът - на кратко

Когато търсите между две стойности, направете експеримент със средната стойност между двете. Ако тестът не ви върши работа, опитайте отново между две други стойности, базирано на последния тест.

Алгоритъмът

Първа стъпка - намерете стойност, която е по-ниска от желания резултат, и стойност, която е по-висока от желания резултат.

Втора стъпка - направете опит със средната стойност между ниската и високата. За да намерите средната стойност, съберете ниската и високата стойност и разделете на две.

Трета стъпка - Ако резултатът от опита е по-нисък от очакваното, променете старата ниска стойност и повтортете втора стъпка.
Ако резултатът от опита е по-висок от търсеното, променете старата висока стойност и повторете втора стъпка.

Пример

Намерете стойността за завой на 90 градуса с един двигател за робот.

Опит 1 (първа стъпка от алгоритъма)
Измерваме, че 360 градуса са твърде малко и 720 градуса са твърде много.

Опит 2 (втора стъпка от алгоритъма)
Средата на областта от 360 до 720 е (360+720) / 2 = 540.
Правим опит и установяваме, че 540 градуса е твърде много.

Опит 3 (трета стъпка от алгоритъма)
Заменяме 720 (старата висока стойност) на 540 градуса.

Опит 4 (повтаряме втора стъпка от алгоритъма с нови стойности)
Средата на областта от 360 до 540 е (360+540) / 2 = 450.
Правим опит и виждаме, че 450 е твърде ниско.

Опит 5 (повтаряме трета стъпка от алгоритъма )
Заменяме 360 (старото ниско) на 450 градуса.

Опит 6 (повтаряме втора стъпка от алгоритъма с нови стойности)
Средата на областта от 450 до 540 е (450+540) / 2 = 495.
Правим опит и установяваме, че 495 е точната стойност!

Сравнение

Описаното по-горе изглежда дълго и трудно.

Но, ако бяхме опитвали на всеки 10 градуса, трябваше да опитаме с 540, 530, 520, 510, 500 и 490 градуса, за да намерим стойността, която ни е нужна.

При директния подход, където изпробваме на всеки десет градуса от 540 градуса надолу, би отнело 6 опита, докато с помощта на двоично търсене, областта от 360 до 720 градуса отнема само три опита за да се намери нужната стойност!

English

Turning with the wheel to 90 degrees does not result in turning the whole robot to 90 degrees. It's just the wheel. Again I'll set the wheel like this. The wheel turns to 90 degrees but not the whole robot. What we should do in this video is find the value for this construction for this wheel, for this robot of how much should we rotate the wheel so that the whole robot rotates to 90 degrees. In the software, I have the computer right beside me we have a program for turning this wheel to 360 degrees and I'll just start the program. 360 degrees with this wheel is not enough for turning the robot to the right - it's slightly to the right but not exactly to the right. What we can do is to experiment and to find the correct value. How do we find this value? There are many different ways. We can just try with 370 degrees or 380 degrees but that's kind of a slow process. What we can do is until we have the experience and you'll know most of the values by heart by the end of this course but for now what we can do is just double this value and set the value to 720 degrees. Like this.

So, 720 degrees is too much. We rotate the robot but not exactly to the right. It's to the right and then it continues forward. But what you can see is that 360 results in the robot positioned like this, 720 results in the robot positioned like this. So, it's somewhere in the middle and we can take the exact middle between 360 and 720. And the exact middle is 540. And if we set this to 540 degrees,

we see that it kind of looks like exactly to the right. Again.

But it's probably more. Exactly to the right would be like this. This process of finding the correct value is called Binary search. And it's very famous algorithm for seraching different values when we don't know them. And it's basically for searching in an array but these are details. With just 2 tries we find a value that's very close to the real one. How do we find if 540 degrees is the real one? What we should do is to make this robot turn to 540 degrees 4 times. And if it just rotates, then we know that the value of 540 is correct. How do we do this in the program?

We have our block - 540 and we must execute this block 4 times. Or even 10 times but 10 is too much. Let's start with 4. What we can do is we can take another block - Large block place it here then we can configure it for a number of degrees - for 540. But as you see this is kind of a slow process. What we can do is to copy. We can select this block, click edit > copy and then click edit > paste. And we have the same block here with the exact same configurations. But we can also do another trick. We can hold CTRL and move.

And this makes another copy of the same block and now we have 4 different blocks. And I'll just download and run these 4 different blocks.

The robot does 4 turns to 540 degrees. If each of these is exactly right then at the end it should arrive at the same position that it started. Because it will do a full circle. But as you saw 540 is a little too much.

At the end the robot is not facing exactly you on the camera and we use the marker, it moves slightly after the marker. So, the correct value is somewhere slightly less than 540 degrees. And we'll leave this to you. Try to find the correct value for making the whole robot turn to exactly 90 degrees and when you do 4 turns it should return to the same position.

Курсове и занятия включващи този Урок

Този Урок е използван в следните курсове и занятия.

Image for EV3 Phi. Introduction to robotics with LEGO Mindstorms
  • 92
  • 220:20
  • 36
Image for Turning with a LEGO Mindstorms Robot
  • 14
  • 0
  • 4
  • 3d_rotation 0
Image for Instructors Remote Training
  • 136
  • 280:11
  • 156
Image for How to make the robot move
  • 24
  • 0
  • 11
  • 3d_rotation 0
Image for Ниво В - "Шпионски Игри" - Роботика с LEGO
  • 30
  • 7:30
  • 108
Image for Роботика с LEGO - Ниво 1.0 - Приключение в Космоса
  • 126
  • 123:52
  • 150
Image for Занятие 3 - Разчистване на площадка за кацане
  • 9
  • 4
  • 2
  • 3d_rotation 0
Image for Роботика с LEGO - Ниво 1.5 - Шпионски игри
  • 56
  • 12:47
  • 135
Image for Ниво A - Въведение - Роботика с LEGO
  • 142
  • 133:42
  • 187
Image for Занятие 5 - Разчистване на площадка за кацане
  • 11
  • 3
  • 5
  • 3d_rotation 0