Program for detecting the maximum speed for Energy Accumulation and Conservation Part 7 Pro Preview

One of the interesting things in this sequence of videos is the program. The program detects when the system has reached the maximum speed and then stops the motor from rotating. We detect this with the EV3-G software

  • # 121
  • 19 Jun 2016
  • 13:59

In the video we look at how to get some feedback from the motor and make decisions based on this feedback.

English

While working with this construction we built very nice program that gave us the speed of rotation of the motor in radii per second. It also did something very interesting. When the whole construction reaches it's maximum speed. It show us how much time do we need from the initial moment, when we start the system until we rotate the wheels to their max speed. So it stops. That's interesting program and because many of you have asked for more programming on the site, we decided to show you how we can program this brick to detect exactly when the system reaches it maximum speed.

Let's first see the end result so you know the program.

It starts rotating and you can see 2 values.

The lower is the speed of rotating and the upper is the time. The upper value stops at 14,47 and that's actually how much time we need to rotate the whole system, from 0 to maximum speed of rotation. As you saw we detect this with the motor. How do we do this? Let's go and program this. The goal is for you to learn how to get some feedback from the motor and how to detect when the whole system, the wheels in the system are rotating at their maximum speed. So we'll first start the motor, pretty straight forward.

Then we enter into a loop and this loop will display the values on the screen. First, we need to show the speed of rotation. We take one sensor, that's a rotation sensor for motor A, we reset it, at the beginning of the loop, then we wait for about a second, because we'll detect the degree of rotation each second. After 1 second we make another measurement, we actually make the measurements. We measure the number of degrees, so that's the number of degrees, and we display this value on the screen. How do we display this value. We take display block and we choose that we want to display text, this text will be wired and we just add drag from the sensor to the block for displaying. And this program will display the speed of rotation each second. Let's try this program. And as you can see, the speed of rotation in degrees per second. It's about 670 degrees per second. Let's stop there. The next thing that we want to do is to display the time, the time that is from the start of the program till now. So we have a timer block, right here and we can put this timer at the beginning and we reset, so in the initial moment the time is 0. We reset the time, then we take another timer block and add this timer block just after the display block.

And it will measure the time from the start till now. And we display this value on the screen again. So it's the same block, just choose: text, pixel, wired and we add the time to the screen. As you can see, we are displaying both values on the screen, add certain coordinates and both text will be displayed on the same place. This will be x=0 and y=0, and this is the same. So we need to move the time or the speed lower. So I'll increase the y value. This will show the first value - the time and the second - the speed. Let's check this program now. Again, we start the brick and we watch the screen.

Now as you can see. We again only see only one of the values and another one is flashing. Now that's an error that's quite common. Let's see how we can solve this.

The problem is in this 2 display blocks. So the first block displays the speed of rotation in degrees per second and the second one the time. When the second one draws the time on the screen, because it is actually drawing pixel by pixel, it is clearing the screen. And now we must choose clear, false. In this way what was first drawn on the screen, from the first block, we'll stay on the screen and then we'll see the other value of the second block. Let's try this program. Now you can see both values displayed on the screen.

Upper is the time and the lower value is the speed of rotation in degrees per second.

And finally our final program is to detect when the whole system has reached its maximum speed of rotation and stop at this moment, just detect how much time do we need from the start, till the maximum speed. Let's do this in the program.

Let's now detect the moment when the system reaches its maximum speed of rotation. And we can do this in the following way. We have the sensor and this sensor detects the speed of rotation, every second. Because it works in the following way.

We reset the motor, we wait for a second, we measure, we detect the number of degrees, that the motor has rotated. This means that for one second we rotated a number of degrees and that's the speed of rotation, degrees per second is the angular velocity. And we do this each second in order to stop to detect when we reached the maximum we must somehow do the following. We must take the value of the speed a second ago and compare it with the current speed and if it's less than the speed a second ago, this means that we've reached the maximum speed. If the speed that we are currently detecting is less than the speed a second ago, this means that we are at the maximum speed. How do we do this? We must somehow store the speed that was a second ago and we'll use a variable. These here in the red section are variables.

Let's do the following, we add a variable and I'll call it S.

So that's the variable, initially it has a value of 0.

Then we'll rotate and after we did for a second, we store this value in this variable. In this variable, this is our current speed of rotation.

We start with 0, then we do something else with the motors, we start the motors, we reset the timer and this is our first time entering the loop. So this is the first time we reset, we wait for a second, we detect a 100 degrees and then the value of this will be stored in this variable, and they are stored there. And then what happens is on the next loop we'll again reset, wait for a second, detect, this time we might detect 200 degrees and we store them in this variable. And it will have the value of 200. So on the third loop we reset, we wait and now if we find a way to compare, what was the previous value with the current, we'll know exactly if the current value is less than the previous. and as you can see the previous value is actually as the previous speed of rotation was stored a second ago in S. Let's take the variable speed and read it's value and we compare.

We compare the previous value of S with the current. We use a block for comparing.

If the previous value is greater than the current, so it's a greater than b and a is the variable and b is the rotation sensor, then we must stop the loop. How do we stop the loop. Each loop has the following. It can stop, whenever we pass through to this.

And this will break the loop. so this is the final stage at which we've reached the maximum speed and then let's continue rotating for about 5 seconds, so we can see these on the screen and then the program stops. This here is the whole program. Let's start it and see if it works.

Now the system starts rotating,

we wait till it reaches maximum speed,

and as you can see it took us about 17 seconds to reach the maximum speed. As you saw in the end, we just stopped detecting anymore, because we reached the maximum speed. That was for the program. It is little more complicated, it includes variables, but it's a nice exercise on programming and if you can get your head around these programs, you pretty much won't have any problems with other even more complex, programs.