Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Made images larger.

Scatter Plot Demo

Without Eigen C++ Library

  • Linear interpolation calculated manually
  • Primary readout group running at 100 Hz
  • Encoder trigger running at 10 Hz   (10x slower  than primary readout group)

Image Added

With Eigen C++ Library

Image Added

Lab 3 Tests

The encoder simulator, triggered by readout group 5, sent a test pattern alternating between values 100 and 200. Three different ratios of trigger rate were tested: 1, 10, and 100.

slowRatio=1

No interpolation occurs because trigger rates are the same.

Image Added

slowRatio=10

The primary readout group's trigger rate is 10x the trigger rate of the encoder.

Image Added

slowRatio=100

The primary readout group's trigger rate is 100x the trigger rate of the encoder.

Image Added





Demonstration of Polynomial Fit Using Eigen Package

...

Code Block
languagetext
titleMakefile
collapsetrue
ifndef GXX
$(error GXX must be set in environment)
endif

ifndef CONDA_PREFIX
$(error CONDA_PREFIX must be set in environment)
endif

eigen: eigen.cc
$(GXX) eigen.cc -o eigen -I $(CONDA_PREFIX)/include/eigen3
polyfit.py
Code Block
languagetextpy
titlepolyfit.py
collapsetrue
#!/usr/bin/env python

import matplotlib.pyplot as plt
import argparse
import subprocess
import sys

def main():
    parser = argparse.ArgumentParser(prog="polyfit", usage="%(prog)s [options] val val val [val...]")
    parser.add_argument('val', nargs='*', help='3 or more values')
    parser.add_argument('-r', type=int, default=10, help='trigger rate ratio (default=10)')
    parser.add_argument('-o', type=int, default=2, help='order of polynomial (default=2)')
    parser.add_argument('-v', action='store_true', help='be verbose')
    args = parser.parse_args()
    ratio = args.r
    order = args.o

    cmd = ["./eigen", "-o", f"{order}", "-r", f"{ratio}"] + args.val

    if len(args.val) < 3:
        parser.error("3 or more values required")

    if args.v:
        print(f"cmd: {cmd}")

    xx = subprocess.run(cmd, capture_output=True)

    result = xx.stdout.decode('UTF-8').strip()

    res = [ float(x) for x in result.split(",") ]
    if args.v:
        print(f"ratio: {ratio}")

    slow_times = range(0, ratio * len(args.val), ratio)
    fast_times = range(0, len(res), 1)

    if args.v:
        print(f"slow_times: (len {len(slow_times)}):  {slow_times}")
        print(f"args.val:   (len {len(args.val)}):    {args.val}")
        print(f"fast_times: (len {len(fast_times)}):  {fast_times}")
        print(f"res:        (len {len(res)}):         {res}")

    intval = [int(v) for v in args.val]
    plt.plot(slow_times, intval, 'ro', markersize=12.0)
    plt.plot(fast_times, res, 'g^')
    plt.title(f'Interpolated Encoder Values  (order={order})')
    plt.grid(True)
    plt.show()

if __name__ == '__main__':
    main()

Example Plots

...

(Click on Image Below for More)

Image AddedEncoder Interpolation.pdf