Skip to content

Commit eaaccb1

Browse files
committed
many fixes
1 parent 5abb720 commit eaaccb1

File tree

10 files changed

+55
-25
lines changed

10 files changed

+55
-25
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ proj/secrets.py
77
vscode/*
88
vscode/
99
vscode
10+
.vscode
11+
.vscode/*
12+
.vscode/settings.json
13+
vscode/settings.json
1014

1115
# Byte-compiled / optimized / DLL files
1216
__pycache__/

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"python.pythonPath": "/Users/federicoclaudi/miniconda3/envs/dev/bin/python",
2+
"python.pythonPath": "C:\\Users\\Federico\\.conda\\envs\\dev\\python.exe",
33
"cSpell.enabled": true
44
}

proj/environment/manager.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,26 @@ def conclude(self):
158158
# Upload results to dropbox
159159
if self.winstor:
160160
self._upload_to_dropbox()
161+
162+
logging.info("Sending slack message")
163+
send_slack_message(
164+
f"""
165+
\n
166+
Completed simulation
167+
Start time: {self.simstart}
168+
End time: {timestamp()}
169+
Data folder: {self.datafolder}
170+
"""
171+
)
161172
else:
162173
logging.info("Did not upload to dropbox")
163174

175+
def failed(self):
164176
logging.info("Sending slack message")
165177
send_slack_message(
166178
f"""
167179
\n
168-
Completed simulation
180+
Failed simulation simulation
169181
Start time: {self.simstart}
170182
End time: {timestamp()}
171183
Data folder: {self.datafolder}

proj/environment/plotter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def _plot_xy(self, ax, curr_goals):
5454
curr_goals[:, 1],
5555
lw=10,
5656
color="r",
57+
alpha=0.5,
5758
zorder=-1,
5859
solid_capstyle="round",
5960
)
@@ -226,7 +227,7 @@ def _plot_cost(self, keep_s=1.2):
226227
if "total" not in k:
227228
n = len(v)
228229
if n > keep_n + 2:
229-
x = v[n - keep_n]
230+
x = v[n - keep_n :]
230231
else:
231232
x = v.copy()
232233

proj/environment/trajectories.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def compute_trajectory_stats(
111111

112112
if distance_travelled < min_dist_travelled:
113113
log.warning("Distance travelled below minimal requirement, erroring")
114-
raise ValueError("Distance travelled below minimal requirement")
114+
return None, None
115115

116116
return trajectory, duration
117117

@@ -223,9 +223,12 @@ def from_tracking(n_steps, params, planning_params, cache_fld, *args):
223223
vars = dict(x=x, y=y, angle=angle, speed=speed, ang_speed=ang_speed)
224224
if params["resample"]:
225225
for k, v in vars.items():
226-
vars[k] = _interpol(
227-
v[start:-1], params["max_deg_interpol"], n_steps
228-
)
226+
try:
227+
vars[k] = _interpol(
228+
v[start:-1], params["max_deg_interpol"], n_steps
229+
)
230+
except ValueError: # there were nans in the array
231+
return None, None
229232

230233
# stack
231234
trajectory = np.vstack(vars.values()).T

proj/environment/world.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ def initialize_world(self, trajectory):
124124
"""
125125
Create the world and the model at some location
126126
"""
127+
if trajectory is None:
128+
return
129+
127130
# create world
128131
self.world_size = self._initialize_world(trajectory)
129132

proj/model/config.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Config:
1212
STATE_SIZE = 5
1313
INPUT_SIZE = 2
1414

15-
R = np.diag([0.0001, 0.0001]) # control cost
15+
R = np.diag([0.1, 0.1]) # control cost
1616
Q = np.diag([5, 5, 1, 5, 0]) # state cost | x, y, theta, v, omega
1717
Sf = np.diag([0, 0, 0, 0, 0]) # final state cost
1818

@@ -25,25 +25,25 @@ class Config:
2525

2626
# ------------------------------- Mouse params ------------------------------- #
2727
# ? works
28-
# mouse = dict(
29-
# L = 1.5, # half body width | cm
30-
# R = 1, # radius of wheels | cm
31-
# d = 0.1, # distance between axel and CoM | cm
32-
# length = 3, # cm
33-
# m = round(20 / 9.81, 2), # mass | g
34-
# m_w = round(2 / 9.81, 2), # mass of wheels/legs |g
35-
# )
36-
37-
# ? more realistic
3828
mouse = dict(
39-
L=2, # half body width | cm
40-
R=2, # radius of wheels | cm
41-
d=3, # distance between axel and CoM | cm
42-
length=8.6, # cm
43-
m=round(25 / 9.81, 2), # mass | g
44-
m_w=round(0.6 / 9.81, 2), # mass of wheels/legs |g
29+
L=1.5, # half body width | cm
30+
R=1, # radius of wheels | cm
31+
d=0.1, # distance between axel and CoM | cm
32+
length=3, # cm
33+
m=round(20 / 9.81, 2), # mass | g
34+
m_w=round(2 / 9.81, 2), # mass of wheels/legs |g
4535
)
4636

37+
# ? more realistic
38+
# mouse = dict(
39+
# L=2, # half body width | cm
40+
# R=2, # radius of wheels | cm
41+
# d=3, # distance between axel and CoM | cm
42+
# length=8.6, # cm
43+
# m=round(25 / 9.81, 2), # mass | g
44+
# m_w=round(0.6 / 9.81, 2), # mass of wheels/legs |g
45+
# )
46+
4747
# ------------------------------ Goal trajectory ----------------------------- #
4848

4949
trajectory = dict( # parameters of the goals trajectory
@@ -53,7 +53,7 @@ class Config:
5353
max_speed=100,
5454
min_speed=80,
5555
min_dist=5, # if agent is within this distance from trajectory end the goal is considered achieved
56-
dist_th=300, # keep frames only after moved away from start location
56+
dist_th=60, # keep frames only after moved away from start location
5757
resample=True, # if True when using tracking trajectory resamples it
5858
max_deg_interpol=8, # if using track fit a N degree polynomial to daa to smoothen
5959
randomize=True, # if true when using tracking it pulls a random trial

proj/run/runner.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ def run_experiment(
5757

5858
# reset things
5959
trajectory = environment.reset()
60+
if trajectory is None:
61+
log.info("Failed to get a valid trajectory")
62+
environment.failed()
63+
return
64+
6065
model.reset()
6166

6267
# Get number of steps

proj/utils/dropbox.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def _fix_path(self, path):
4444

4545
def _check_path(self, path):
4646
path = str(path)
47+
path = path.replace("\\", "/")
4748
if path[0] != "/":
4849
return "/" + path
4950
else:

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"rich",
1717
"sklearn",
1818
"fancylog",
19+
"slackclient",
1920
"dropbox",
2021
]
2122

0 commit comments

Comments
 (0)