File size: 4,064 Bytes
05f9189
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
"""Export the ultra-simple Electric Slide count map and 50 Hz joint references."""

from __future__ import annotations

import argparse
import csv
import json
import math
from pathlib import Path
import sys

import numpy as np

sys.path.insert(0, str(Path(__file__).resolve().parents[1]))

from choreography import BEAT_SECONDS, CONTROL_HZ, STAND_POSE
from simple_choreography import (
    SHOW_SECONDS,
    SIMPLE_COUNTS,
    command_vector,
    count_phase,
    joint_bias,
)


JOINT_ORDER = (
    "left_hip_yaw", "left_hip_roll", "left_hip_pitch", "left_knee",
    "left_ankle", "neck_pitch", "head_pitch", "head_yaw", "head_roll",
    "right_hip_yaw", "right_hip_roll", "right_hip_pitch", "right_knee",
    "right_ankle",
)


def main() -> None:
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("output_dir", type=Path)
    args = parser.parse_args()
    output_dir = args.output_dir.resolve()
    output_dir.mkdir(parents=True, exist_ok=True)

    jsonl_path = output_dir / "simple_joint_targets_50hz.jsonl"
    sample_count = int(math.ceil(SHOW_SECONDS * CONTROL_HZ))
    with jsonl_path.open("w", encoding="utf-8") as stream:
        for sample in range(sample_count):
            time_seconds = sample / CONTROL_HZ
            wall, count, phase = count_phase(time_seconds)
            spec = SIMPLE_COUNTS[count]
            bias = joint_bias(time_seconds).astype(float)
            nominal = np.asarray(STAND_POSE, dtype=float) + bias
            row = {
                "sample": sample,
                "time_seconds": time_seconds,
                "beat": time_seconds / BEAT_SECONDS,
                "wall": wall + 1,
                "count": count + 1,
                "phase": phase,
                "label": spec.label,
                "swing_foot": spec.swing,
                "placement": spec.placement,
                "weight_transfer": spec.weight_transfer,
                "command_13d": command_vector(time_seconds).astype(float).tolist(),
                "additive_joint_bias_14d": bias.tolist(),
                "nominal_joint_target_14d": nominal.tolist(),
            }
            stream.write(json.dumps(row, separators=(",", ":")) + "\n")

    csv_path = output_dir / "simple_16_count_choreography.csv"
    with csv_path.open("w", newline="", encoding="utf-8") as stream:
        writer = csv.DictWriter(
            stream,
            fieldnames=("count", "label", "swing_foot", "placement", "weight_transfer"),
        )
        writer.writeheader()
        for index, spec in enumerate(SIMPLE_COUNTS, start=1):
            writer.writerow(
                {
                    "count": index,
                    "label": spec.label,
                    "swing_foot": spec.swing,
                    "placement": spec.placement,
                    "weight_transfer": spec.weight_transfer,
                }
            )

    summary = {
        "version": "simple-v3",
        "control_hz": CONTROL_HZ,
        "bpm": 60.0 / BEAT_SECONDS,
        "walls": 4,
        "counts_per_wall": len(SIMPLE_COUNTS),
        "duration_seconds": SHOW_SECONDS,
        "sample_count": sample_count,
        "joint_order": JOINT_ORDER,
        "stand_pose_14d": STAND_POSE,
        "command_order_13d": (
            "vx", "vy", "yaw_rate", "neck_pitch", "head_pitch", "head_yaw",
            "head_roll", "body_x", "body_y", "body_z", "body_roll",
            "body_pitch", "body_yaw",
        ),
        "important": (
            "nominal_joint_target_14d is STAND_POSE plus the v3 choreography bias. "
            "At runtime the official balance-policy action is added before joint-limit "
            "clipping. The beak-snap label is implemented through neck/head pitch because "
            "the official 14-actuator model has no jaw joint. The free root is never written."
        ),
    }
    (output_dir / "simple_reference_summary.json").write_text(
        json.dumps(summary, indent=2), encoding="utf-8"
    )
    print(jsonl_path)
    print(csv_path)


if __name__ == "__main__":
    main()