We are ready to build the first program for moving the robot forward and backward. We learn how to build simple programs for moving the program. But it is not that easy...downloading to the robot does not always result in the robot moving.
- 01 Mar 2017
Reorder the view in the software
We clear the screen from unnecessary things to make the code editor more visible.
Set power to the motor
We can use the code:
motor[port2] = 50
motor[port3] = 50
to set the power of our motors.
Nothing happens when starting
After the program is executed it ends and that's why we will not see anything if we just set the power to motors. We should wait for a couple of seconds to give the robot a chance to move before the program is terminated.
Finally we are ready to build our first program for moving the robot. And we're going to move it forward and backward. Why? Because these are some of the most basic things that you'll do with this robot. And the purpose is just to learn how to move the robot and how to build simple programs for moving the robot.
I'll start with the first program but first let's just remove some of the unnecessary things from our window. First is this compiler errors view. And I just remove them. Then this text function view. We don't need it currently. And I just remove it. And then I press Ctrl+ to make the text larger so that you can see it on the screen. And this here is the main function. We've talked about the main function. This is the main task of our robot. This is the main and only task that will be executed by the micro controller. And in this task we can control our motors. The way you control the motors is the following. We have a variable motor. And we set motor 2 to have a power of 50. And we set motor on port 3 to have a power of again 50. Now the power of the motors is between -127 and 127. So, the maximum power is 127, I think. And 50 is kind of like the medium. And this is the program. Now, if we just upload this program to our robot it will run and we'll have the robot moving forward. For how long? Well, actually that's interesting. Let's see for how long.
We have the robot on the camera and now I just compile the program and download to the robot. And when I download it to the robot and press 'start' you remember that we set motor on port 2 to have a power of 50 and the motor on port 3 to have a power of 50. And I just click on 'start'.
And nothing happens. And then again - 'start'. The program is successfully downloaded to the robot but the robot does nothing. Why? Because in the main task we just set two values and the whole task is completed. So, the robot executes the program very fast. We just set the power of the motors and then the program is ended. And that's why we don't see anything from the robot. It doesn't move, it doesn't change the position because we just set two variables. What we should do is to tell the robot after we set the variables to wait so that it can move.
Courses and lessons with this Tutorial
This Tutorial is used in the following courses and lessons