0% found this document useful (0 votes)
322 views5 pages

Lab Assignment 10 Wheel Encoders-1

The document describes a lab assignment involving building a simple robot and developing software for navigation using wheel encoders. Wheel encoders count motor rotations to calculate distance traveled. The program uses interrupts to read the encoder signals and control a DC motor's direction and speed based on the encoder position relative to a target angle. Calculations were done to convert the encoder count to degrees turned by the motor.

Uploaded by

api-519059218
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
322 views5 pages

Lab Assignment 10 Wheel Encoders-1

The document describes a lab assignment involving building a simple robot and developing software for navigation using wheel encoders. Wheel encoders count motor rotations to calculate distance traveled. The program uses interrupts to read the encoder signals and control a DC motor's direction and speed based on the encoder position relative to a target angle. Calculations were done to convert the encoder count to degrees turned by the motor.

Uploaded by

api-519059218
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Lab Assignment 10: Wheel Encoders

Introduction – in your own words, briefly describe the purpose of the laboratory and the

operation of your completed program(1-2 paragraphs).

The purpose of the laboratory assemble your simple robot and develop software for

simple navigation. Also, have an understanding of the wheel encoder is used to count the

number of times the motor (left or right) has rotated. To calculate the distance that the robot has

driven or turned. An Encoders convert the motion to an electrical signal that can be read by some

type of control device in a motion control system.

Implementation – the implementation section of your lab report should include the following:

Schematic of your circuit


A photograph or youtube link to a video of your completed circuit and program in

operation

1. Listing of your program

// motor control pin


const int motorDirPin = 5; // Input 1
const int motorPWMPin = 6; // Input 2
const int EnablePin = 9; // Enable
const int LED = 13;
// encoder pin
const int encoderPinA = 2;
const int encoderPinB = 3;
int encoderPos = 0;
// encoder value change motor turn angles
const float ratio = 360./188.611/48.;
// 360. -> 1 turn
// 188.611 -> Gear Ratio
// 48. -> Encoder: Countable Events Per Revolution (Motor Shaft)
// P control
float Kp = 30;
float targetDeg = 360;

void doEncoderA()
{
encoderPos += (digitalRead(encoderPinA)==digitalRead(encoderPinB))?
1:-1;
}
void doEncoderB()
{
encoderPos +=
(digitalRead(encoderPinA)==digitalRead(encoderPinB))?-1:1;
}

void doMotor(bool dir, int vel)


{
digitalWrite(motorDirPin, dir);
digitalWrite(LED, dir);
analogWrite(motorPWMPin, dir?(255 - vel):vel);
}

void setup()
{
Serial.begin(9600);

pinMode(encoderPinA, INPUT_PULLUP);
attachInterrupt(0, doEncoderA, CHANGE);

pinMode(encoderPinB, INPUT_PULLUP);
attachInterrupt(1, doEncoderB, CHANGE);

pinMode(LED, OUTPUT);
pinMode(motorDirPin, OUTPUT);
pinMode(EnablePin, OUTPUT);
}

void loop()
{
float motorDeg = float(encoderPos)*ratio;
float error = targetDeg - motorDeg;
float control = Kp*error;

digitalWrite(EnablePin, 255);

doMotor((control>=0)?HIGH:LOW, min(abs(control), 255));

Serial.print("encoderPos : ");
Serial.print(encoderPos);
Serial.print(" motorDeg : ");
Serial.print(float(encoderPos)*ratio);
Serial.print(" error : ");
Serial.print(error);
Serial.print(" control : ");
Serial.print(control);
Serial.print(" motorVel : ");
Serial.println(min(abs(control), 255));
}
2. An explanation of the structure of your program, and an explanation of how your

program works.(2-3 paragraphs)

The structure of my program where it starts with the micro-control pinouts where I

connect to my breadboard that is the motor control. Also, display how encoder code wheels

contain data tracks that are a series of alternating clear and opaque areas. Then input the encoder

pin where I connect the micro-controller with wire DC motor with Encoder in 2 and 3 pinouts.

Even, to input encoder value change motor turn angles with const float ratio = 360./188.611/48.

If I click the code, start simulation the Serial Monitor and start rotating the encoder we

will start getting the values in the serial monitor. Input serial. print that would display in the

serial monitor encoderPos, Motor Deg, error, control, and MotorVel. Relative encoders detect
changes in position relative to their starting position, which resets when they power off. The

encoder sends a feedback signal that can be used to determine position, count, speed, or

direction.

3. Any calculations that you completed during the laboratory (for example, LED resistor
calculations) with explanation of their purpose

Yes for the encoder value change motor turn angels and have any understand how much motor
should move. It helps me have a calculation with the motor encoder is a rotary encoder mounted
to an electric motor that provides closed-loop feedback signals by tracking the speed and/or
position of a motor shaft.

360. -> 1 turn

188.611 -> Gear Ratio

48. -> Encoder: Countable Events Per Revolution (Motor Shaft)

You might also like