Work in progress: this documentation is still being written and reviewed. Check details against the source code.

Embedded robot viewer

Render the robot model and obstacle preview inside the operator GUI. These JavaScript functions change the display; they do not send robot commands or update the MoveIt planning scene.

src/mtc_gui/mtc_gui/resources/viewer.html · Source

Operator GUI · Guide · Symbol index

How it is used

VisualizationPanel loads this page in QWebEngine and calls the exposed window functions. Load the URDF with window.loadRobot(), then update the displayed joints or obstacle list as GUI state changes. Model loading is asynchronous.

The viewer applies the ROS Z-up to Three.js Y-up rotation to both robot and obstacles. Rendering, demo animation, and geometry-disposal helpers support those operations and are grouped below the callable interface.

Start here

Callable

Purpose

window.loadRobot

Replace the displayed robot with a URDF fetched asynchronously. Discard stale XHR results and robot assignments, resolve package meshes through the local mesh server, and restore cached obstacles after loading.

window.updateJoints

Update up to six named arm joints in the displayed URDF, converting supplied degrees to radians.

window.setSceneObstacles

Cache and display a complete replacement obstacle list.

window.resetView

Restore the default camera position and orbit-control target.

Example

After the viewer has loaded a robot, the embedding GUI can display a joint pose:

window.updateJoints([0, -90, 90, -90, -90, 0]);

Angles are in degrees. This changes only the rendered pose.

Functions

window.loadRobot()

Replace the displayed robot with a URDF fetched asynchronously. Discard stale XHR results and robot assignments, resolve package meshes through the local mesh server, and restore cached obstacles after loading.

Entry point · Source

window.loadRobot(urdfUrl, meshPort)

Parameter

Meaning

urdfUrl

URL fetched with an asynchronous HTTP GET; a successful response must have status 200.

meshPort

Loopback HTTP port used to resolve package mesh URLs as http://127.0.0.1:<port>/<package>.

Returns: undefined immediately; completion is reported through loading/error elements rather than a Promise.

Errors: HTTP or network failures update the error display. Parse exceptions are caught and displayed; individual mesh errors are logged. XHR callbacks and robot assignment check the load ID before applying stale results. Older LoadingManager callbacks can still change loading/error displays or log mesh errors.

Side effects: Disposes the old robot geometry/materials, removes it, fetches URDF and meshes, creates a new scene object, and rebuilds cached obstacles.

Used by: VisualizationPanel sends this window function through QWebEngine JavaScript after selecting a model.

window.updateJoints()

Update up to six named arm joints in the displayed URDF, converting supplied degrees to radians.

Entry point · Source

window.updateJoints(degArray)

Parameter

Meaning

degArray

Array in shoulder_pan, shoulder_lift, elbow, wrist_1, wrist_2, wrist_3 order, in degrees. Short arrays update only their supplied prefix; extra entries are ignored.

Returns: undefined.

Errors: Returns immediately if no robot or joint map is loaded. Missing individual joints are skipped; elements are not checked for finite numeric values.

Side effects: Changes viewer joint values only.

Used by: Python viewer updates, setHomePose(), and demoStep().

Example

Viewer-only example after a model has loaded:

window.updateJoints([0, -90, 90, -90, -90, 0]);

This changes the rendered pose; it does not command the arm.

window.setSceneObstacles()

Cache and display a complete replacement obstacle list.

Entry point · Source

window.setSceneObstacles(list)

Parameter

Meaning

list

Array of obstacle specifications; this array is retained by reference as lastObstacleList.

Returns: Number of shapes added, or 0 when the input is not an Array.

Errors: Non-array input leaves the current scene/cache unchanged. Malformed array entries can propagate errors from _applyObstacles().

Side effects: Replaces the cached list and visible obstacle objects.

Used by: Python scene-preview updates through QWebEngine JavaScript.

Example

Viewer-only sphere example:

window.setSceneObstacles([{
  name: "example", type: "sphere",
  pos: [0.3, 0, 0.2], rot: [0, 0, 0],
  dims: {radius: 0.025}
}]);

Returns 1 and displays one obstacle; it does not update MoveIt’s planning scene.

window.resetView()

Restore the default camera position and orbit-control target.

Entry point · Source

window.resetView()

Returns: undefined.

Side effects: Moves the viewer camera to (1.2, 1.0, 1.2) and targets (0, 0.4, 0). Robot joint values are unchanged.

Used by: The GUI’s reset-view control.

window.setHomePose()

Apply the viewer’s fixed six-joint home pose.

Entry point · Source

window.setHomePose()

Returns: undefined.

Errors: Inherits updateJoints() behavior when a model or individual joint is absent.

Side effects: Sets the rendered pose to [0, -90, 0, 0, 0, -180] degrees; does not move hardware.

Used by: Calls window.updateJoints(); available to the embedding GUI as a window function.

window.demoMode()

Start a synthetic joint animation when enabled, or cancel an active demo animation when disabled.

Entry point · Source

window.demoMode(enable)

Parameter

Meaning

enable

Truthy starts the animation if none is running; falsy cancels the stored animation frame if one exists.

Returns: undefined.

Errors: No local exception handling. Repeated enable calls do not start additional loops.

Side effects: Creates or cancels demoAnimId and changes the displayed joints over time.

Used by: The viewer’s exposed demonstration control.

window.clearSceneObstacles()

Clear both the cached obstacle list and the displayed obstacle objects.

Entry point · Source

window.clearSceneObstacles()

Returns: undefined.

Errors: Disposal errors are not caught.

Side effects: Replaces lastObstacleList with an empty array and disposes graphics resources.

Used by: The exposed viewer clear operation.

Internal callbacks and helpers

animate()

Schedule the next render frame, update damped orbit controls, and draw the scene.

Callback · Source

animate()

Returns: undefined.

Errors: Renderer and control errors are not caught.

Side effects: Keeps a requestAnimationFrame loop running and redraws the canvas.

Used by: Called once during viewer initialization and then by its own scheduled frame callback.

demoStep()

Compute six sinusoidal joint angles from elapsed demo time, display them, and schedule another demo frame.

Callback · Source

demoStep()

Returns: undefined.

Errors: No local exception handling; updateJoints() simply returns before a model is loaded.

Side effects: Changes rendered joints and the stored animation-frame ID.

Used by: Nested helper created by window.demoMode(); invoked immediately and on subsequent animation frames.

_disposeObstacles()

Dispose the current obstacle geometries and materials, then remove every child from the obstacle group.

Internal helper · Source

_disposeObstacles()

Returns: undefined.

Side effects: Releases graphics resources and clears the visible obstacle group. It does not itself clear lastObstacleList.

Used by: _applyObstacles() and window.clearSceneObstacles().

_makeObstacleMaterial()

Create the green, transparent, double-sided material used for static obstacles.

Internal helper · Source

_makeObstacleMaterial()

Returns: A new THREE.MeshBasicMaterial with opacity 0.30 and depthWrite=false.

Errors: Three.js construction errors are not caught.

Side effects: Allocates a material that the obstacle owner must later dispose.

Used by: _buildObstacle().

_buildObstacle()

Build one positioned and rotated box, cylinder, or sphere group from an obstacle specification.

Internal helper · Source

_buildObstacle(spec)

Parameter

Meaning

spec

Object with optional name, type (box/cylinder/sphere), pos=[x,y,z] in metres, rot=[roll,pitch,yaw] in radians, and dims. Box uses size=[x,y,z]; cylinder uses radius and height; sphere uses radius.

Returns: A THREE.Group containing the shape, or null for an unsupported type.

Errors: Required arrays and dimensions are read directly without validation; malformed specifications can throw. Unsupported types return null after material allocation.

Side effects: Allocates geometry/materials and assigns transforms. Cylinders receive an inner X rotation of π/2 to align their local axis with ROS Z. The group is not added to the scene here.

Used by: _applyObstacles().

_applyObstacles()

Replace visible obstacles with all supported specifications in a supplied list.

Internal helper · Source

_applyObstacles(list)

Parameter

Meaning

list

Array of obstacle objects accepted by _buildObstacle().

Returns: Number of supported shapes added.

Errors: Unsupported types are skipped. A malformed entry can throw after old obstacles have already been removed and earlier new ones added.

Side effects: Disposes the old obstacle group and builds a replacement. It does not update the cached lastObstacleList itself.

Used by: window.setSceneObstacles() and successful robot loading.