-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: get trajectories since last call
- Loading branch information
Showing
4 changed files
with
40 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { GetTrajectoryResponse } from "@wandelbots/wandelbots-api-client" | ||
import type { NovaCellAPIClient } from "./NovaCellAPIClient" | ||
|
||
let lastMotionIds: Set<string> = new Set() | ||
|
||
export async function getLatestTrajectories( | ||
apiClient: NovaCellAPIClient, | ||
): Promise<GetTrajectoryResponse[]> { | ||
const newTrajectories: GetTrajectoryResponse[] = [] | ||
|
||
try { | ||
const motions = await apiClient.motion.listMotions() | ||
const currentMotionIds = new Set(motions.motions) | ||
|
||
const newMotionIds = Array.from(currentMotionIds).filter( | ||
(id) => !lastMotionIds.has(id), | ||
) | ||
|
||
for (const motionId of newMotionIds) { | ||
const trajectory = await apiClient.motion.getMotionTrajectory( | ||
motionId, | ||
50, | ||
) | ||
newTrajectories.push(trajectory) | ||
} | ||
|
||
lastMotionIds = currentMotionIds | ||
} catch (error) { | ||
console.error("Failed to get latest trajectories:", error) | ||
} | ||
|
||
return newTrajectories | ||
} |