Skip to content
Draft
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
8 changes: 8 additions & 0 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ app's data dir), so a change from the agent or another window shows up in every
continuous driving from the keys and sticks, which publishes through the gateway at 20 Hz with the gateway's deadman;
`POST api/drive` is the endpoint way to drive (a Twist for up to 10 s, then zeros; `dryRun` sends nothing).

## URL options

For an app that shows the Controller in an iframe, e.g. `../dim-controller/?robot=arm&onboarding=off`
([core/urlOptions.ts](../frontend/src/core/urlOptions.ts)):

- `robot=<type>` (`dog`, `humanoid`, `wheeled`, `arm`, `drone`): this page uses that [controller format](#controller-format), saved nowhere (other pages keep theirs).
- `onboarding=off`: no first-run message cards and no "Waiting for lidar data." in the 3D view; driving is still held when nothing can be driven.

## What it shows

Every dimos topic is `dimos/<topic>/<message type>` on zenoh, so the key says how to draw it. Each message type has a
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { cameraId, FIXED_PANELS, plotId } from "./ui/workspace.ts"
import type { RunState } from "./core/runs.ts"
import { openOverlay } from "./ui/overlay.ts"
import { ContainCrash } from "./ui/Unavailable.tsx"
import { urlOptions } from "./core/urlOptions.ts"

declare global {
interface Window {
Expand Down Expand Up @@ -146,7 +147,7 @@ function Driving({ app, api }: { app: ViewerApp; api: WorkspaceApi }) {
{api.mobile
? !onboarding.blocksDriving && (isArm ? <ArmHud app={app} mobile /> : <DriveHud app={app} mobile />)
: <><TopBar app={app} api={api} /><KeyOverlay app={app} stage={api.layout.stage} /></>}
{onboarding.message && (
{onboarding.message && !urlOptions.onboardingOff && (
<div className="stage-message" style={rectStyle(api.layout.stage)}>
<EmptyLayer {...onboarding.message} />
</div>
Expand Down
13 changes: 9 additions & 4 deletions frontend/src/core/driveCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type { RobotProfile, RobotType } from "../profile/types.ts"
import { checkLink, DEFAULT_MAX_LATENCY_MS, LINK_CHECK_MS, maxLatencyOf } from "./linkWatch.ts"
import type { ResolvedType, RobotsAnswer } from "./robotType.ts"
import { robotsAnswer } from "./robotType.ts"
import { urlOptions } from "./urlOptions.ts"

export interface ViewSettings {
/** the robot type picked in Settings (a RobotType), "" = auto (core/robotType.ts) */
Expand Down Expand Up @@ -140,15 +141,18 @@ export class DriveCore {
}
}

/** Always the wheeled base's controls (Jeff 10-26: no format picker; drones come later). The auto-detection
* (core/robotType.ts resolveType) stays for when more formats return. */
/** The type this page's URL asks for (?robot=arm), else the wheeled base's controls (Jeff 10-26: no format
* picker; drones come later). The auto-detection (core/robotType.ts resolveType) stays for when more formats return. */
#resolve(): ResolvedType {
if (urlOptions.robot) {
return { type: urlOptions.robot, reason: `this page's URL (?robot=${urlOptions.robot})` }
}
return { type: "wheeled", reason: "the wheeled base controls" }
}

#updateRobot() {
const resolved = this.#resolve()
const auto = true
const auto = !urlOptions.robot
const current = this.robot.get()
if (current.type !== resolved.type || current.reason !== resolved.reason || current.auto !== auto) {
this.robot.set({ type: resolved.type, auto, reason: resolved.reason })
Expand All @@ -158,7 +162,8 @@ export class DriveCore {
this.drive.setProfile(this.#profile)
this.profileChanged.forEach((changed) => changed(this.#profile))
}
if (this.settings.get().robot !== resolved.type && typeof location !== "undefined") {
// a type from the URL is this page's alone: the shared lv.view.robot keeps the other pages' type
if (!urlOptions.robot && this.settings.get().robot !== resolved.type && typeof location !== "undefined") {
this.settings.update({ robot: resolved.type })
}
}
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/core/recordFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ export function inRecordingsFolder(directory: string, root: string | null): bool
return directory === trimmed || directory.startsWith(`${trimmed}/`)
}

/** Why Record can't start with nothing running (the button's title, the palette's note). */
export const NOTHING_TO_RECORD = "Nothing to record: launch a blueprint first"

/**
* The Record toggle's state, the bar's and the phone HUD's alike: recording (and for how long), the short text, and
* whether it can be pressed (not while starting / stopping, not with the recorder down, not with nothing to record).
* `idle`: nothing is running (core/runs.ts nothingRunning), so a new recording would be empty.
*/
export function recordToggleState(input: {
active: boolean
Expand All @@ -45,8 +48,9 @@ export function recordToggleState(input: {
recordNew: boolean
selected: number
seconds: number
idle: boolean
}): { recording: boolean; text: string; disabled: boolean } {
const { active, pending, unavailable, recordNew, selected, seconds } = input
const { active, pending, unavailable, recordNew, selected, seconds, idle } = input
const text = pending === "start" ? "Starting…" : pending === "stop" ? "Stopping…" : active ? formatClock(seconds) : "REC"
return { recording: active, text, disabled: pending !== null || !!unavailable || (!active && !recordNew && selected === 0) }
return { recording: active, text, disabled: pending !== null || !!unavailable || (!active && (idle || (!recordNew && selected === 0))) }
}
7 changes: 7 additions & 0 deletions frontend/src/core/runs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ export class RunWatch {
}
}

/** Nothing running: no blueprint the Launcher started and no robot data on the bus (a blueprint run from a terminal,
* `dimos run` / `dtk run`, sends some). Not robot data: /rpc and /dimos/ topics (dimos's own) and topics ending in
* _request (questions apps ask the robot, such as this page's /render_file_request for the robot's model). */
export function nothingRunning(state: RunState, topics: { name: string }[]): boolean {
return state.running.length === 0 && !topics.some((topic) => !/^\/rpc\b|^\/dimos\/|_request$/.test(topic.name))
}

/** A running blueprint has dimos's ManipulationModule (the arm planner viser sits on): the controller's Plan and move
* shows whatever the controller format, since a robot that drives can have arms too (an R1 Pro's nav). */
export function plannerRunning(state: RunState): boolean {
Expand Down
19 changes: 19 additions & 0 deletions frontend/src/core/urlOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Options in this page's own URL, for an app that shows the Controller in an iframe (docs/reference.md, "URL options").
import type { RobotType } from "../profile/types.ts"
import { chosenType } from "./robotType.ts"

export interface UrlOptions {
/** ?robot=<type>: this page uses that robot type, saved nowhere; null when not given or not a robot type */
robot: RobotType | null
/** ?onboarding=off: no first-run message cards, and no "Waiting for lidar data." in the 3D view */
onboardingOff: boolean
}

/** A query string (`location.search`) → its options. */
export function readUrlOptions(search: string): UrlOptions {
const params = new URLSearchParams(search)
return { robot: chosenType(params.get("robot")), onboardingOff: params.get("onboarding") === "off" }
}

/** This page's options (none in unit tests, which have no page). */
export const urlOptions = readUrlOptions(typeof location === "undefined" ? "" : location.search)
8 changes: 4 additions & 4 deletions frontend/src/ui/Onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { ViewerApp } from "../core/app.ts"
import { useStore } from "../core/store.ts"
import { appInstalled, type EmptyStateOptions, openApp, underDesktop } from "dimos-react/dim-app/desktop.js"
import { takesVelocity } from "../core/cmdvel.ts"
import { nothingRunning } from "../core/runs.ts"

const LAUNCH_DRIVABLE = { stream: "cmd_vel" }
const LAUNCH_ARM = { stream: "joint_command" }
Expand Down Expand Up @@ -160,13 +161,12 @@ export function useOnboarding(app: ViewerApp): Onboarding {
},
}
}
// nothing the Launcher started, but robot data is flowing: a blueprint run from a terminal (dimos run / dtk run)
const outside = runs.running.length === 0 && connection.topics.some((topic) => !/^\/rpc\b|^\/dimos\//.test(topic.name))
if (runs.running.length === 0 && !outside && noBlueprintDismissed) {
const nothing = nothingRunning(runs, connection.topics)
if (nothing && noBlueprintDismissed) {
// dismissed: the 3D view shows whatever topics exist; there's nothing to drive, so no key guide
return { message: null, blocksDriving: true, reason: isArm ? "no arm blueprint is running" : "no blueprint with a cmd_vel input is running", launch }
}
if (runs.running.length === 0 && !outside) {
if (nothing) {
return {
blocksDriving: true,
reason: isArm ? "no arm blueprint is running" : "no blueprint with a cmd_vel input is running",
Expand Down
9 changes: 6 additions & 3 deletions frontend/src/ui/RecordControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { useEffect, useRef, useState } from "react"
import type { ViewerApp } from "../core/app.ts"
import { persistentStore, useStore } from "../core/store.ts"
import { recorder, type Compression, type ImageFormat, type StreamRate } from "../core/recorder.ts"
import { biggestStreams, formatBytes, formatClock, formatRate, inRecordingsFolder, isRecorded, isRpcTopic, recordToggleState, TOP_STREAMS } from "../core/recordFormat.ts"
import { biggestStreams, formatBytes, formatClock, formatRate, inRecordingsFolder, isRecorded, isRpcTopic, NOTHING_TO_RECORD, recordToggleState, TOP_STREAMS } from "../core/recordFormat.ts"
import { nothingRunning } from "../core/runs.ts"
import type { Topic } from "../core/transport.ts"
import { Alert, Badge, Button, Card, Checkbox, Field, Heading, Label, NumberInput, Select, Text, TextInput, Toggle } from "dimos-react"
import { Icon } from "./icons.tsx"
Expand Down Expand Up @@ -35,6 +36,8 @@ export function RecordControl({ app }: { app: ViewerApp }) {
const active = status.recording.active
const selected = topics.filter((topic) => isRecorded(topic.key, chosen))
const busy = pending.action !== null
const runs = useStore(app.runs.state)
const idle = nothingRunning(runs, topics)

// a hash link (#record, as other apps open it with) opens the options
useEffect(() => {
Expand Down Expand Up @@ -66,10 +69,10 @@ export function RecordControl({ app }: { app: ViewerApp }) {
variant={active ? "danger" : "default"}
className={`record-toggle ${active ? "recording" : ""} ${busy ? "pending" : ""}`}
pressed={active}
title={status.unavailable ?? (error ? `${label}: ${error}` : label)}
title={status.unavailable ?? (!active && idle ? NOTHING_TO_RECORD : error ? `${label}: ${error}` : label)}
aria-label={label}
// with new streams joining, a recording can start before anything is on the bus: they join as they appear
disabled={recordToggleState({ active, pending: pending.action, unavailable: status.unavailable, recordNew: status.options.recordNew, selected: selected.length, seconds: status.recording.seconds }).disabled}
disabled={recordToggleState({ active, pending: pending.action, unavailable: status.unavailable, recordNew: status.options.recordNew, selected: selected.length, seconds: status.recording.seconds, idle }).disabled}
onClick={toggle}
>
<span className="record-dot" />
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/ui/ScenePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { jointControlState } from "../core/jointControl.ts"
import { SceneSettings } from "./SettingsPanel.tsx"
import { SnapshotTools } from "./SnapshotGallery.tsx"
import { saveSnapshot, snapshot3d } from "../core/snapshots.ts"
import { urlOptions } from "../core/urlOptions.ts"


const isCloud = (entry: LayerEntry) => entry.topic.type === "sensor_msgs.PointCloud2"
Expand Down Expand Up @@ -98,7 +99,7 @@ export function ScenePanel({ host, app, onTf }: { host: RefObject<HTMLDivElement
{app && !off && <ViewControls app={app} />}
{app && !off && <JointControlArea app={app} />}
{app && !off && <TfFootnote app={app} onOpen={onTf} />}
{app && !off && <SceneWaiting app={app} />}
{app && !off && !urlOptions.onboardingOff && <SceneWaiting app={app} />}
{app && menuOpen && !off && <CloudMenu app={app} anchor={cloudButton.current} onClose={() => setMenuOpen(false)} />}
</Panel>
</>
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/ui/useCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import type { ViewerApp } from "../core/app.ts"
import { useStore } from "../core/store.ts"
import { recorder } from "../core/recorder.ts"
import { NOTHING_TO_RECORD } from "../core/recordFormat.ts"
import { nothingRunning } from "../core/runs.ts"
import { cameraTabs } from "../core/cameraChoice.ts"
import { profiles } from "../profile/index.ts"
import { type Command, panelCommands, panelTitle } from "./commands.ts"
Expand All @@ -27,6 +29,7 @@ export function useCommands(app: ViewerApp, api: WorkspaceApi, cameras: CameraAc
const recording = useStore(recorder.status)
const view = useStore(app.settings)
const connection = useStore(app.connection.status)
const runs = useStore(app.runs.state)
const arm = app.profile.type === "arm"
const focused = api.view.hide.length === 2
const offered = useStore(dockActions)
Expand Down Expand Up @@ -103,7 +106,7 @@ export function useCommands(app: ViewerApp, api: WorkspaceApi, cameras: CameraAc
id: "record.toggle",
label: recording.recording.active ? "Stop recording" : "Start recording",
group: "Record",
blocked: recording.unavailable ?? undefined,
blocked: recording.unavailable ?? (!recording.recording.active && nothingRunning(runs, connection.topics) ? NOTHING_TO_RECORD : undefined),
words: "mcap capture",
run: () => void toggleRecording(app).catch(() => {}),
},
Expand Down
16 changes: 13 additions & 3 deletions frontend/test/record.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { assert, assertEquals } from "jsr:@std/assert@1"
import { biggestStreams, formatClock, formatRate, inRecordingsFolder, isRecorded, isRpcTopic, recordToggleState, TOP_STREAMS } from "../src/core/recordFormat.ts"
import type { StreamRate } from "../src/core/recorder.ts"
import { nothingRunning, type RunState } from "../src/core/runs.ts"

const stream = (topic: string, bytesPerSecond: number): StreamRate => ({
key: `dimos${topic}/x.Y`,
Expand Down Expand Up @@ -47,15 +48,24 @@ Deno.test("numbers read at a glance", () => {
})

Deno.test("the Record toggle (bar and phone HUD): REC at rest, the time while recording, and held while it starts or stops", () => {
const rest = { active: false, pending: null, unavailable: null, recordNew: true, selected: 0, seconds: 0 } as const
const rest = { active: false, pending: null, unavailable: null, recordNew: true, selected: 0, seconds: 0, idle: false } as const
assertEquals(recordToggleState(rest), { recording: false, text: "REC", disabled: false })
assertEquals(recordToggleState({ ...rest, active: true, seconds: 75 }), { recording: true, text: formatClock(75), disabled: false })
assertEquals(recordToggleState({ ...rest, pending: "start" }), { recording: false, text: "Starting…", disabled: true })
assertEquals(recordToggleState({ ...rest, active: true, pending: "stop" }), { recording: true, text: "Stopping…", disabled: true })
// the recorder down, or nothing chosen without new streams joining: can't start
// the recorder down, nothing running, or nothing chosen without new streams joining: can't start
assert(recordToggleState({ ...rest, unavailable: "recorder down" }).disabled)
assert(recordToggleState({ ...rest, idle: true }).disabled)
assert(recordToggleState({ ...rest, recordNew: false }).disabled)
assert(!recordToggleState({ ...rest, recordNew: false, selected: 3 }).disabled)
// a recording can always be stopped, even if every stream was turned off since
// a recording can always be stopped, even if every stream was turned off or the blueprint stopped since
assert(!recordToggleState({ ...rest, active: true, recordNew: false }).disabled)
assert(!recordToggleState({ ...rest, active: true, idle: true }).disabled)
})

Deno.test("nothing running: the page's own requests and dimos's topics on the bus aren't a robot", () => {
const none: RunState = { known: true, desktop: true, dimosInstalled: true, running: [], starting: null, blueprints: {} }
const asks = ["/render_file_request", "/file_request", "/named_locations_request", "/rpc/x", "/dimos/logs"].map((name) => ({ name }))
assert(nothingRunning(none, asks))
assert(!nothingRunning(none, [...asks, { name: "/color_image" }]))
})
9 changes: 9 additions & 0 deletions frontend/test/urlOptions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// The page's URL options (core/urlOptions.ts): ?robot=<type> and ?onboarding=off; anything else changes nothing.
import { assertEquals } from "jsr:@std/assert@1"
import { readUrlOptions } from "../src/core/urlOptions.ts"

Deno.test("url options: a known robot type and onboarding=off; unknown values are ignored", () => {
assertEquals(readUrlOptions("?robot=arm&onboarding=off"), { robot: "arm", onboardingOff: true })
assertEquals(readUrlOptions("?robot=car&onboarding=no"), { robot: null, onboardingOff: false })
assertEquals(readUrlOptions(""), { robot: null, onboardingOff: false })
})
Loading