Assignments‎ > ‎Pre Lab 3 Encoder‎ > ‎

Pre Lab 3 FAQ

FAQ Section:
updated 1/21 by djyang@ucsd.edu

Part 1: 
a-c) keep it brief
d) Make sure your motor is not plugged into the motor driver. Measure with multi-meter
e) Measure this with a multi-meter
f) oops, you were supposed to take a photo of this. Luckily you will do the same thing in part 2.3. Don't forget to sand annotate the photo.
g) What does slow down the motor mean? Good question, there are two interpretations:
Slow the motor by applying a load.
Slow the motor by reduceing the PWM going to the motor
h) The disassembled rotor is located in the corner of the room next to the arbor press and scale.

General Advice and Issues:
  1. Do not attach your poteniometer for these exercises, it will can slow down the motor too much and skew your results.
  2. Cannot open Arduino sketch? That's because the file name has a number in front. Delete that number and underscore and you should be happy.
  3. The arduino and o-scope are outputting the frequency of the encoder ticks, not to be confused with the angular frequency of the motor. To convert between the two: divide by CPR and spice it up with some 2π to get rad/s.
  4. Encoder pins must able to handle interrupts. On mega 2560, only digital pins 2, 3, 18, 19, 20, and 21 read interrupts
How to get Arduino to Matlab:
There are two ways: .CSV (comma separated variable) and direct Copy and Paste. The latter is faster but way more janky:
1) change your print statements to add a semicolon (;) after every line:

    Serial.print(millis());           
    Serial.print(",");              
    Serial.print(count);           
    Serial.print(",");              
    Serial.print(omega, 3);         
    Serial.println(";");

2) Copy and Paste terminal window into matlab
3) Add a "A = [" infront of the data
4) Add a "];" at the end of the data

Example:
A = [
13923, 43826, 458.15;
13934, 43860, 404.60;
..... 
13974 ,44001, 458.15; ];


From the Homework:
 

Translation: for part 2.3 ONLY. Turn your motor on from rest and output to the terminal time (ms), position (counts), and encoder frequency. Provide the following plots for the first 500ms of motor startup:
Position(rads) vs Time (ms)
Unfiltered Velocity (rad/s) vs Time (ms)
Filtered Velocity (rad/s) vs Time (ms) Combine this plot with unfiltered velocity
Create these plots for both forwards and backwards rotation, and take a photo of the o-scope at steady state for each experiment.

Now here is where things get sketchy: In lecture the professors asked you to use a backwards difference low pass filtered velocity estimate. The problem is, the loop time is just too damn fast, leading to oversampling (wikipedia). So the velocity data has a ton of discretization noise. Instead, I suggest converting the encoder frequency to angular velocity (see general advice #3), and plotting and filtering that frequency instead.

To summarize, the deliverables of Part II of the assignment actually:
2.1.b) Give the max encoder speed your code can read, and a short description of the experiment and why
2.2.b.b) (lets just call this 2.2.b) Do either of the suggested methods
2.3) Just do the parts under "Translation". You should have 4 plots total, and two photos of the o-scope.

Part 2.1: encoder counting for noobs
a) No need to modify any code. Code 2.1 seems does this for you already. Plus, 2.1a is not even really asking a question, so how can you get it wrong?
bonus points: doesn't input_encoder_A_now == 0 making it a falling edge? I have no idea anymore.
b) The purpose of this question is to show that a certain speeds, the arduino will start skipping counts and can no longer keep up with the encoder.

Part 2.2: encoder counting for middle school students
a) What is an interrupt? Wikipedia: link
2.2.b.a) This asks you to redo 2.1.b, except with the new interrupt code. You should find that it does not skip counts anymore
2.2.b.b) Ok, something was lost in translation here. How can you use the o-scope to measure the frequency of the program?
Maybe you were supposed to have a DigitalWrite(pin,1) and a DigititalWrite(pin, 0) in your code so you could read the pulse on the o-scope?
Maybe you are supposed to take the time stamps and find the frequency by taking 1/Δt? But this doesn't use the o-scope...

Part 2.3:  encoder counting for pre teens
a) Again, this code is provided. There is a random typo, change the println(count) to a regular Serial.print(); 
b) Why does the encoder frequency 4x more than the o-scope?
The o-scope only measures channel A's rise time frequency (12 CPR)
The quadrature encoder arduino code measures rise and fall, and two channels (12*2*2 = 48 CPR)
c) Additional stuff to turn in:
2x plots Filtered and unfiltered velocity vs time, for forewards and backwards
2x pictures of the O-scope forewards and backwards

Part 3: Update Hardware
Sorry we dropped the ball on this one.
Comments