We start with the previous program where we made the robot move forward and turn. We continue in this tutorial with repeating the same RobotC instructions four times. Our goal is to make the robot move in a square.
- 12 Apr 2017
Copy/paste the instructions
The simplest and most obvious solution is to just copy and paste the code 4 times. This would make the robot move and turn four times. This is of course not the best solution. And it is not even right. What you have to remember is that every time you do a copy paste in a software program you are introducing a bug. If you ever wonder why are there so many bugs in software products that is because naive software developers like to copy and paste stuff. Which is wrong.
In the previous video we finished with implementing moving forward and turning. The robot was working like this. Move and turn. Our goal is to build a square and what we'll do now is just repeat this move forward and turn 4 times. Let's do this in the software.
Implementing a square when you have the code for move forward and for turning right is very simple. We can just copy this code. Now, it's not very intelligent to copy it and we'll find other ways in the next video but for now let's just copy this and paste it. And now we have move and turn 4 times. Let's number them. Move forward 1, turn right 1. Then 2. Then 3. And then 4. This will be a little difficult to see it on the camera but we'll find a way. Let's see how this program behaves when downloaded to the controller.
Курсове и занятия включващи този Урок
Този Урок е използван в следните курсове и занятия.