예제 #1
0
        def __init__(self):
            super().__init__(**vars(cfg.env_kwargs))
            wingrock.load_config()
            self.x = wingrock.System()
            self.x.unc = lambda t, x: 0

            self.A = wingrock.cfg.Am
            self.B = wingrock.cfg.B
            self.Kopt, self.Popt = LQR.clqr(self.A, self.B, cfg.Q, cfg.R)
            self.behave_K, _ = LQR.clqr(self.A - 3, self.B, cfg.Qb, cfg.Rb)

            self.logger = fym.logging.Logger(Path(cfg.dir, "env.h5"))
            self.logger.set_info(cfg=cfg)
예제 #2
0
def exp1():
    basedir = Path("data/exp1")

    cfg = wingrock.cfg

    wingrock.load_config()
    cfg.dir = Path(basedir, "data00")
    cfg.label = "MRAC"
    run_simple(wingrock.MRACEnv())

    wingrock.load_config()
    cfg.dir = Path(basedir, "data01")
    cfg.label = "HMRAC"
    run_simple(wingrock.HMRACEnv())
예제 #3
0
def exp3():
    basedir = Path("data/exp3")

    cfg = wingrock.cfg

    # wingrock.load_config()
    # cfg.dir = Path(basedir, "data00")
    # cfg.label = "MRAC"
    # run_simple(wingrock.MRACEnv())

    wingrock.load_config()
    cfg.dir = Path(basedir, "data01")
    cfg.label = "Value Learner"
    cfg.R = np.zeros((1, 1))
    run_with_agent(wingrock.ValueLearnerEnv(), wingrock.ValueLearnerAgent())

    wingrock.load_config()
    cfg.dir = Path(basedir, "data01")
    cfg.label = "Value Learner"
    cfg.R = np.zeros((1, 1))
    run_with_agent(wingrock.ValueLearnerEnv(), wingrock.ValueLearnerAgent())
예제 #4
0
def exp3_plot():
    def get_data(datadir):
        data = SN()
        env, info = fym.logging.load(list(datadir.glob("*env.h5"))[0],
                                     with_info=True)
        data.env = env
        data.info = info
        agentlist = list(datadir.glob("*agent.h5"))
        if agentlist != []:
            data.agent = fym.logging.load(agentlist[0])
        data.style = dict(label=info["cfg"].label)
        return data

    plt.rc("font", family="Times New Roman")
    plt.rc("text", usetex=True)
    plt.rc("lines", linewidth=1)
    plt.rc("axes", grid=True)
    plt.rc("grid", linestyle="--", alpha=0.8)

    datadir = Path("data", "exp3")
    mrac = get_data(Path(datadir, "data00"))
    vlmrac = get_data(Path(datadir, "data01"))
    data = [mrac, vlmrac]

    basestyle = dict(c="k", lw=0.7)
    cmdstyle = dict(basestyle, c="r", ls="--", label="Command")
    mrac.style.update(basestyle, c="g", ls="-")
    vlmrac.style.update(basestyle, c="b", ls="-")

    # Figure common setup
    cfg = wingrock.cfg
    wingrock.load_config()
    t_range = (0, cfg.final_time)

    # All in inches
    subsize = (4.05, 0.946)
    width = 4.94
    top = 0.2
    bottom = 0.671765
    left = 0.5487688
    hspace = 0.2716

    # =================
    # States and inputs
    # =================
    figsize, pos = plot.posing(3, subsize, width, top, bottom, left, hspace)

    plt.figure(figsize=figsize)

    ax = plt.subplot(311, position=pos[0])
    lines = []
    lines += plt.plot(mrac.env["t"], mrac.env["c"][:, 0], **cmdstyle)
    lines += [plot.states_and_input(d, "x", 0)[0] for d in data]
    plt.ylabel(r"$x_1$")
    plt.ylim(-2, 2)
    plt.figlegend(
        lines,
        [line.get_label() for line in lines],
        bbox_to_anchor=(0.99, 0.78)
    )

    plt.subplot(312, sharex=ax, position=pos[1])
    [plot.states_and_input(d, "x", 1) for d in data]
    plt.ylabel(r"$x_2$")
    plt.ylim(-2, 2)

    plt.subplot(313, sharex=ax, position=pos[2])
    [plot.states_and_input(d, "u", 0) for d in data]
    plt.ylabel(r'$u$')
    plt.ylim(-80, 80)
    plt.xlabel("Time, sec")
    plt.xlim(t_range)

    for ax in plt.gcf().get_axes():
        ax.label_outer()

    # ====================
    # Parameter estimation
    # ====================
    figsize, pos = plot.posing(2, subsize, width, top, bottom, left, hspace)
    plt.figure(figsize=figsize)

    ax = plot.subplot(pos, 0)
    plot.all(mrac, "Wcirc", style=cmdstyle)
    plot.all(mrac, "W", style=dict(mrac.style, c="k"))
    plt.ylim(-70, 30)

    plot.subplot(pos, 1, sharex=ax)
    plot.all(mrac, "Wcirc", style=cmdstyle)
    plot.all(vlmrac, "W", style=dict(mrac.style, c="k"))
    plot.all(vlmrac, "F", style=dict(mrac.style, c="b"))
    plot.all(vlmrac, "What", is_agent=True, style=dict(mrac.style, c="g"))
    plt.ylim(-70, 30)

    plt.xlabel("Time, sec")
    plt.xlim(t_range)

    plt.show()