Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use marker name for triggers; change spec to prepare for timestamp-range markers. #856

Merged
merged 4 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions choreolib/py/choreo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def load_differential_trajectory_string(
splits = [int(split) for split in data["trajectory"]["splits"]]
events = [
EventMarker(
float(event["data"]["offset"]["val"])
+ float(event["data"]["targetTimestamp"]),
event["event"]["data"]["event"],
float(event["from"]["offset"]["val"])
+ float(event["from"]["targetTimestamp"]),
event["name"],
)
for event in data["events"]
]
Expand Down Expand Up @@ -96,9 +96,9 @@ def load_swerve_trajectory_string(trajectory_json_string: str) -> SwerveTrajecto
splits = [int(split) for split in data["trajectory"]["splits"]]
events = [
EventMarker(
float(event["data"]["offset"]["val"])
+ float(event["data"]["targetTimestamp"]),
event["event"]["data"]["event"],
float(event["from"]["offset"]["val"])
+ float(event["from"]["targetTimestamp"]),
event["name"],
)
for event in data["events"]
]
Expand Down
5 changes: 2 additions & 3 deletions choreolib/py/choreo/test/choreolib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@
"forcesAvailable":false
},
"events":[
{"data":{"name":"Marker", "target":0, "targetTimestamp":0, "offset":{"exp":"0 s", "val":0.0}}, "event":{"type":"choreolib", "data":{"event":"testEvent"}}}
],
"pplib_commands":[]
{"name":"testEvent", "from":{"target":0, "targetTimestamp":0, "offset":{"exp":"0 s", "val":0.0}}, "event":null}
]
}
"""

Expand Down
2 changes: 1 addition & 1 deletion choreolib/py/choreo/test/resources/swerve_test.traj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@
"splits":[],
"forcesAvailable":false
},
"events":[{"data":{"name":"Marker", "target":1, "targetTimestamp":1.3926677138988457, "offset":{"exp":"-1 s", "val":-1.0}}, "event":{"type":"choreolib", "data":{"event":"testEvent"}}}],
"events":[{"name":"testEvent", "from":{"target":1, "targetTimestamp":1.3926677138988457, "offset":{"exp":"-1 s", "val":-1.0}}, "event":null}],
"pplib_commands":[]
}
13 changes: 3 additions & 10 deletions choreolib/src/main/java/choreo/trajectory/EventMarker.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,19 @@ public EventMarker deserialize(
try {
var targetTimestamp =
json.getAsJsonObject()
.get("data")
.get("from")
.getAsJsonObject()
.get("targetTimestamp")
.getAsDouble();
var offset =
json.getAsJsonObject()
.get("data")
.get("from")
.getAsJsonObject()
.get("offset")
.getAsJsonObject()
.get("val")
.getAsDouble();
var event =
json.getAsJsonObject()
.get("event")
.getAsJsonObject()
.get("data")
.getAsJsonObject()
.get("event")
.getAsString();
var event = json.getAsJsonObject().get("name").getAsString();

return new EventMarker(targetTimestamp + offset, event);
} catch (IllegalStateException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void choreo::to_json(wpi::json& json, const EventMarker& event) {

void choreo::from_json(const wpi::json& json, EventMarker& event) {
event.timestamp =
units::second_t{json.at("data").at("offset").at("val").get<double>() +
json.at("data").at("targetTimestamp").get<double>()};
event.event = json.at("event").at("data").at("event").get<std::string>();
units::second_t{json.at("from").at("offset").at("val").get<double>() +
json.at("from").at("targetTimestamp").get<double>()};
event.event = json.at("name").get<std::string>();
}
5 changes: 2 additions & 3 deletions choreolib/src/test/java/choreo/ChoreoTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ public class ChoreoTests {
"forcesAvailable":false
},
"events":[
{"data":{"name":"Marker", "target":0, "targetTimestamp":0, "offset":{"exp":"0 s", "val":0.0}}, "event":{"type":"choreolib", "data":{"event":"testEvent"}}}
],
"pplib_commands":[]
{"name":"testEvent", "from":{ "target":0, "targetTimestamp":0, "offset":{"exp":"0 s", "val":0.0}}, "event":null}
]
}
""";

Expand Down
5 changes: 2 additions & 3 deletions choreolib/src/test/native/cpp/TrajectoryFileTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ constexpr std::string_view swerveTrajectoryString =
"forcesAvailable":false
},
"events":[
{"data":{"name":"Marker", "target":0, "targetTimestamp":0, "offset":{"exp":"0 s", "val":0.0}}, "event":{"type":"choreolib", "data":{"event":"testEvent"}}}
],
"pplib_commands":[]
{"name":"testEvent", "from":{"target":0, "targetTimestamp":0, "offset":{"exp":"0 s", "val":0.0}}, "event":null}
]
})";

const wpi::json swerveTrajectoryJson = wpi::json::parse(swerveTrajectoryString);
Expand Down
29 changes: 5 additions & 24 deletions src-core/src/spec/trajectory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,7 @@ pub struct TrajectoryFile {
pub trajectory: Trajectory,
/// The choreo events.
#[serde(default)]
pub events: Vec<ChoreolibEventMarker>,
/// The pplib commands to execute.
/// This is a compatibility layer for working with
/// the path planner library.
#[serde(default)]
pub pplib_commands: Vec<PplibEventMarker>,
pub events: Vec<EventMarker>,
}

impl TrajectoryFile {
Expand All @@ -442,24 +437,17 @@ impl TrajectoryFile {
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EventMarkerData {
pub name: String,
pub target: Option<usize>,
pub target_timestamp: Option<f64>,
pub offset: Expr,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ChoreolibEventMarker {
data: EventMarkerData,
event: ChoreolibEvent,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PplibEventMarker {
data: EventMarkerData,
event: PplibCommand,
pub struct EventMarker {
pub name: String,
pub from: EventMarkerData,
pub event: Option<PplibCommand>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand All @@ -485,10 +473,3 @@ pub enum PplibCommand {
commands: Vec<PplibCommand>,
},
}

// single-case enum so that it matches the serialization from above
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", tag = "type", content = "data")]
pub enum ChoreolibEvent {
Choreolib { event: String },
}
25 changes: 1 addition & 24 deletions src/components/config/eventmarker/CommandDraggable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class CommandDraggable extends Component<Props, State> {
onChange={(e) => command.setType(e.target.value as CommandType)}
>
{CommandUIData.map((data) => {
if (data.id === "choreolib" && this.props.parent !== undefined) {
if (data.id === "none" && this.props.parent !== undefined) {
return undefined;
}

Expand Down Expand Up @@ -126,29 +126,6 @@ class CommandDraggable extends Component<Props, State> {
}}
></TextField>
)}
{command.isChoreolib && (
<TextField
inputRef={this.eventInputRef}
sx={{
marginLeft: "1ch",
".MuiInput-input": {
paddingBottom: "0px"
}
}}
fullWidth
variant="standard"
placeholder="Event"
value={command.event ?? ""}
size="small"
onClick={(e) => e.stopPropagation()}
onChange={(e) => command.setEvent(e.target.value)}
onKeyDown={(e) => {
if (e.key == "Enter") {
this.eventInputRef.current?.blur();
}
}}
></TextField>
)}
{command.isWait && (
<ExpressionInputList style={{ flexGrow: 1 }}>
<ExpressionInput
Expand Down
6 changes: 3 additions & 3 deletions src/components/config/eventmarker/EventMarkerConfigPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class EventMarkerConfigPanel extends Component<Props, State> {
}
render() {
const marker = this.props.marker;
const data = marker.data;
const data = marker.from;
let startIndex = (data.getTargetIndex() ?? -0.5) + 1;
const points = this.props.points;
const pointcount = points.length;
Expand Down Expand Up @@ -125,8 +125,8 @@ class EventMarkerConfigPanel extends Component<Props, State> {

<TextField
inputRef={this.nameInputRef}
value={data.name}
onChange={(e) => data.setName(e.target.value)}
value={marker.name}
onChange={(e) => marker.setName(e.target.value)}
variant="standard"
size="small"
placeholder="Marker Name"
Expand Down
4 changes: 2 additions & 2 deletions src/components/field/PathAnimationSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ class PathAnimationSlider extends Component<Props, State> {
})
.concat(
activePath.markers.flatMap((marker: IEventMarkerStore) => {
if (marker.data.timestamp === undefined) {
if (marker.from.timestamp === undefined) {
return [];
}
return {
value: marker.data.timestamp,
value: marker.from.timestamp,
label: (
<span>
<Room
Expand Down
2 changes: 1 addition & 1 deletion src/components/field/svg/FieldEventMarkerAddLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class FieldConstraintsAddLayer extends Component<Props, State> {
onClick={() => {
const newMarker = activePath.addEventMarker();

newMarker.data.setTarget({ uuid: point.uuid });
newMarker.from.setTarget({ uuid: point.uuid });
// TODO set direct timestamp if trajectory not stale
doc.setSelectedSidebarItem(newMarker);
}}
Expand Down
4 changes: 2 additions & 2 deletions src/components/field/svg/FieldEventMarkers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ class FieldEventMarkers extends Component<Props, State> {
const path = doc.pathlist.activePath;
const markers = path.markers;
return markers.flatMap((marker) => {
if (marker.data.timestamp === undefined) {
if (marker.from.timestamp === undefined) {
return [];
}
const marked = sample(marker.data.timestamp, path.trajectory.samples);
const marked = sample(marker.from.timestamp, path.trajectory.samples);
return (
<FieldEventMarker
key={marker.uuid}
Expand Down
10 changes: 5 additions & 5 deletions src/components/sidebar/SidebarEventMarker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ class SidebarMarker extends Component<Props, State> {
className={styles.SidebarLabel}
style={{ display: "grid", gridTemplateColumns: "1fr auto auto" }}
>
<Tooltip disableInteractive title={this.props.marker.data.name}>
<Tooltip disableInteractive title={this.props.marker.name}>
<span style={{ overflow: "hidden", textOverflow: "ellipsis" }}>
{this.props.marker.data.name}
{this.props.marker.name}
</span>
</Tooltip>
{/* {!isInSameSegment || marker.data.getTargetIndex() === undefined ? (
Expand All @@ -63,11 +63,11 @@ class SidebarMarker extends Component<Props, State> {
<span></span>
)} */}
<span>
<span>{this.waypointIDToText(this.props.marker.data.target)} </span>
<span>{this.waypointIDToText(this.props.marker.from.target)} </span>
<span style={{}}>
(
{(this.props.marker.data.offset.value < 0 ? "" : "+") +
this.props.marker.data.offset.value.toFixed(2) +
{(this.props.marker.from.offset.value < 0 ? "" : "+") +
this.props.marker.from.offset.value.toFixed(2) +
" s"}
)
</span>
Expand Down
19 changes: 6 additions & 13 deletions src/document/2025/v2025_0_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ export interface Trajectory {
params: ChoreoPath<Expr>;
snapshot: ChoreoPath<number>;
trajectory: Output;
events: EventMarker<ChoreolibEvent>[];
pplibCommands: EventMarker<PplibCommand>[];
events: EventMarker[];
}

export type GroupCommand = {
Expand All @@ -159,15 +158,8 @@ export type NamedCommand = {
name: string | null;
};
};
export type ChoreolibEvent = {
type: "choreolib";
data: {
event: string | null;
};
};

export type EventMarkerData = {
name: string;
target: WaypointIDX | undefined;
offset: Expr;
/**
Expand All @@ -176,8 +168,9 @@ export type EventMarkerData = {
targetTimestamp: number | undefined;
};
export type PplibCommand = WaitCommand | GroupCommand | NamedCommand;
export type Command = PplibCommand | ChoreolibEvent;
export interface EventMarker<C extends Command> {
data: EventMarkerData;
event: C;
export type Command = PplibCommand | undefined;
export interface EventMarker {
name: string;
from: EventMarkerData;
event: Command;
}
Loading
Loading