©  Gene Harding 2018
Gene HardingProgramming LEGO® EV3 My Blockshttps://doi.org/10.1007/978-1-4842-3438-9_4

4. Turning in Place

Gene Harding1 
(1)
South Bend, Indiana, USA
 

Learning Topics

My Blocks , geometry , unit conversion , calibration , torque , traction , dead reckoning , and parallel execution

Requirement

Turn left or right to an angle specified in degrees

The next step in effective navigation is being able to turn. This chapter focuses on turning in place from a dead stop. There are two basic approaches. The first is to lock one wheel while driving the other wheel. In this mode, the robot’s pivot axis is the wheel that is not rotating, as shown in Figure 4-1 (a–d). The second approach is to drive both wheels, but in opposite directions. In this method, the robot’s pivot axis is ideally the center point between the two wheels, as shown in Figure 4-1 (e and f). For the sake of clarity, the term “turn” is used to describe the first technique, whereas “spin” is used to describe the second.
../images/461934_1_En_4_Chapter/461934_1_En_4_Fig1_HTML.jpg
Figure 4-1

Turning options

For high turning precision, especially for the first approach previously listed, a narrow, high-crown tire is better than a wide tire with a flat cross-section. As shown in Figure 4-2, the reason is that the pivot point for a high-crown tire is the center of the tire, whereas the pivot point for a flat-profile tire could be most any point across the part of the tire contacting the mat.
../images/461934_1_En_4_Chapter/461934_1_En_4_Fig2_HTML.jpg
Figure 4-2

Tire profile comparison

Turning Left and Right

Learning topics covered: My Blocks , geometry , unit conversion , torque , traction

Although it is possible to construct one My Block that can perform all four turn types (a–d), it is arguably better to use one My Block for right turns and another for left turns. There are at least two reasons to do so. First, the code becomes somewhat self-commenting as a block named TurnRight clearly implies the robot is going to turn right, even with no comment added. Second, a fringe benefit is that the My Block code is simpler.

To create an intuitive turn My Block, desired degrees of turn angle for the robot must be converted to degrees of wheel rotation for the appropriate drive motor. In the forward and backup My Blocks , we converted inches of linear movement to degrees of wheel rotation. A similar exercise in geometry and algebra will allow a straightforward conversion from turning angle degrees.

The distance (center to center) between the robot’s two drive wheels is the track width . For turning, this distance is also the radius of the circle that the outside wheel traces as the robot turns, as shown in Figure 4-3. The lowercase variable c refers to the circumference of the driving wheel, R is the robot’s track width and turning circle radius, and C is the robot’s turning circle circumference. Dividing the turning circle circumference by the wheel circumference gives the ratio of motor (axle) rotation degrees to turn angle degrees, which is the number we need to convert a turning angle My Block input to motor rotations. If the robot track width is 4.8" and tire circumference is 7.0", then we get the following:

$$ conversionkern0.38em factor=frac{{}^{{}^{circ}} motor  rotation}{{}^{{}^{circ}} turn  angle}=frac{2pi R}{c}=frac{2pi left({4.8}^{"}
ight)}{7.0^{"}}=4.3 $$
(8)
../images/461934_1_En_4_Chapter/461934_1_En_4_Fig3_HTML.jpg
Figure 4-3

Degrees of turning angle vs. axle rotation

The My Block is pretty simple. Start with a Large Motor block configured to stop motor C so that it does not move, then a Math block to convert turning angle to degrees of motor rotation, and finally a Large Motor block to rotate the B motor (left side) to make the robot turn to the right. The TurnRight My Block code is shown in Figure 4-4.
../images/461934_1_En_4_Chapter/461934_1_En_4_Fig4_HTML.jpg
Figure 4-4

TurnRight My Block code

The My Block itself is shown in a program in Figure 4-5, where it has been set to turn the robot 20° at 20 percent power. The My Block code (Figure 4-4) will multiply the 20° input by 4.3 so the wheel rotates 86° to accomplish the 20° turn angle. Be careful not to use a power that is too large. This can cause the drive wheel to lose traction , and the resultant slippage will make turning angles inconsistent. A little bit of testing and tweaking to calibrate the conversion parameter and input power should give you a My Block that turns at angles close to the specified input values. Also, note that a negative value for either input will make the robot back up to the right, whereas positive values will make it rotate forward to the right.
../images/461934_1_En_4_Chapter/461934_1_En_4_Fig5_HTML.jpg
Figure 4-5

TurnRight My Block in a program, to turn 20° at 20 percent power

A TurnLeft My Block is now easy to make. Use the same approach, but change the TurnAngle icon from a right arrow to a left arrow, change the first motor block to lock the B motor, change the second motor block to drive the C motor, and update the comments appropriately. Figure 4-6 shows an example.
../images/461934_1_En_4_Chapter/461934_1_En_4_Fig6_HTML.jpg
Figure 4-6

TurnLeft My Block

Spinning Left and Right

Learning topics covered: My Blocks , geometry , unit conversion , torque , traction

The SpinRight and SpinLeft My Blocks are similar to the turn My Blocks, but the geometry is different because both motors are driven together. In the turn My Blocks , the robot’s track width was the turning circle radius . In the spin My Blocks, the track width is the turning circle diameter (see Figure 4-7).
../images/461934_1_En_4_Chapter/461934_1_En_4_Fig7_HTML.jpg
Figure 4-7

Degrees of spin angle vs. axle rotation

This means that the conversion factor for the spin My Blocks will be about half of the conversion factor in the turn My Blocks . Because both motors are driven, the first block will be the Math block to convert turning angle into degrees of wheel rotation, with the smaller multiplier. Add a second Math block to invert (multiply by -1) the output for the right motor, which will turn backward. As in the TurnRight My Block, next comes the Large Motor block to rotate the B motor forward. Its Power input comes from the My Block’s Power input, and its Degrees input comes from the first Math block’s output.

Now we will do something that is a new feature with the EV3 software: operate two sections of code in parallel simultaneously, i.e., parallel execution. Add a second Large Motor block to run the C motor in mode “On for Degrees,” but place it below instead of to the right of the other Large Motor block.

Next, use the pointer to “grab” the Sequence Plug Exit of the second Math block (not the data wire output port; the output plug at the right end of the Math block) and connect it to the Sequence Plug Entry of the C motor block. When you do that, the program will automatically shift the other motor block to the right, making it obvious that parallel operation is occurring. Connect the numeric data output of the second Math block to the Degrees input, and the Power input of the My Block to the motor block’s input, as shown in Figure 4-8.

Construct the SpinLeft My Block in a similar manner, changing the forward drive motor to C, the backward drive motor to B, and updating the icon and comments, as shown in Figure 4-9.
../images/461934_1_En_4_Chapter/461934_1_En_4_Fig8_HTML.jpg
Figure 4-8

SpinRight My Block

../images/461934_1_En_4_Chapter/461934_1_En_4_Fig9_HTML.jpg
Figure 4-9

SpinLeft My Block

Conclusion

If you have created all of the My Blocks up to this point in the book, you have what you need to navigate anywhere on a challenge board using what is called dead reckoning . In dead reckoning navigation , one’s position is calculated from a starting point based on the distance and direction traveled. The problem with dead reckoning is that any errors in those calculations tend to be larger as distance traveled gets larger. For instance, if you point your robot at an object on the board and program it to go forward, it might come within a fraction of an inch of its intended mark if that mark is a short distance away. On the other hand, if it must travel several feet to get there, it could be off by more than an inch, which could result in a failed mission.

Before the days of radio navigation (e.g., LORAN, TACAN, GPS), pilots used what is called waypoint navigation. People use this method of navigation all the time without thinking about it. Suppose you were giving someone directions to the store. It might go something like this:

“Go up the street that direction and take a left at the stop sign. Turn right at the first traffic light, then go about ¾ mile and turn left just before the gas station. The store will be on the right.”

Those landmarks—stop sign, traffic light, gas station—are waypoints, fixed points of reference that can be used to adjust, or correct, dead reckoning navigation . FLL challenge boards always have lines on the mats and border walls that can be used for such corrections to improve navigation precision. The next two chapters deal with using lines and border walls for this purpose.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.246.203