Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) void setSpeeds(int microsLeft, int microsRight) 2)void calibrateSpeeds() 3)vo

ID: 3872630 • Letter: 1

Question

1) void setSpeeds(int microsLeft, int microsRight)

2)void calibrateSpeeds()

3)void setSpeedsRPS (float rpsLeft, float rpsRight)

4)void setSpeedsIPS(float ipsLeft, float ipsRight)

5)void setSpeedsvw(float v, float w)

•The first function should set the speed of the motors by giving the speeds in microseconds. You should write the code so that microsLeft and microsRight control the left and right speeds of the wheels respectively. Also, you should implement the function so that if bothvalues are positive the robot will mov e forward, if both are negative it will move backwards, and if both are 0, it should not move.

•The second function should use the encoder functions implemented on section B .1.2 to create a mapping from the servos input(micro seconds)to the servos output (wheel speed in revolutions per second). In other words, measure the speeds of the wheels for different input values and store the results. You should do this for both wheels since the servo’s output won’t necessarily be the same for both wheels. This information will be used by the following functions.

•The third function should set the speed of the motors as in the first function, but this time, theinput parameters indicate the speeds at which each wheel should spin.

•The fourth function is the same as theprevious one, but this time, the speed is given in inches per second.

•The fifth function should set the speed of the robot, so that the robot will move with a linear speed given by the parameter ‘v’ (in inches per second), and with an angular velocity ‘w(given in radians per second). Positive angular velocities should make the robot spin counterclockwise.

Aspects to consider:

•The wheels’ diameter is 2.61''.

•The wheels are separated by 3.95'' approximately, although this may vary from robot to robot since some may be bent.

FOR ARDUINO SOFTWARE

Explanation / Answer

/*-------definning Inputs------*/
#define LS 2 // left sensor
#define RS 3 // right sensor

/*-------definning Outputs------*/
#define LM1 4 // left motor
#define LM2 5 // left motor
#define RM1 6 // right motor
#define RM2 7 // right motor

void setup()
{
pinMode(LS, INPUT);
pinMode(RS, INPUT);
pinMode(LM1, OUTPUT);
pinMode(LM2, OUTPUT);
pinMode(RM1, OUTPUT);
pinMode(RM2, OUTPUT);
}

void loop()
{
if(digitalRead(LS) && digitalRead(RS)) // Move Forward
{
digitalWrite(LM1, HIGH);
digitalWrite(LM2, LOW);
digitalWrite(RM1, HIGH);
digitalWrite(RM2, LOW);
}
  
if(!(digitalRead(LS)) && digitalRead(RS)) // Turn right
{
digitalWrite(LM1, LOW);
digitalWrite(LM2, LOW);
digitalWrite(RM1, HIGH);
digitalWrite(RM2, LOW);
}
  
if(digitalRead(LS) && !(digitalRead(RS))) // turn left
{
digitalWrite(LM1, HIGH);
digitalWrite(LM2, LOW);
digitalWrite(RM1, LOW);
digitalWrite(RM2, LOW);
}
  
if(!(digitalRead(LS)) && !(digitalRead(RS))) // stop
{
digitalWrite(LM1, LOW);
digitalWrite(LM2, LOW);
digitalWrite(RM1, LOW);
digitalWrite(RM2, LOW);
}
}