Skip to content

Commit

Permalink
feat: get trajectories since last call
Browse files Browse the repository at this point in the history
  • Loading branch information
bompo committed Dec 5, 2024
1 parent eb705ea commit 5315a8e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@
"dependencies": {
"@auth0/auth0-spa-js": "^2.1.3",
"@types/three": "^0.167.1",
"@wandelbots/wandelbots-api-client": "^24.7.0",
"@wandelbots/wandelbots-api-client": "^24.8.1",
"axios": "^1.7.2",
"mobx": "^6.12.4",
"path-to-regexp": "^7.1.0",
"reconnecting-websocket": "^4.4.0",
"three": "^0.167.1",
"url-join": "^5.0.0"
}
}
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from "./lib/AutoReconnectingWebsocket"
export * from "./lib/ConnectedMotionGroup"
export * from "./lib/converters"
export * from "./lib/errorHandling"
export * from "./lib/getLatestTrajectories"
export * from "./lib/JoggerConnection"
export * from "./lib/MotionStreamConnection"
export * from "./lib/NovaCellAPIClient"
Expand Down
33 changes: 33 additions & 0 deletions src/lib/getLatestTrajectories.ts
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
}

0 comments on commit 5315a8e

Please sign in to comment.