Circle measure the distance¶
What students should know before:
Basic Lesson - Motors
Time constraints:
starting from 45 min - single lesson
Preparing For This Tutorial:¶
The LEGO Mindstorm EV3 Robot that coincides with this tutorial comes from building specific sections found in the LEGO Mindstorm Education - Driving Base.
For the first exercise, you can use a simple model presented below (measuring Wheel):
Effects¶
Computer science – Students will learn how to work with functions from LargeMotor, MoveSteering and Button classes.
Mathematics – Students will create a programme that will allow them to understand application of circle to measure the distance and see the applications of circle.
Physics – Students will have the opportunity to determine the instantaneous and average speed of the robot and apply a known formula \(v = \frac{s}{t}\).
Exercises¶
Create a programme that will display the distance traveled by the wheel (you see Figure nr 1. Draw a large infinity symbol on the floor and try to measure it.
Create a programme which will allow you to measure the average velocity of your robot.
Create a programme which will allow you to measure the instantaneous velocity of your robot.
Figure no 1 - Measuring Wheel |
Figure no 2 - Measuring Wheel |
Example solution¶
Exercise 1:
Math science
Ask students to measure the circumference of a circle with a thread and compare the results with colleagues in the group.
Ask students to calculate the circumference of the circle using the formula \(\text{Circumference} = 2 \times \pi \times \text{radius}\)
The distance is therefore equal to the circumference multiplied by the number of rotations.
\(distance\ = \text{Circumference } \times \text{rotations}\ \)
How to count the number of rotations? In the programme we will use property position from class LargeMotor which returns the current position of the motor in pulses of the rotary encoder. When the motor rotates clockwise, the position will increase. Likewise, rotating counter-clockwise causes the position to decrease. We consider the situation when the robot drives forward (or turns) but does not go backward. We get the number of rotations by dividing the value of the variable position by 360.
In the programme we will use the class Button to stop the robot.
Programme distance_1
Exercise 2 Create a programme which will allow you to measure the average velocity of your robot.
Physics science
Velocity is a physical vector quantity; both magnitude and direction are needed to define it. The scalar absolute value (magnitude) of velocity is called speed. For example, “10 metres per second” is a scalar, whereas “10 metres per second north” is a vector.
Average velocity is defined to be the change in position divided by the time of travel.
\(v{}_{\text{avg\ }} = \frac{\Delta d}{\Delta t} =\)\(\frac{\Delta d}{t}\)\(v{}_{\text{avg\ }} = \frac{\Delta d}{\Delta t} = \frac{\Delta d}{t_{\text{end}} - {t_{\text{start}}}_{}}\).
In programme \(\Delta t\) we compute d_t=time.time()-start_time,
where time.time() is current time. The value \(\Delta d\) is
computed from mb.position/360 which gives us the number of rotations
(note that at the beginning we put position equals to 0). So multiplying
obtained value by \(\text{circumference}\) gives us the distance
(programme velocity.py
).
Notice that this definition of velocity indicates that velocity is a vector because displacement is a vector. It has both magnitude and direction. The average velocity of an object does not tell us anything about what happens to the object between the starting point and the ending point. For example, we cannot tell from average velocity whether the car stops momentarily. Let’s note that the average speed is constant.
Computer science
In this programme we will use the on (steer, speed) function from the MoveSteering class to control two engines together (line 18).
The first argument - steering controls the path of the robot and can be any value between -100 and +100.
-100 means to turn left on the spot
-50 means to turn left with the left wheel not turning
0 means to go straight
+50 means to turn right with the right wheel not turning
+100 means to turn right on the spot.
The second argument - speed is the speed of the fast wheel. The speed of the slower wheel is automatically calculated based on the steering and speed values.
Programme velocity
It is obvious that if the vehicle has stopped the average speed will decrease. A slight modification of the above code (marked in yellow) makes it possible to observe changes in the average speed. We will use the right button from the brick to stop motors and enter button to stop the programme.
Programme velocity_1
Exercise 2 b
Step 1.
Physics science
How to compute the instantaneous velocity? If we consider v as velocity and d as the displacement (change in position) vector, then we can express the (instantaneous) velocity of a particle or object, at any particular time t, as the derivative of the position with respect to time.
\(v = \lim_{\Delta t \rightarrow 0}\frac{\Delta d}{\Delta t}\).
Computer science
From a programming point of view, we need a small period of time and a
distance related to this time. Look at the programme velocity_2.py
.
Variable d_distance (corresponds to \(\Delta d)\) is the difference
between current (mb.position) and previous (start_position_b) value of
motor’s position.The value of start_ position is updated in every
repetition of the loop. Distance necessary to compute the average
velocity is the sum of value d_distance (\(\Delta d)\). Analogous we
have with time. Value of variable d_time is the difference between the
current value of time and previous (d_time=c_time-s_time), while the
value of s_time is updated every repeat of the loop. So in d_distance
and d_time we have as small a possible value of distance and time
(duration is one repeat of the loop).
Programme velocity_2.py
Step 2.
We use the arithmetic mean of the left and right motor’s values to get the correct results when the robot turns (try to change the steering value).
Programme velocity_3.py
Summary¶
We have just learnt how to use functions from LargeMotor, MoveSteering and Button classes, moreover, how to use circles to measure the distance and how the car speedometer works.