node-red-contrib-physical-sandbox 0.5.4
Physical Sandbox for Node-RED: a sidebar pane that shows robots on a real site, moved by MQTT messages and records
node-red-contrib-physical-sandbox
Physical Sandbox for Node-RED. A pane in the editor's sidebar shows robots standing on a real site, at real
scale, over a photo or a video of that site. The robots are moved by MQTT messages (ps in) or by a record
(ps play), and what moved can be saved as a record on PS.com.
Requirements: Node-RED 4.1 or later, Node.js 20 or later. Nothing in this version needs Python or psbx, except converting your own URDF (see Robots only this machine has).
Install
In the Node-RED user directory (~/.node-red by default):
cd ~/.node-red
npm i node-red-contrib-physical-sandbox
Restart Node-RED. The sidebar gets a tab "PS", and the palette gets a category "physical sandbox" with the
nodes ps in and ps play (and the config node ps account). The plugin never deploys flows and never does anything without a click.
The pane
Open the tab "PS" in the sidebar, or press "Open in a window" to put it on another screen. Both show the same scene and the same stream, so you can use either, or both at once.
The screens follow Node-RED's language setting (Japanese or English); messages to the agent stay in both languages. The labels below are the English ones (the Japanese ones are in README.ja.md).
The pane is laid out as PS.com's video screen: the picture fills it under one bar ("Background ▾", "Decide the
floor", "Place…", "Record ▾"). The bar holds only what the hand does on the picture (the background, the floor,
placing and moving robots) and saving the record; every setting is in the nodes' settings (on a hit in ps play and
ps in, signing in to PS.com and the agent switch in ps account, playing in ps play; below). What plays, the hits and the copies PS.com does not have
stand on the picture's top left, and messages at its foot. In a narrow sidebar the bar wraps to more rows and the
picture keeps the whole width.
- Background. Choose a photo or a video of the site. It stays in your browser and in
<userDir>/physical-sandbox/backgrounds/; it is never sent to PS.com. - Background by address or latitude and longitude. Enter an address, or a place as
42.65132, 143.18545, and press "Show" (an address is placed by Geolonia's address data, made from the Digital Agency's Address Base Registry, to the house number, block or land lot number where the data has it, else by GSI's address search; the pane says how fine the place found is, and credits the data): the town round it is drawn from open data (the aerial photo of GSI, the Geospatial Information Authority of Japan, with the buildings, street furniture and roads of MLIT PLATEAU), in Japan. Drag to turn, Shift-drag to slide the ground, wheel to come closer. The source is shown on the stage while it is. A record saved on it carries the place (anchor: latitude, longitude and bearing; never the address), and a record with one brings this background when it is opened. "Remove the background" takes it away. - Floor. Click the four corners of a rectangle on the ground in the picture (1 to 4, going round), enter the lengths of edges 1→2 and 2→3 in metres, and press "Decide". The robots are placed on this floor at real scale.
- Robots. "Place…" lists the robots of three places: the PS.com catalog, the psbx cache
(
~/.cache/physical-sandbox) and local folders (below). Choose one, then click the floor to place it there. Without a connection to PS.com, only the robots on this computer are listed. - Moving robots by hand, as on PS.com's video screen. Click a robot to pick it: an orange ring lies at its feet
and "Re-place" and "Delete" come up beside it. Click the floor to send the picked robot there: a robot that
drives (its bundle.json's
locomotion: wheels, legs, a drone) is driven along PS.com's drive plan, and one that does not (Static, an arm on a bench) turns on the spot to face the point. A robot whose bundle.json says nothing of how it drives is driven as a wheeled one on PS.com's default figures, and the pane says so. Drag a robot to carry it (it goes see-through) and let go where it goes; "Re-place" carries it until the next click. The left and right arrow keys turn the picked robot 15°, Delete takes it away, and Esc or the right button lets go (a robot being carried goes back). Nothing is moved by hand while a record plays. Only the place and the facing move: wheels and legs are not turned yet. - What the hand does goes into the flow. A robot driven to a floor click says where it is ten times a second
as
ps/<site>/<id>/state({ "at", "type": "mover", "position", "yaw" }), thenps/<site>/<id>/event{ "at", "event": "arrived" }; one put somewhere or turned by hand says one such state. These come out of everyps innode's first output, as MQTT's messages do, withmsg.from = "pane", and are recorded. A state with a position from MQTT (or a play) takes the robot over: the drive by hand stops and the robot goes where MQTT says. - Playback. Records are played by
ps playnodes (below), chosen in each node's settings. Aps playnode is started and stopped with its button in the editor (once deployed) or astartorstopmessage. Aps playnode with "Open in the pane" takes the record's site and robots. - Recording the stream. States that arrive through
ps inare kept as a record in the pane, as they come. - Saving ("Record ▾"). "Record ▾" first says which record is open (the one "Save" writes over). "Save" makes the next version of the record you opened. "Save as a new record" makes a new
record under a name you give. Versions are never written over. "Export" writes a record file to
<userDir>/physical-sandbox/exports/.
On a hit: each node's setting
What happens when two robots hit is a setting of each ps play node (for the robots it plays) and each ps in
node (for the robots it brings in from MQTT), with the same four choices: "Do not check", "Only tell" (the
default: the robots that hit turn red and ps in sends the events below), "Stop the robot that hit" and "Stop
everything".
ps play. On a stop, a played robot stops just before the robot it would hit (its states are not sent on either) and stays there until the play ends, is stopped or starts again. "Stop everything" also pauses every play; the node's button (or aresumemessage) goes on.ps in. On a stop, the robot is held in the pane where it hit, and itshiton the second output has"stopped": true, so the flow can send the real robot a stop. States that come while it is held are recorded but not shown. It goes on from its next state that would not hit (with aclear), from a message whosetopicisrelease, or from a deploy. A play starting or ending does not free it.- Two settings. A robot follows the node that last moved it. Two robots under different settings take the stronger (Do not check < Only tell < Stop the robot that hit < Stop everything); a robot nothing has moved yet only stands there. Hits are checked while any node (or the agent's own setting) is not "Do not check".
- From 0.5.2. A
ps playorps innode made before 0.5.3 has no setting of its own: it keeps the one 0.5.2 kept in<userDir>/physical-sandbox/collision.json(shown when its settings are opened; saved with the next deploy). A new node starts at "Only tell". The robots the agent plays follow that kept setting, which the agent'sps_scene_collisionchanges. Aps panenode left in a flow from 0.5.2 still loads; it does nothing and warns that its settings moved, and it can be deleted.
ps in: from MQTT into the pane
Put ps in after mqtt in (topic ps/#, or narrower). Messages on ps/<site>/<id>/<kind>, with <kind>
one of state, command or event, and a JSON payload with at in milliseconds (at may be left out: ps in
then gives the payload the time it took it, also on its output), move the robots in the pane
and are recorded. The payload may be an object, JSON text or a Buffer, so any Output setting of mqtt in
works; anything else is ignored without an error (the node's status turns yellow). When the pane does not show
a message, the status says why: another site's than the pane's (a ps play node opening its record in the pane sets the pane's site; ps play plays on the pane's site),
nothing to move, no robot of that name in the pane, or a play under way that writes over it. The status goes
blank with the next message the pane shows. The optional Site filter passes only one site. A retained
message moves the robots but is not recorded. The message goes on to the node's output unchanged.
A state is { "at": 1700000000000, "joints": { "shoulder": 0.5 }, "position": [x, y, z], "yaw": 0.2 } with at
least one of joints and position (metres, ROS axes); { "joints": { "shoulder": 0.5 } } alone is enough, as
ps in gives it the time it came. An at you give is used as spacing only: the pane shows the last state to come,
whatever its at (past or future), and a record keeps the spacing of each robot's at on the time the pane took the
first one (taken again when at goes back or drifts from the time it comes by more than 3 s), or for an item
{ "at": …, "type": "item", "parent": "site", "xyz": [x, y, z] }. Only states are kept in a record.
The first output also sends what the hand does in the pane (a robot driven to a floor click, put somewhere or
turned), in the same form, with msg.from = "pane" (see "Moving robots by hand" above). Sent on to a broker and
back through mqtt in and ps in, such a message moves the robot but is not recorded twice.
The second output tells when two robots hit each other in the pane: ps/<site>/<id>/event with
{ "at": 1700000000000, "event": "hit", "with": "<the other robot's id>" }, and "event": "clear" when they part.
Each robot of the pair gets one message, and at is that of the state that made the hit. Robots touching are
not hitting; items, robots whose bundle.json gives no dimensions, and a robot riding another are not
checked. On "Stop the robot that hit" and "Stop everything" (the "On a hit" setting, above), a hit means that a played
robot stopped just before the other one: the robot that stopped gets "stopped": true in its payload, and the
pair's clear comes when the stop is released (the play ends, is stopped or starts again), not when the robots
part. A clear made by a release carries the time of the release as at. With a Site, only that site's events are sent. Every ps in sends them, so two ps in nodes send each
event twice. These events are not recorded.
ps play: from a record out to MQTT
ps play plays a record's motion in time as ps/<site>/<id>/state messages, on its output and in the pane.
The record is either this node's own (JSON pasted in, or "From a file" to read a record file of this computer)
or a PS.com record (handle/name or handle/name:version). Its field suggests records as you type, as
Node-RED's own suggestions do: from the first character, a moment after the last key, at most 10 from PS.com's
catalog with the typed part in bold (name, handle/name and date); ↑ ↓ choose, Enter or a click takes one, Esc
closes. Focused while empty, it suggests your own records (signed in) and the ones chosen lately in this
Node-RED. The last row, "Search the PS.com catalog…", opens the catalog's records page in the browser. A
handle/name typed as it is needs no suggestion. What you type is sent to PS.com only, to search the records). Its settings also hold the speed, looping, the PS.com account (below) and
"Open in the pane" (on for a new node): before each play the record is opened in the pane, its site and robots,
as the pane's own play used to; a record with a place (a public background) or a floor brings
them too, and one without leaves out the background and floor an earlier record brought, keeping the ones you
chose (two ps play nodes played in turn each show their own record); off, the states play on the pane's site as it is. The node's button in the editor
(once deployed) sends it start, or stop while it plays.
Send it start, stop or rewind as the payload, or {"command": "start", "speed": 2, "loop": true}.
Wire its output to mqtt out to publish; retain is mqtt out's setting.
To start music or a video together with it, wire the same inject to the music node as well: both start on the same message.
What ps play plays is not recorded in the pane, and neither are its messages when they come back through a
broker and ps in; they still move the robots.
On the pane's "Stop the robot that hit", the states of a robot that stopped are not sent on the output either,
so a robot listening through mqtt out stops where the pane's does. On "Stop everything", the node pauses with
every play and goes on with its button, a resume message, "Go on" in the ps account settings, or the agent's ps_stream_resume. Each start, stop, rewind, loop round and end of the node frees
the robots that were stopped, and so does a deploy.
Robots only this machine has
Your own robot (a URDF) can be shown without sending it anywhere. Convert it with psbx from the main branch (the next release; 0.1.2 on PyPI does not have it yet):
psbx machine bundle path/to/robot.urdf --out ~/robots/myarm --name myarm
and tell Node-RED the folder in settings.js:
physicalSandbox: {
localMachineDirs: ['~/robots'], // folders holding <name>/bundle.json
catalogBase: 'https://physicalsandbox.com', // optional; $PS_CATALOG_URL wins
site: 'local', // optional; the site in ps/<site>/<id>/<kind>
},
Each robot goes in its own folder under the configured folder (--out is the folder bundle.json is written into). ~ is your home folder, and other relative paths are taken from the user directory. A record that uses such a
robot cannot be saved to PS.com (PS.com does not have the robot); it stays on this computer as "Not on PS.com".
PS.com: sign-in and saving
Signing in is in the nodes' settings, as Node-RED keeps an account: choose or add a "PS.com account" (ps account
config node) in the settings of a ps play or ps in node and press "Sign in to PS.com". It shows a code and the
address to open (<catalogBase>/app/?new, which is https://physicalsandbox.com/app/?new by default). Sign in
there, choose "Connect a VR headset" from the icon at the top right, enter the code and press "Allow". "Sign out"
forgets it. There is one sign-in per Node-RED, kept in <userDir>/physical-sandbox/ps-com-token.json: every
ps account node shows the same account, and the pane's saves, ps play's PS.com records and the agent all use
it. Signed out, the pane's "Record ▾" only says that saves are kept on this computer.
The ps account settings also hold the agent switch "Share the pane's frames with the agent" (below), and show
what the agent plays now with "Stop", and "Go on" after a hit paused the plays (both act at once).
If a save cannot reach PS.com (offline, signed out, PS.com failing), the record is kept in
<userDir>/physical-sandbox/unsent/ and the pane shows "Not on PS.com" with a button "Send again". It survives a restart of Node-RED. If the record you saved over was changed elsewhere meanwhile, your
copy is saved as a new record and the pane says so. A copy that can never go (it uses a robot only this
computer has, or belongs to another account) can be taken away with "Remove" on its line.
Claude Desktop
ps-nodered-mcp lets Claude Desktop (or any MCP client that starts a command) use the agent tools of the Node-RED running on this computer.
Connecting Claude Desktop
Add this to Claude Desktop's configuration (claude_desktop_config.json) and restart it:
{"mcpServers": {"node-red-physical-sandbox": {"command": "npx", "args": ["-y", "-p", "node-red-contrib-physical-sandbox", "ps-nodered-mcp"]}}}
(If the package is installed, "command" can be the path of the ps-nodered-mcp bin instead.) Node-RED must be running with this package installed, and the Node-RED editor open in a browser tab for the tools that need it (flows, pane pictures).
Options (add them to args after ps-nodered-mcp):
--url <address>: the MCP route of Node-RED. Defaulthttp://127.0.0.1:1880/physical-sandbox/mcp; alsoPS_NODERED_URL. When Node-RED's settings sethttpAdminRoot, the address must include it (for examplehttp://127.0.0.1:1880/admin/physical-sandbox/mcpforhttpAdminRoot: '/admin').--user-dir <folder>: Node-RED's user folder (userDir). Default~/.node-red; alsoNODE_RED_USER_DIR. If you start Node-RED with-u <folder>, give the same folder here.PS_BRIDGE_POLL_MS(environment): while Node-RED cannot be reached, how often the bridge looks again for its tools, in milliseconds. Default 5000.
The key lives in <userDir>/physical-sandbox/mcp-key. The plugin creates it when Node-RED starts (readable by your user only; on Windows this file mode has no effect, so the folder's own permissions are what protect it), and the bridge reads it from there. The route answers only this computer, and only with that key.
Limits of "this computer only":
- Behind a reverse proxy or a tunnel on the same computer (nginx, Cloudflare Tunnel, ngrok and so on), every caller looks local to Node-RED, and only the key guards the route. Keep the key file private.
- Node-RED in Docker does not see the host's calls as loopback, so the MCP route refuses them: the bridge does not work with Node-RED in a container.
What the agent can do
- Look at the setup. The status of the pane (sign-in, scene, editors and panes open, the pictures switch) and the robots available, with their joints and chains.
- Work out poses. Inverse kinematics for a chain of a robot (position only in this version): the joint angles that put a hand at a point, or the closest ones when it is out of reach.
- Set the scene and play motion. Place or remove robots, play state messages in the pane (a new attempt replaces the last one; loops can be stopped), and turn messages into a record for a
ps playnode. - Choose a public background. Show the town round an address or a latitude and longitude in Japan, as the pane's "Background by address or latitude and longitude" does (
ps_scene_background), or take it away. An address the agent gives is searched by GSI's address search from Node-RED (see below). - Check collisions. Ask when robots of the record overlap (
ps_collisions, checked every 0.1 s on the record's own motion, at a wider step for a very long record; the answer gives the step), choose what to do on a hit (ps_scene_collision: off, notify, stopRobot or stopAll) and go on after a stopAll pause (ps_stream_resume). - Open and save records. Open a PS.com record, and save the stream as a new record or as the next version of the open one (same rules as the pane).
- Work on flows. Read the flows in the open editor and propose a flow (see "No deploying" below). Reading the flows (
ps_flows_read) sends them to the agent, and through it to its AI provider: function nodes' code, broker addresses and the values of environment variables that are not secret (credentials are never included). - Look at the pane. Only while the switch below is on.
The pictures switch
The switch "Share the pane's frames with the agent" in the settings of a ps account node is off by default: without a ps account node, or with the switch off and deployed, it is off. While it is on and deployed, the agent can ask for pictures of the pane (ps_pane_frames), and those pictures include the background photo or video. They go to the agent, and through it to the AI provider the agent runs on. This is the one place where pictures leave your machine. They are never sent to PS.com. With the switch off, nothing is sent and the tool is refused.
No deploying
The agent never deploys. ps_flow_propose makes the Node-RED editor import the nodes (in a new tab, with new ids, so nothing of yours is overwritten) as an undeployed change, and shows a notice. Nothing runs until you check it and press Deploy: your Deploy is the approval.
Example
You ask Claude: 「OpenArm に盆踊りさせて」 (make OpenArm dance a bon odori). The agent places OpenArm, works out arm poses with the inverse kinematics tool (both hands above the head, and so on), and plays them in a loop. You see the robot dancing in the pane. Then it may offer a flow: it proposes inject → ps play → mqtt out in a new tab of the editor, waiting for your Deploy. Music is not part of this: sync it with another node. The background (the real site behind the robot) is chosen by you in the pane.
Privacy and limits
- The background photo or video never leaves this computer, except while you turn on the
ps accountnode's "Share the pane's frames with the agent" switch: then the pictures go to the connected agent and its AI provider (never to PS.com). Only the record (states and the scene's devices) goes to PS.com, and only when you save. - When Node-RED's
adminAuthis on, the textures of robots are not loaded (the shapes are). - An address typed in the pane is looked up by this browser in Geolonia's address data
(
japanese-addresses-v2.geoloniamaps.com, CC BY 4.0, made from the Digital Agency's Address Base Registry; land lot places also come from the registry office maps of the Ministry of Justice). Geolonia sees the prefecture, the municipality and which town (the files and byte ranges asked for), never the numbers. Geolonia offers this data free for now and may stop or change it; hosting the data ourselves is planned for later. When it finds no block, house or land lot, the address as typed also goes to GSI's address search. - A background by address or latitude and longitude is fetched by this browser straight from GSI and PLATEAU (never through Node-RED or PS.com): they see which place is looked at. GSI says its address search is meant mainly for its own map and may change or stop without notice. PLATEAU's delivery is a trial without a promise of service; when it cannot be reached only the aerial photo is shown.
- When an agent chooses the background by an address (
ps_scene_background), Node-RED sends the address to GSI's address search (the pane's own search goes from the browser). A latitude and longitude is not searched. The drawing is still fetched by the browser.
Development
npm install
npm run build
npm test # against Node-RED 4.1.x
npm run test:nr5 # the smoke test against Node-RED 5.0.x
npm run start:dev # Node-RED on http://127.0.0.1:1881 with this package installed
npm run start:dev -- <userDir> uses that user directory instead of a new temporary one.