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

In this section you will implement a library to use the wheel encoders. Encoders

ID: 3883571 • Letter: I

Question

In this section you will implement a library to use the wheel encoders. Encoders allow the robot to get feedback on motor rotations by counting the number of holes encountered by the encoder. Encoders are needed since a servo’s response to the control signal varies due to several factors including floor friction, load on the motors, noise, etc. For this section, you must use interrupts3 to implement the 4 functions on the header file “MyEncoders.h”:

1) void resetCounts()

2) void getCounts(unsigned long counts[])

3) void getSpeeds(float speeds[])

4) void initEncoders()

The first function should reset the tick count (number of holes counted) to zero.

The second function should return the left and right tick counts since the last call to

resetCounts, or since the start of the program (if there were no calls to resetCounts).

The third function should return the instantaneous left and right wheel speeds (measured in revolutions per second).

The fourth function should contain whatever code is necessary for initialization.

Must be for ARDUINO

Explanation / Answer

#include //the motor driver uses this library #include Servo LEFT, RIGHT;//left wheel right wheel int RclickNum=0;//used for the rotory encoder int LclickNum=0;//these are the number of "clicks" each wheel has moved int D =115;//Drive int R =70;//Reverse int B =90;//Break int Linterrupt = 1;//these are the interrupt numbers. 0 = pin 3 and 1 = pin 2 int Rinterrupt = 0; int clickConvert = 7;// how many rotary encoder clicks equal a foot void setup() { Serial.begin(9600); //starting serial communication LEFT.attach( 9, 1000, 2000);//attaching the motor controller that is acting like a servo RIGHT.attach(10, 1000, 2000); attachInterrupt(Linterrupt, LclickCounter, FALLING);//attaching the rotary encoders as interrupts that will attachInterrupt(Rinterrupt, RclickCounter, FALLING);//trip when the encoder pins go from high to low } void loop() {//This is for controling the robot using the standard wasd format int input= Serial.read(); if(input == 'a') left(2); if(input == 'd') right(2); if(input == 'w') forward(2); if(input == 's') backward(2); if(input == 'e') STOP(); } void forward(int feet)//this is called when w is sent threw the serial port and is where i am testing all of my code. { interrupts(); //turn on the interrupts while(RclickNum
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote