def drawDF(df, x, columns, colors=None, axes=None):
    from collections import Counter
    if axes is not None:
        num_axes = Counter(axes)
        nrows = max(num_axes.values())
        ncols = len(num_axes.keys())
    X = df[x]
    ax1 = None
    if colors is None: colors = color_grad(len(columns))
    for i, k in enumerate(columns):
        if axes is None:
            plt.plot(X, df[k], label=k, color=colors[i])
        else:
            ax = plt.subplot(nrows,
                             ncols,
                             ncols * (i % nrows) + axes[i],
                             sharex=ax1)
            ax.plot(X, df[k], label=k, color=colors[i])
            plt.ylabel(k)
            if ax1 is None: ax1 = ax
        plt.minorticks_on()
        plt.grid(b=False, which='major', axis='x', color='b', linestyle='-')
        plt.grid(b=False,
                 which='minor',
                 axis='x',
                 color='0.15',
                 linestyle='--')
        plt.grid(b=False, which='major', axis='y', color='b', linestyle='-')
        #     plt.legend(bbox_to_anchor=(1.01, 1), loc=2, borderaxespad=0.0)
    plt_show_maxed()
 def simAngle(eng, mass, TT, error_rate, error_time, errors):
     if error_rate > 0:
         Sandbox.analyze_results(1, 1, *[simTurnTime(0, mass, eng, tt, error_rate, error_time) for tt in TT])
     else:
         cols = len(errors)
         for c, error in enumerate(errors):
             Sandbox.analyze_results(cols, c + 1, *[simTurnTime(error, mass, eng, tt) for tt in TT])
     fig = plt.gcf()
     fig.canvas.set_window_title(datetime.strftime(datetime.now(), '%H:%M:%S'))
     plt_show_maxed()
 def simAngle(eng, AA, base_thrust, wheels_ratio, error_rate, error_time, angles):
     if error_rate > 0:
         ATC.analyze_results(1, 1, *[simAA(0, aa, eng, base_thrust, wheels_ratio, error_rate, error_time) for aa in AA])
     else:
         cols = len(angles)
         for c, ang in enumerate(angles):
             ATC.analyze_results(cols, c + 1, *[simAA(ang, aa, eng, base_thrust, wheels_ratio) for aa in AA])
     fig = plt.gcf()
     fig.canvas.set_window_title(datetime.strftime(datetime.now(), '%H:%M:%S'))
     plt_show_maxed()
 def simAngle(AAs, error_rate, error_time, angles):
     if error_rate > 0:
         BRC.analyze_results(1, 1,
                             *[simAA(0, aa, error_rate, error_time) for aa in AAs])
     else:
         cols = len(angles)
         for c, ang in enumerate(angles):
             BRC.analyze_results(cols, c + 1, *[simAA(ang, aa) for aa in AAs])
     fig = plt.gcf()
     fig.canvas.set_window_title(datetime.strftime(datetime.now(), '%H:%M:%S'))
     plt_show_maxed()
 def timelines(t, *lines):
     n = len(lines)
     ax1 = None
     for i, line in enumerate(lines):
         ax = plt.subplot(n, 1, i + 1, sharex=ax1)
         plt.plot(t, line)
         plt.grid(b=False, which='major', axis='x', color='g', linestyle='-')
         plt.grid(b=False, which='minor', axis='x', color='0.15', linestyle='--')
         plt.grid(b=False, which='major', axis='y', color='g', linestyle='-')
         if ax1 is None:
             ax1 = ax
     plt_show_maxed()
 def simAngle(AAs, error_rate, error_time, angles):
     if error_rate > 0:
         BRC.analyze_results(
             1, 1, *[simAA(0, aa, error_rate, error_time) for aa in AAs])
     else:
         cols = len(angles)
         for c, ang in enumerate(angles):
             BRC.analyze_results(cols, c + 1,
                                 *[simAA(ang, aa) for aa in AAs])
     fig = plt.gcf()
     fig.canvas.set_window_title(
         datetime.strftime(datetime.now(), '%H:%M:%S'))
     plt_show_maxed()
Exemple #7
0
def sim_PointNav():
    P = 2
    D = 0.1
    AAk = 0.5
    pid = PID(P, 0, D, 0, 10)
    accel = np.arange(0.1, 1.1, 0.1)
    distance = 500
    distanceF = 0.1
    cols = color_grad(len(accel))
    for i, a in enumerate(accel):
        d = [distance]
        v = [0]
        act = [0]
        t = 0
        A = [0]
        while d[-1] > 0:
            pid.kp = P * a / clampL(v[-1], 0.01)
            act.append(pid.update(d[-1] * distanceF))
            aa = a * AAk

            if v[-1] < pid.action:
                if A[-1] < a: A.append(A[-1] + a * AAk * dt)
                else: A.append(a)
            elif v[-1] > pid.action:
                if A[-1] > -a: A.append(A[-1] - a * AAk * dt)
                else: A.append(-a)
            elif A[-1] > 0: A.append(A[-1] - a * AAk * dt)
            elif A[-1] < 0: A.append(A[-1] + a * AAk * dt)
            else: A.append(0)
            #             print 'd=% 8.4f, v=% 8.4f, act=% 8.4f, A=% 8.4f' % (d[-1], v[-1], act[-1], A[-1])
            v.append(v[-1] + A[-1] * dt)
            d.append(d[-1] - v[-1] * dt)
            t += dt
        print 'accel=%.2f, time: %.1fs' % (a, t)
        print len(d), len(A)
        plt.subplot(3, 1, 1)
        plt.plot(d, v, color=cols[i], label="accel=%.2f" % a)
        plt.ylabel("V")
        plt.xlabel("distance")
        plt.subplot(3, 1, 2)
        plt.plot(d, act, color=cols[i], label="accel=%.2f" % a)
        plt.ylabel("act")
        plt.xlabel("distance")
        plt.subplot(3, 1, 3)
        plt.plot(d, A, color=cols[i], label="accel=%.2f" % a)
        plt.ylabel("real accel");
        plt.xlabel("distance")
    plt.legend()
    plt_show_maxed()
Exemple #8
0
 def simAngle(eng, mass, TT, error_rate, error_time, errors):
     if error_rate > 0:
         Sandbox.analyze_results(
             1, 1, *[
                 simTurnTime(0, mass, eng, tt, error_rate, error_time)
                 for tt in TT
             ])
     else:
         cols = len(errors)
         for c, error in enumerate(errors):
             Sandbox.analyze_results(
                 cols, c + 1,
                 *[simTurnTime(error, mass, eng, tt) for tt in TT])
     fig = plt.gcf()
     fig.canvas.set_window_title(
         datetime.strftime(datetime.now(), '%H:%M:%S'))
     plt_show_maxed()
 def simAngle(eng, AA, base_thrust, wheels_ratio, error_rate, angles):
     cols = 1 if error_rate > 0 else len(angles)
     if error_rate > 0:
         ATC.analyze_results(
             cols, 1, *[
                 simAA(0, aa, eng, base_thrust, wheels_ratio, error_rate)
                 for aa in AA
             ])
     else:
         for c, ang in enumerate(angles):
             ATC.analyze_results(
                 cols, c + 1, *[
                     simAA(ang, aa, eng, base_thrust, wheels_ratio)
                     for aa in AA
                 ])
     fig = plt.gcf()
     fig.canvas.set_window_title(
         datetime.strftime(datetime.now(), '%H:%M:%S'))
     plt_show_maxed()
Exemple #10
0
def sim_Altitude():
    #     vs = loadCSV('VS-filtering-26.csv', ('AbsAlt', 'TerAlt', 'Alt', 'AltAhead', 'Err', 'VSP', 'aV', 'rV', 'dV'))
    # #     ter = vs.TerAlt[-10:10:-1]
    #     vs = vs[vs.Alt > 3]
    #     ter = vs.TerAlt[17000:22000]

    sim1 = VSF_sim(AS=0.12, DS=0.5)
    sim1.t1 = 60.0
    thrust = [100]  # np.arange(100, 300, 50)

    def run_sim(c, n, A, sA, pid):
        for t in thrust:
            sim1.run_alt(A, sA, thrust=t, pid=pid)
            i = 0;
            r = 7
            sim1.plot_alt(r, c, c * i + n)
            i += 1
            sim1.plot_ter(r, c, c * i + n)
            i += 1
            sim1.plot_ralt(r, c, c * i + n)
            i += 1
            sim1.plot_vs(r, c, c * i + n)
            i += 1
            sim1.plot_vsp(r, c, c * i + n)
            i += 1
            sim1.plot_dvsp(r, c, c * i + n)
            i += 1
            sim1.plot_k(r, c, c * i + n)
            i += 1
            sim1.describe()
        #     run_sim(2,1, 100.0, pid)

    run_sim(2, 1, 50.0, 0.0, PID2(0.3, 0.0, 0.3, -9.9, 9.9))
    run_sim(2, 2, 50.0, 105.0, PID2(0.3, 0.0, 0.3, -9.9, 9.9))
    #    run_sim(4,3, -alt/10.0, pid)
    #    run_sim(4,4, -alt, pid)
    sim1.legend()
    plt_show_maxed()
def drawDF(df, x, columns, colors=None, axes=None):
    from collections import Counter
    if axes is not None:
        num_axes = Counter(axes)
        nrows = max(num_axes.values())
        ncols = len(num_axes.keys())
    X = df[x]
    ax1 = None
    if colors is None: colors = color_grad(len(columns))
    for i, k in enumerate(columns):
        if axes is None:
            plt.plot(X, df[k], label=k, color=colors[i])
        else:
            ax = plt.subplot(nrows, ncols, ncols * (i % nrows) + axes[i], sharex=ax1)
            ax.plot(X, df[k], label=k, color=colors[i])
            plt.ylabel(k)
            if ax1 is None: ax1 = ax
        plt.minorticks_on()
        plt.grid(b=False, which='major', axis='x', color='b', linestyle='-')
        plt.grid(b=False, which='minor', axis='x', color='0.15', linestyle='--')
        plt.grid(b=False, which='major', axis='y', color='b', linestyle='-')
        #     plt.legend(bbox_to_anchor=(1.01, 1), loc=2, borderaxespad=0.0)
    plt_show_maxed()
 def timelines(t, *lines):
     n = len(lines)
     ax1 = None
     for i, line in enumerate(lines):
         ax = plt.subplot(n, 1, i + 1, sharex=ax1)
         plt.plot(t, line)
         plt.grid(b=False,
                  which='major',
                  axis='x',
                  color='g',
                  linestyle='-')
         plt.grid(b=False,
                  which='minor',
                  axis='x',
                  color='0.15',
                  linestyle='--')
         plt.grid(b=False,
                  which='major',
                  axis='y',
                  color='g',
                  linestyle='-')
         if ax1 is None:
             ax1 = ax
     plt_show_maxed()
Exemple #13
0
        vy = [start_vel * np.sin(start_angle)]
        a = [start_angle]
        t = [0]
        m = self.M
        while a[-1] > end_angle:
            accel = self.T / m
            thrust_angle = a[-1] - self.a
            ax = accel * np.cos(thrust_angle)
            ay = accel * np.sin(thrust_angle) - self.G
            m -= self.mflow * dt
            vx.append(vx[-1] + ax * dt)
            vy.append(vy[-1] + ay * dt)
            x.append(x[-1] + vx[-1] * dt)
            y.append(y[-1] + vy[-1] * dt)
            a.append(np.arctan2(vy[-1], vx[-1]))
            t.append(t[-1] + dt)
            print(t[-1], vx[-1], vy[-1],
                  np.sqrt(vx[-1] * vx[-1] + vy[-1] * vy[-1]))
        return t, a, x, y, vx, vy


if __name__ == '__main__':
    import matplotlib.pyplot as plt

    sim = GTurn(2, 15, 0.01, 5)
    t, a, x, y, vx, vy = sim.simulate(50, 90, 30)
    a = np.rad2deg(a)
    plt.plot(t, a)
    plt.quiver(t, a, vx, vy, units='xy', width=0.02, angles='xy')
    plt_show_maxed()
        vx = [start_vel * np.cos(start_angle)]
        vy = [start_vel * np.sin(start_angle)]
        a = [start_angle]
        t = [0]
        m = self.M
        while a[-1] > end_angle:
            accel = self.T / m
            thrust_angle = a[-1] - self.a
            ax = accel * np.cos(thrust_angle)
            ay = accel * np.sin(thrust_angle) - self.G
            m -= self.mflow * dt
            vx.append(vx[-1] + ax * dt)
            vy.append(vy[-1] + ay * dt)
            x.append(x[-1] + vx[-1] * dt)
            y.append(y[-1] + vy[-1] * dt)
            a.append(np.arctan2(vy[-1], vx[-1]))
            t.append(t[-1] + dt)
            print(t[-1], vx[-1], vy[-1], np.sqrt(vx[-1] * vx[-1] + vy[-1] * vy[-1]))
        return t, a, x, y, vx, vy


if __name__ == '__main__':
    import matplotlib.pyplot as plt

    sim = GTurn(2, 15, 0.01, 5)
    t, a, x, y, vx, vy = sim.simulate(50, 90, 30)
    a = np.rad2deg(a)
    plt.plot(t, a)
    plt.quiver(t, a, vx, vy, units='xy', width=0.02, angles='xy')
    plt_show_maxed()
def boxplot(df, columns=None):
    cnames = df.keys() if columns is None else columns
    plt.boxplot([df[k] for k in cnames], labels=cnames)
    plt_show_maxed()
def boxplot(df, columns=None):
    cnames = df.keys() if columns is None else columns
    plt.boxplot([df[k] for k in cnames], labels=cnames)
    plt_show_maxed()