K values
We could use the heading and distance values measured by IR 1 to directly control the steering for the tank. However, this is not ideal. Instead, we need to multiply each of these values in order to scale them so that the resulting corrections fit better with the possible range of the hardware. The factor by which a measurement is multiplied is called a k value.
Most proportional feedback loops use a k value. In this part of the program, we will use two: the first (k1) will multiply the measured beacon heading to control the magnitude of the steering, and the other (k2) will multiply the measured distance to control the speed.
The optimal value for k1 is 5. The optimal value for k2 is 10. k2 is set so that for any distance value greater than 10, the resulting power level of the drive motors will be greater than 100%. Not to worry, because the EV3 will simply run the motors at 100% power whenever it sees a value that is larger. k2 is set this way because the tank should only slow down if the beacon is very close; the tank will drive at full power to follow the beacon unless the distance to the beacon is less than 10.
To incorporate these k values into the program, add a math block after the new sensor block and set its mode to multiply. Drag a data wire from the heading output of the sensor block and plug it into the input a of the math block. In the b input, enter a value of 5, the value we set for k1.
Take out a second math block and set its mode to multiply as well. Place it after the first multiplication block. Drag out a data wire from the proximity output of the IR sensor block and plug it into the a input of the math block. Enter 10, the value we set for k2, into the b input of the math block.