Complete the program below to have a robot move away from a light source. The ro
ID: 2081339 • Letter: C
Question
Complete the program below to have a robot move away from a light source. The robot has two wheels, similar to the robot used in lab, and has a light sensor on each side. See figure below Motor Control Assume that you are programming Timer 1 module A (for left motor) and Timer1 module B (for right motor) to generate PWM waveforms to control the speed of each wheel's motor (note, connect Timer 1 to Port B). The speed of the motor is proportional to the percentage of time the PWM signal is high (i.e. PWM duty cycle). Note: Your PWM wave must have a period of 1.4ms Note the system clock is 16 MHz Light Sensors: The light sensors are connected to Channel 4 (left sensor) and 7 (right sensor) of the ADC as single channel inputs (i.e. not different Robot behavior: The Robot should move away from the light in the following way. Where "Speed of motor" is the fraction of the motor's maximum speed. Speed of left motor Intensity of left sensor (Intensity of left sensor Intensity of right sensor) Speed of right motor Intensity of right sensor (Intensity of left sensor Intensity of right sensor) Turn away from light Front Robot BackExplanation / Answer
// Don’t go into the light program
main()
{
int left_sensor;
int right_sensor;
int left_motor;
int right_motor;
init_TIMER1_A_B();
init_ADC();
while(1)
{
get_sensor_reading(&left_sensor, &right_sensor);
// Computed motor speed commands
left_motor = (100*left_sensor)/(left_sensor + right_sensor);
right_motor = (100*right_sensor)/(left_sensor + right_sensor);
set_motor_speed(left_motor, right_motor);
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.