|
| 1 | +import numpy as np |
| 2 | + |
| 3 | +# ------------------------------- Model specific params ------------------------------ # |
| 4 | +_cart_params = dict( |
| 5 | + STATE_SIZE=5, |
| 6 | + INPUT_SIZE=2, |
| 7 | + ANGLE_IDX=2, # state vector index which is angle, used to fit diff in |
| 8 | + R=np.diag([0.0001, 0.00001]), # control cost |
| 9 | + Q=np.diag([30, 30, 30, 1, 0]), # state cost | x, y, theta, v, omega |
| 10 | + Sf=np.diag([0, 0, 0, 0, 0]), # final state cost |
| 11 | +) |
| 12 | + |
| 13 | +_polar_params = dict( |
| 14 | + STATE_SIZE=4, |
| 15 | + INPUT_SIZE=2, |
| 16 | + ANGLE_IDX=2, # state vector index which is angle, used to fit diff in |
| 17 | + R=np.diag([0.05, 0.05]), # control cost |
| 18 | + Q=np.diag([2.5, 2.5, 0, 0]), # state cost | r, omega, v, omega |
| 19 | + Sf=np.diag([2.5, 2.5, 0, 0]), # final state cost |
| 20 | +) |
| 21 | + |
| 22 | +# -------------------------------- Mouse types ------------------------------- # |
| 23 | + |
| 24 | +_easy_mouse = dict( |
| 25 | + L=1.5, # half body width | cm |
| 26 | + R=1, # radius of wheels | cm |
| 27 | + d=0.1, # distance between axel and CoM | cm |
| 28 | + length=3, # cm |
| 29 | + m=round(20 / 9.81, 2), # mass | g |
| 30 | + m_w=round(2 / 9.81, 2), # mass of wheels/legs |g |
| 31 | + mouse_type="easy", |
| 32 | +) |
| 33 | + |
| 34 | +_realistic_mouse = dict( |
| 35 | + L=2, # half body width | cm |
| 36 | + R=1.5, # radius of wheels | cm |
| 37 | + d=2, # distance between axel and CoM | cm |
| 38 | + length=1, # 8.6, # cm |
| 39 | + m=round(23 / 9.81, 2), # mass | g |
| 40 | + m_w=0.8, # mass of wheels/legs |g |
| 41 | + mouse_type="realistic", |
| 42 | +) |
| 43 | + |
| 44 | +# ---------------------------------------------------------------------------- # |
| 45 | +# CONFIG # |
| 46 | +# ---------------------------------------------------------------------------- # |
| 47 | + |
| 48 | + |
| 49 | +class Config: |
| 50 | + # ----------------------------- Simulation params ---------------------------- # |
| 51 | + SIMULATION_NAME = "even_moreR_moreQ" |
| 52 | + |
| 53 | + USE_FAST = True # if true use cumba's methods |
| 54 | + SPAWN_TYPE = "trajectory" |
| 55 | + LIVE_PLOT = False |
| 56 | + |
| 57 | + mouse_type = "realistic" |
| 58 | + model_type = "cart" |
| 59 | + |
| 60 | + dt = 0.005 |
| 61 | + |
| 62 | + # ------------------------------ Goal trajectory ----------------------------- # |
| 63 | + |
| 64 | + trajectory = dict( # parameters of the goals trajectory |
| 65 | + name="tracking", |
| 66 | + # ? For artificial trajectories |
| 67 | + nsteps=1000, |
| 68 | + distance=150, |
| 69 | + max_speed=100, |
| 70 | + min_speed=80, |
| 71 | + min_dist=0, # if agent is within this distance from trajectory end the goal is considered achieved |
| 72 | + # ? for trajectories from data |
| 73 | + px_to_cm=1, # 1 / 8, # convert px values to cm |
| 74 | + # dist_th=60, # keep frames only after moved away from start location |
| 75 | + dist_th=50, |
| 76 | + resample=True, # if True when using tracking trajectory resamples it |
| 77 | + max_deg_interpol=8, # if using track fit a N degree polynomial to daa to smoothen |
| 78 | + randomize=True, # if true when using tracking it pulls a random trial |
| 79 | + ) |
| 80 | + |
| 81 | + # ------------------------------ Planning params ----------------------------- # |
| 82 | + planning = dict( # params used to compute goal states to be used for control |
| 83 | + prediction_length=80, |
| 84 | + n_ahead=5, # start prediction states from N steps ahead |
| 85 | + ) |
| 86 | + |
| 87 | + # --------------------------------- Plotting --------------------------------- # |
| 88 | + traj_plot_every = 15 |
| 89 | + |
| 90 | + # ------------------------------ Control params ------------------------------ # |
| 91 | + iLQR = dict( |
| 92 | + max_iter=500, |
| 93 | + init_mu=1.0, |
| 94 | + mu_min=1e-6, |
| 95 | + mu_max=1e10, |
| 96 | + init_delta=2.0, |
| 97 | + threshold=1e-6, |
| 98 | + ) |
| 99 | + |
| 100 | + def __init__(self,): |
| 101 | + # get mouse params |
| 102 | + self.mouse = ( |
| 103 | + _easy_mouse if self.mouse_type == "easy" else _realistic_mouse |
| 104 | + ) |
| 105 | + |
| 106 | + # set model params |
| 107 | + if self.model_type == "cart": |
| 108 | + params = _cart_params |
| 109 | + else: |
| 110 | + params = _polar_params |
| 111 | + |
| 112 | + self.STATE_SIZE = params["STATE_SIZE"] |
| 113 | + self.INPUT_SIZE = params["INPUT_SIZE"] |
| 114 | + self.ANGLE_IDX = params["ANGLE_IDX"] |
| 115 | + self.R = params["R"] |
| 116 | + self.Q = params["Q"] |
| 117 | + self.Sf = params["Sf"] |
| 118 | + |
| 119 | + # Adjust mouse length for plotting |
| 120 | + self.mouse["length"] = ( |
| 121 | + self.mouse["length"] * self.trajectory["px_to_cm"] |
| 122 | + ) |
| 123 | + |
| 124 | + def config_dict(self): |
| 125 | + return dict( |
| 126 | + dt=self.dt, |
| 127 | + STATE_SIZE=self.STATE_SIZE, |
| 128 | + INPUT_SIZE=self.INPUT_SIZE, |
| 129 | + R=list(np.diag(self.R).tolist()), |
| 130 | + Q=list(np.diag(self.Q).tolist()), |
| 131 | + Sf=list(np.diag(self.Sf).tolist()), |
| 132 | + mouse=self.mouse, |
| 133 | + trajectory=self.trajectory, |
| 134 | + planning=self.planning, |
| 135 | + iLQR=self.iLQR, |
| 136 | + ) |
0 commit comments