def plot(canon, H, riders, environments, idMats):
    filename = ''
    for rider in riders:
        filename += '-' + rider
    for env in environments:
        filename += '-' + env.replace(' ', '')

    filename = 'canonical-id-plots/' + filename[1:]

    print filename

    v0 = 0.
    vf = 10.
    num = 100

    mM, mC1, mK0, mK2, mH = csi.mean_canon(riders, canon, H)
    speeds, mAs, mBs = bicycle.benchmark_state_space_vs_speed(mM, mC1, mK0, mK2,
            v0=v0, vf=vf, num=num)
    w, v = control.eigen_vs_parameter(mAs)
    mEigenvalues, mEigenvectors = control.sort_modes(w, v)

    iM, iC1, iK0, iK2, iH = idMats
    speeds, iAs, iBs = bicycle.benchmark_state_space_vs_speed(iM, iC1, iK0, iK2,
            v0=v0, vf=vf, num=num)
    w, v = control.eigen_vs_parameter(iAs)
    iEigenvalues, iEigenvectors = control.sort_modes(w, v)

    aAs, aBs, aSpeed = csi.mean_arm(riders)
    w, v = control.eigen_vs_parameter(aAs)
    aEigenvalues, aEigenvectors = control.sort_modes(w, v)

    rlfig = plt.figure()
    ax = rlfig.add_subplot(1, 1, 1)
    ax.plot(speeds, iEigenvalues.real, 'k-')
    ax.plot(speeds, abs(iEigenvalues.imag), 'k--')
    ax.plot(speeds, mEigenvalues.real, 'b-')
    ax.plot(speeds, abs(mEigenvalues.imag), 'b--')
    ax.plot(aSpeed, aEigenvalues.real, 'r-')
    ax.plot(aSpeed, abs(aEigenvalues.imag), 'r--')
    ax.set_ylim((-15, 10))
    ax.set_xlabel('Speed [m/s]')
    ax.set_ylabel('Real and Imaginary Parts of the Eigenvalues [1/s]')
    rlfig.savefig(filename + '-eig.png')
    rlfig.clf()

    # bode plots
    speeds = [2.0, 3.0, 5.8, 9.0]
    null, mAs, mBs = bicycle.benchmark_state_space_vs_speed(mM, mC1, mK0, mK2,
            speeds)
    null, iAs, iBs = bicycle.benchmark_state_space_vs_speed(iM, iC1, iK0, iK2,
            speeds)
    C = np.array([[1.0, 0.0, 0.0, 0.0]])
    D = np.array([[0.0, 0.0]])
    systems = []
    inputNames = ['$T_\phi$', '$T_\delta$']
    stateNames = ['$\phi$', '$\delta$', '$\dot{\phi}$', '$\dot{\delta}$']
    outputNames = ['$\phi$']
    for A, B in zip(mAs, mBs):
        systems.append(control.StateSpace(A, B, C, D, name='Whipple',
                stateNames=stateNames, inputNames=inputNames,
                outputNames=outputNames))

    for A, B in zip(iAs, iBs):
        systems.append(control.StateSpace(A, B, C, D, name='Canon ID',
                stateNames=stateNames, inputNames=inputNames,
                outputNames=outputNames))

    C = np.zeros((1, 19))
    C[0, 3] = 1
    D = 0.
    indices = [20, 30, 58, 90]
    for A, B in zip(aAs[indices], aBs[indices]):
        systems.append(control.StateSpace(A, B[:, [0, 2]], C, D, name='Arms',
                inputNames=inputNames, outputNames=outputNames))

    w = np.logspace(-1, 2)
    linestyles = ['-', '--', '-.', ':'] * 3
    colors = ['k'] * len(speeds) + ['b'] * len(speeds) + ['r'] * len(speeds)
    bode = control.Bode(w, *tuple(systems), linestyles=linestyles, colors=colors)
    bode.plot()
    bode.figs[0].savefig(filename + '-Tphi.png')
    bode.figs[1].savefig(filename + '-Tdel.png')
    bode.figs[0].clf()
    bode.figs[1].clf()
# Eigenvalues versus speed plot.
v0 = 0.
vf = 10.
num = 100

# identified for all rider and all environments
iM, iC1, iK0, iK2, iH = idMat['A-A']
speeds, iAs, iBs = bicycle.benchmark_state_space_vs_speed(iM,
                                                          iC1,
                                                          iK0,
                                                          iK2,
                                                          v0=v0,
                                                          vf=vf,
                                                          num=num)
w, v = control.eig_of_series(iAs)
iEigenvalues, iEigenvectors = control.sort_modes(w, v)

# whipple model (mean)
wM, wC1, wK0, wK2, wH = cbi.mean_canon(allRiders, canon, H)
speeds, wAs, wBs = bicycle.benchmark_state_space_vs_speed(wM,
                                                          wC1,
                                                          wK0,
                                                          wK2,
                                                          v0=v0,
                                                          vf=vf,
                                                          num=num)
w, v = control.eig_of_series(wAs)
wEigenvalues, wEigenvectors = control.sort_modes(w, v)

# arm model (mean)
aAs, aBs, aSpeed = cbi.mean_arm(allRiders)
def plot(canon, H, riders, environments, idMats):
    filename = ''
    for rider in riders:
        filename += '-' + rider
    for env in environments:
        filename += '-' + env.replace(' ', '')

    filename = '../plots/' + filename[1:]

    print filename

    v0 = 0.
    vf = 10.
    num = 100

    # identified
    iM, iC1, iK0, iK2, iH = idMats
    speeds, iAs, iBs = bicycle.benchmark_state_space_vs_speed(iM, iC1, iK0, iK2,
            v0=v0, vf=vf, num=num)
    w, v = control.eigen_vs_parameter(iAs)
    iEigenvalues, iEigenvectors = control.sort_modes(w, v)

    # whipple model (mean)
    wM, wC1, wK0, wK2, wH = cbi.mean_canon(riders, canon, H)
    speeds, wAs, wBs = bicycle.benchmark_state_space_vs_speed(wM, wC1, wK0, wK2,
            v0=v0, vf=vf, num=num)
    w, v = control.eigen_vs_parameter(wAs)
    wEigenvalues, wEigenvectors = control.sort_modes(w, v)

    # arm model (mean)
    aAs, aBs, aSpeed = cbi.mean_arm(riders)
    indices = np.int32(np.round(speeds * 10))
    w, v = control.eigen_vs_parameter(aAs[indices])
    aEigenvalues, aEigenvectors = control.sort_modes(w, v)

    # eigenvalue plot
    rlfig = cbi.plot_rlocus_parts(speeds, iEigenvalues, wEigenvalues,
            aEigenvalues)
    rlfig.savefig(filename + '-eig.png')

    # root locus
    v0 = 0.
    vf = 10.
    num = 20
    speeds, iAs, iBs = bicycle.benchmark_state_space_vs_speed(iM, iC1, iK0, iK2,
            v0=v0, vf=vf, num=num)
    iEig, null = control.eigen_vs_parameter(iAs)

    speeds, wAs, wBs = bicycle.benchmark_state_space_vs_speed(wM, wC1, wK0, wK2,
            v0=v0, vf=vf, num=num)
    wEig, null = control.eigen_vs_parameter(wAs)

    indices = np.int32(np.round(speeds * 10))
    aEig, null = control.eigen_vs_parameter(aAs[indices])
    rlcfig = cbi.plot_rlocus(speeds, iEig, wEig, aEig)
    rlcfig.savefig(filename + '-rlocus.png')

    # bode plots
    speeds = np.array([2.0, 4.0, 6.0, 9.0])
    null, iAs, iBs = bicycle.benchmark_state_space_vs_speed(iM, iC1, iK0, iK2,
            speeds)
    null, wAs, wBs = bicycle.benchmark_state_space_vs_speed(wM, wC1, wK0, wK2,
            speeds)
    figs = cbi.plot_bode(speeds, iAs, iBs, wAs, wBs, aAs, aBs)
    figs[0].savefig(filename + '-Tphi.png')
    figs[1].savefig(filename + '-Tdel.png')
Example #4
0
    id_matrices = cPickle.load(f)


# Eigenvalues versus speed parameters.
v0 = 0.
vf = 10.
num = 100

# Load the identified model from data for rider L and in pavillion floor and
# generate the eigenvalues an eigenvectors as a function of speed.
iM, iC1, iK0, iK2, iH = id_matrices['L-P']
speeds, iAs, iBs = bicycle.benchmark_state_space_vs_speed(iM, iC1, iK0, iK2,
                                                          v0=v0, vf=vf,
                                                          num=num)
w, v = control.eig_of_series(iAs)
iEigenvalues, iEigenvectors = control.sort_modes(w, v)

# Load the Whipple model M, C1, K0, K2, H from first principles and generate
# the eigenvalues and eigenvectors as a function of speed.
wM, wC1, wK0, wK2 = cbi.load_benchmark_canon(['Luke'])['Luke']
wH = cbi.lateral_force_contribution(['Luke'])['Luke']
speeds, wAs, wBs = bicycle.benchmark_state_space_vs_speed(wM, wC1, wK0, wK2,
                                                          v0=v0, vf=vf,
                                                          num=num)
w, v = control.eig_of_series(wAs)
wEigenvalues, wEigenvectors = control.sort_modes(w, v)

# Load the Arm model state space for each rider from first principles and
# generate the eigenvalues and eigenvectors as a function of speed.
aAs, aBs, aSpeed = cbi.mean_arm(['Luke'])
indices = np.int32(np.round(speeds * 10))