preview

Nt1310 Unit 8 Lab

Decent Essays

The objective of the lab was to program a vehicle to continuously drive in a one meter square. The square was to be completed in less than 20 seconds, and only the wheel encoder could be used to navigate the vehicle. All of this was done by using the Arduino software tool and the Redbot library to create a program that would satisfy the given lab requirements. The program below has a void setup() function which only runs once and is used to create a pin input into the board. Next is the void loop() function which runs forever until there is a condition that makes the program exit the loop. In the loop() function, there is a for loop that contains the functions driveStraight() and turnLeft() with a delay command after each one. The drive Straight() function takes in the two parameters, the preferred distance and motor power.The turnLeft() function takes in an angle and turning speed. …show more content…

Next, there is a while loop that continues to run if the left encoder is less than the value of the number of revolutions multiplied by the counted ticks per revolution. After this, if the computed motor ticks are unequal between the two motors, the function is written to where the vehicle can adjust and correct itself if it starts to drift to one side. This is done by if-else statements in which each motor power is adjusted. Variables used in the driveStraight() function were used in the turnLeft () function as well. The function contains a turningTime variable, which is set to the inputted angle multiplied by 1000 and is divided by the inputted turning speed. Like the previous function, if-else statements were used to adjust each of the motors power to make a proper turning angle. At the end of the function, the command encoder.clearEnc(Both) clears both the encoders counted motor

Get Access