Skip to content

Commit df67d71

Browse files
committed
cost fix
1 parent 64a06f9 commit df67d71

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

proj/control/control.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ def __init__(self, model):
1818
self.R = model.R
1919
self.Sf = model.Sf
2020

21+
self.angle_idx = model.ANGLE_IDX
22+
2123
# Params
2224
self.max_iter = model.iLQR["max_iter"]
2325
self.init_mu = model.iLQR["init_mu"]

proj/control/cost.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44

55
class Cost:
6-
@staticmethod
7-
def fit_diff_in_range(diff_x):
6+
def fit_diff_in_range(self, diff_x):
87
""" fit difference state in range(angle)
98
109
Args:
@@ -17,11 +16,15 @@ def fit_diff_in_range(diff_x):
1716
"""
1817

1918
if len(diff_x.shape) == 3:
20-
diff_x[:, :, -2] = fit_angle_in_range(diff_x[:, :, -2])
19+
diff_x[:, :, self.angle_idx] = fit_angle_in_range(
20+
diff_x[:, :, self.angle_idx]
21+
)
2122
elif len(diff_x.shape) == 2:
22-
diff_x[:, -2] = fit_angle_in_range(diff_x[:, -2])
23+
diff_x[:, self.angle_idx] = fit_angle_in_range(
24+
diff_x[:, self.angle_idx]
25+
)
2326
elif len(diff_x.shape) == 1:
24-
diff_x[-2] = fit_angle_in_range(diff_x[-2])
27+
diff_x[self.angle_idx] = fit_angle_in_range(diff_x[self.angle_idx])
2528

2629
return diff_x
2730

@@ -53,7 +56,7 @@ def state_cost_fn(self, x, g_x):
5356
"""
5457
diff = self.fit_diff_in_range(x - g_x)
5558
# diff = x - g_x
56-
return ((diff) ** 2) * np.diag(self.Q)
59+
return (diff ** 2) * np.diag(self.Q)
5760

5861
def terminal_state_cost_fn(self, terminal_x, terminal_g_x):
5962
"""

proj/model/config.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ class Config:
77
SPAWN_TYPE = "trajectory"
88

99
# ----------------------------- Simulation params ---------------------------- #
10-
dt = 0.01
10+
dt = 0.005
1111

1212
# -------------------------------- Cost params ------------------------------- #
1313
STATE_SIZE = 5
1414
INPUT_SIZE = 2
15+
ANGLE_IDX = 2 # state vector index which is angle, used to fit diff in
1516

16-
R = np.diag([0.1, 0.1]) # control cost
17-
Q = np.diag([5, 5, 1, 5, 0]) # state cost | x, y, theta, v, omega
17+
R = np.diag([0.01, 0.01]) # control cost
18+
Q = np.diag([1, 1, 1, 5, 0]) # state cost | x, y, theta, v, omega
1819
Sf = np.diag([0, 0, 0, 0, 0]) # final state cost
1920

2021
# STATE_SIZE = 4
@@ -64,7 +65,7 @@ class Config:
6465

6566
# ------------------------------ Planning params ----------------------------- #
6667
planning = dict( # params used to compute goal states to be used for control
67-
prediction_length=80,
68+
prediction_length=150,
6869
n_ahead=5, # start prediction states from N steps ahead
6970
)
7071

proj/run/runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def run_experiment(
9898
environment.itern = itern
9999
environment.update_world(g_xs, elapsed=itern * model.dt)
100100

101-
# log status once a second
101+
# log status once a (simulation) second
102102
if itern % int(1 / model.dt) == 0:
103103
log.info(
104104
f"Iteration {itern}/{n_steps}. Current cost: {environment.curr_cost}."

0 commit comments

Comments
 (0)