Skip to content

Commit 5e5168c

Browse files
committed
Add video_record script for Cassie hardware experiment (not tested)
1 parent b9b3420 commit 5e5168c

File tree

4 files changed

+100
-2
lines changed

4 files changed

+100
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ fort.*
1313
.vscode
1414
*.csv
1515
/examples/Cassie/saved_trajectories/
16+
*.mp4

examples/Cassie/start_logging.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import subprocess
2+
import os
3+
import glob
4+
import codecs
5+
from datetime import date
6+
7+
8+
def main():
9+
sim = (os.getlogin() == 'brian')
10+
curr_date = date.today().strftime("%m_%d_%y")
11+
year = date.today().strftime("%Y")
12+
13+
logdir = \
14+
f"{os.getenv('HOME')}/workspace/logs/cassie_simulation/{year}/{curr_date}" \
15+
if sim else f"{os.getenv('HOME')}/logs/{year}/{curr_date}"
16+
17+
current_dair_dir = f"{os.getcwd()}/"
18+
standing_gains = current_dair_dir + "examples/Cassie/osc/osc_standing_gains.yaml"
19+
walking_gains = current_dair_dir + "examples/Cassie/osc/osc_walking_gains.yaml"
20+
alip_gains = current_dair_dir + "examples/Cassie/osc/osc_walking_gains_alip.yaml"
21+
22+
if not os.path.isdir(logdir):
23+
os.mkdir(logdir)
24+
25+
git_diff = subprocess.check_output(['git', 'diff'], cwd=current_dair_dir)
26+
commit_tag = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=current_dair_dir)
27+
28+
os.chdir(logdir)
29+
current_logs = sorted(glob.glob('lcmlog-*'))
30+
if current_logs:
31+
last_log = int(current_logs[-1].split('-')[-1])
32+
log_num = f'{last_log+1:02}'
33+
else:
34+
log_num = '00'
35+
36+
with open('commit_tag%s' % log_num, 'w') as f:
37+
f.write(str(commit_tag))
38+
f.write("\n\ngit diff:\n\n")
39+
f.write(codecs.getdecoder("unicode_escape")(git_diff)[0])
40+
41+
subprocess.run(['cp', standing_gains, 'standing_gains_%s.yaml' % log_num])
42+
subprocess.run(['cp', walking_gains, 'walking_gains_%s.yaml' % log_num])
43+
subprocess.run(['cp', alip_gains, 'walking_gains_alip%s.yaml' % log_num])
44+
subprocess.run(['lcm-logger', '-f', 'lcmlog-%s' % log_num])
45+
46+
47+
if __name__ == '__main__':
48+
main()

examples/goldilocks_models/procman_scripts/hardware_cassie_controller.pmd

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,14 @@ group "4.lcm-tools" {
8585
exec = "bazel-bin/lcmtypes/dair-lcm-spy";
8686
host = "localhost";
8787
}
88-
cmd "2. lcm-logger" {
89-
exec = "lcm-logger -f /home/yuming/Desktop/temp/log";
88+
cmd "record_video" {
89+
exec = "python3 record_video.py";
9090
host = "localhost";
9191
}
92+
cmd "0.cassie-lcm-logger" {
93+
exec = "python3 examples/Cassie/start_logging.py";
94+
host = "dair-cassie";
95+
}
9296
}
9397

9498
group "1.rom-space-controller (wired ethernet)" {
@@ -206,3 +210,12 @@ script "switch to walking" {
206210
wait ms 1000;
207211
stop cmd "3.standing-controller-real-robot";
208212
}
213+
214+
script "switch to walking start logging" {
215+
start cmd "0.cassie-lcm-logger";
216+
start cmd "record_video";
217+
wait ms 100;
218+
start cmd "3.0.switch-to-rom-mpc";
219+
wait ms 1000;
220+
stop cmd "3.standing-controller-real-robot";
221+
}

record_video.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import subprocess
2+
import sys
3+
import os
4+
import glob
5+
from datetime import date
6+
def main():
7+
curr_date = date.today().strftime("%m_%d_%y")
8+
year = date.today().strftime("%Y")
9+
logdir = f"{os.getenv('HOME')}/Videos/cassie_experiments/{year}/{curr_date}/"
10+
11+
12+
current_logs = sorted(glob.glob(logdir + 'log_*'))
13+
if current_logs:
14+
last_log = int(current_logs[-1].split('_')[-1].split('.')[0])
15+
log_num = f'{last_log+1:02}'
16+
else:
17+
log_num = '00'
18+
print(log_num)
19+
print(current_logs)
20+
experiment_name = logdir + 'log_' + log_num + '.mp4'
21+
cmd = 'v4l2-ctl --list-devices'.split(' ')
22+
process = subprocess.check_output(cmd)
23+
lines = process.decode("utf-8").split('\n')
24+
dev_name = ''
25+
for i, line in enumerate(lines):
26+
if 'HD' in line:
27+
dev_name = lines[i+1].split('\t')[1]
28+
print(dev_name)
29+
cmds = ('ffmpeg -y -f alsa -i default -i ' + dev_name + ' -vcodec libx264 -acodec aac -qp 0').split(' ')
30+
cmds.append(experiment_name)
31+
print(cmds)
32+
# import pdb; pdb.set_trace()
33+
subprocess.run(cmds)
34+
35+
if __name__ == '__main__':
36+
main()

0 commit comments

Comments
 (0)