Computer experts, please help with the codes. I would very appreciate your help
ID: 3765661 • Letter: C
Question
Computer experts, please help with the codes. I would very appreciate your help with the codes and clear comments for those parts. Thank you very much!
1) Write an Arduino program that turns on a motor for 1000 encoder counts. You will watch the wheel rotate and expect it to rotate 3 full turns. When you have the wheel rotating 3 full turns for 1000 encoder counts, you will know that you are correctly measuring the encoder data.
2) Write an Arduino sketch that calculates and displays motor speed. You will need to measure encoder counts over time. Motor speed should be measured and displayed separately for both the left and right sides. Set all four motors to spin in the same direction. Measure speed at a 25% duty cycle, 50% duty cycle, and 100% duty cycle. Report the speed in cm/s.
3) Write an Arduino sketch that drives your robot in a straight line for distances of 1m, 3m, and 5 m. First, test your sketch with the 1m distance. Your robot should be able to drive this distance without much error. Sensor measurements are subject to error. This error accumulates over time. As you increase the testing distance, your robot may appear to be more inaccurate by not driving in a straight line, drifting to the left or right, or not stopping very near the endpoint location.
In the setup function of your Arduino sketch, include a time delay long enough for you to press the reset button and place your robot at the starting line. The robot should drive from the starting line and stop exactly at the 1m mark. When you have tested your robot’s performance and are confident your Arduino program is correct, document your robot’s performance. How far away from the 1m mark did it stop? Did the robot start drifting left or right? If so, why do you think this happened?
Perform this test again for 3m and 5m distances. Record your results. If your robot is still performing well at the 5m distance, try a longer distance to find that point where the error accumulates and the robot does not have a good estimate of the distance traveled.
Explanation / Answer
Answered 1) question only. Please ask the rest of the questions separately.
int pwm=13; int forward=12; int reverse=11;
int encorderValue=0;
void setup()
{
Serial.begin(9600);
pinMode(21,INPUT);
attachInterrupt(2,count,FALLING);
encorderValue=0;
}
void loop()
{
digitalWrite(pwm,0);
digitalWrite(forward,0);
analogWrite(reverse,1);
delay(3000);
while(1)
{
if(encorderValue>1000)
break; // loop will break as soon as encoder value reaches 1000 or above
digitalWrite(forward,1);
digitalWrite(reverse,0);
analogWrite(pwm,255);
}
analogWrite(pwm,0);
}
void count()
{
encorderValue++;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.