Lab Assignment 10 Wheel Encoders-1
Lab Assignment 10 Wheel Encoders-1
Introduction – in your own words, briefly describe the purpose of the laboratory and the
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
Implementation – the implementation section of your lab report should include the following:
operation
void doEncoderA()
{
encoderPos += (digitalRead(encoderPinA)==digitalRead(encoderPinB))?
1:-1;
}
void doEncoderB()
{
encoderPos +=
(digitalRead(encoderPinA)==digitalRead(encoderPinB))?-1:1;
}
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);
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
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.