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
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 servos 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.
You are allowed to modify the header file but all those functions need to be implemented.
Aspects to consider:
Each encoder has 32 equidistant holes; thus, they are separated by 1/32 rotations.
Sometimes, if the wheels shake, the values read by the encoders might oscillate making the tick count increase very fast. You should take this into account.
The maximum speed of the servos is approximately 0.80 revolutions per second, so the shortest time interval between two holes is approximately 39ms. At half speed, the interval increases to 78ms, at one fourth it increases to 156ms, and so on. These intervals are very large when compared to the speed at which a processor can run. For this reason, it is possible to measure the speed when you havent even counted 1 tick. This is especially true at slow speeds. If you havent seen any new ticks since the last time you called getSpeeds, and you try to get a new measure what speed should you return? How do you know whether the robot is moving very slow or just standing still?
Do the encoders used in the course provide information on the direction that the wheel has moved (forward / backward)?
MyEncoders.h
#ifndef __MY_ENCODERS__ #define __MY_ENCODERS__ //this function sets the tick counts to 0 void resetCounts() { count = 0; } //this function should return the left and right tickcounts // since either the start of the program or the last //call to the function resetCounts() void getCounts(unsigned long counts[]); //this function should return the instantaneous speeds of the wheels //meassured in revolutions per second. void getSpeeds(float speeds[]); //this function should include whatever code necessary to initialize this module void initEncoders(); #endif Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
