Step 4. Converting the Word Block Program
The are 2 reason for modifying the programs. Missing reflection calibration word block and motor configuration.
The legacy EV3 word block program relies on percentage reflection to determine if the robot is off track. Before the robot can work reliably, the maximum and minimum must be established by using the build-in calibration word blocks. The following word block code is captured from the EV3 line follower program.
Once the calibration is done, the main program of the line follower is captured below for reference. Please note that it is very important for the following program to have an accurate calibration. If the calibration is not done properly and the value returned is biased, the robot will not function.
As mentioned earlier, the reflection calibration word block is no longer available from the Spike Prime / Robot Inventor; therefore, we will have to change the programming approach. We will therefore reference the now Spike Prime / Robot Inventor line follower approach to use colour detection. The new code relies on colour detection instead of percentage reflection. It is much cleaner because it does not have any calibration related code. Please see the capture below for reference.
The new word block code simple turns the robot based on the color received instead of reflection.
The 2nd change is the fact that the 2nd movement percentage speed is now a negative number. Let me explain the reason behind the negative sign. Imagine you put two motor side by side and both of them has a rotating wheel on top truing in a clockwise manner; as show in the middle 2 rows of the table below. Now if you turn the 2 motors sideways with the wheel on the side and look at the direction of rotation from above.
As shown in the table below, the 2 wheel will not be moving in sync forward or backward. To compensate for the sideway motor, Lego word blocks has already flipped the director of one of the motors in SP / RI. However, for EV3 motors for this particular robot, if the motors are in same direction, the robot will be moving forward already.
Therefore, in order to compensate for the build-in compensation by Lego, we will have to turn one of the direction of the motor negative, as shown in the word block program above.