Facts about This Project

  1. Encoders must be used for actions as simple as opening or closing the claw. Encoders can be used to measure the amount a wheel has turned and can be used to calculate how many encoder ticks are needed to go a certain distance. In this case, encoders are used to see how much a motor must turn to fully open or close a claw. If a motor continues to turn after a claw is completely opened or closed, the claw may snap.

void closeClaw(){

nMotorEncoder[clawMotor]=0;

while(nMotorEncoder[clawMotor]<30){

motor[clawMotor]=50;

}

}


  1. This code must be completed using basic, simple, and complex behaviors. A basic behavior is a single line of code and is the shortest and simplest behavior a robot can perform. A simple behavior is a function that uses a series of basic behaviors to perform one action while a complex behavior is the main task and can use a series of both simple and basic behaviors to complete a task.

  2. Encoders can also be used to calculate how much a wheel has to rotate in order to turn a certain number of degrees. This is done by calculating the circumference of an imaginary circle which is the path a robot takes while turning. The circumference is dependent on the dimensions of the robot as well as the type of turn it is performing. The formula for calculating the circumference of a circle is C = 2πR, meaning that the circumference, or the length of the are around a circle, is the radius, half of the diameter which is the width of the circle, multiplied by two and then multiplied by Pi. The radius in this case is the distance between the two wheels of a robot. In the case, of a spin turn however, the bot width is the diameter. The circumference divided by the wheel circumference multiplied by 360, the number of encoder ticks in one rotation, equals the number of encoder ticks for a 360-degree rotation. Using the rate at which encoder ticks move the robot, one can also find the number of encoder ticks needed to travel for a shorter or longer turn.

float spinDegToTicks(int spinDeg){

return Botwidth * PI/WheelCircum * 360/(360/spinDeg)

}

  1. This project is done by using PID line tracing. PID stands for proportional, integral, and derivative. The bot tries to trace the very edge of the line and the proportional part means compensating for the error. The edge of the line is the target value and the error is the target value minus the current sensor value. The integral is an accumulation of all the errors. The derivative used the difference between the previous error and the current one to find a trend and use it to predict the next error. In PID line tracing, there is also values called K values. These numbers act as multipliers for the error, integral, and derivative. There are three K values. These numbers are the KP, KI, and KD. the amount the robot must turn is determined by a value called the correction. The correction is the error multiplied by the KP plus the integral multiplied by the KI plus the derivative multiplied by the KD. This correction is added to the motor speed of one motor and subtracted to the other. PID line tracing is a more accurate form of line following.

void lineTrace(float turn){

error=targetValue-SensorValue[light];

reading=SensorValue[light];

turn=correction(error, last_error);

motor[leftMotor]=26+turn;

motor[rightMotor]=26-turn;

last_error=error;

}