Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ARDUINO C++ HELP! WILL RATE! Need some help finishing an encoder header file for an Arduino Uno bot : Arduino bot: https://www.parallax.com/product/32335 Encoder: https://www.parallax.com/product/28107 Servo:

ARDUINO C++ HELP! WILL RATE!

Need some help finishing an encoder header file for an Arduino Uno bot :

Arduino bot: https://www.parallax.com/product/32335

Encoder: https://www.parallax.com/product/28107

Servo: http://www.mantech.co.za/Datasheets/Products/900-00008-65S.pdf

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 interrupts 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 (don't need to answer questions): 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?

Here's what I have so far with the encoder:

#ifndef __MY_ENCODERS__

#define __MY_ENCODERS__

//this function sets the tick counts to 0

void resetCounts();

unsigned long lEncCount = 0;

unsigned long rEncCount = 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[]);

bool resetCounts(){

//not sure here

}

unsigned long lEncLast = 0;

unsigned long rEncLast = 0;

int lEncVal = digitalRead(lEncPin);

int rEncVal = digitalRead(rEncPin);

if (lEncVal != lEncLast) lEncCount++;

if (rEncVal != rEncLast) rEncCount++;

lEncLast = lEncVal;

rEncLast = rEncVal;

//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();

int lEncPin = 10;

int rEncPin = 11;

//SET ENCODERS

pinMode(lEncPin, INPUT_PULLUP);

pinMode(rEncPin, INPUT_PULLUP);

#endif

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What does the target full product cost include?

Answered: 1 week ago

Question

=+ Introduce unionization rates and rationales pro and con.

Answered: 1 week ago

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago