Skip to content

Object

API Reference - object

This module allows you to:

  • query object state (position, rotation, velocity, angular velocity, acceleration)
  • set object state (position and rotation only)
  • if object is a vehicle, pass commands to its controller (go to position, set velocity, etc.)

All functions in this module require object ID (see map.list_objects and map.list_vehicles). In lua, they are passed as first argument, in websocket API they are passed as part of the command.

Getting object state

object.position(object_id)

Returns object position in local ENU coordinates.

let position = await client.rpc('object_GwAAAAEAAAA=.position')
// or subscribe
let sub = client.newSubscription('object_GwAAAAEAAAA=.position')

Return value is a table with three fields - x (f32), y (f32), z (f32).

object.gps_position(object_id)

Returns object position in GPS coordinates.

let gps_position = await client.rpc('object_GwAAAAEAAAA=.gps_position')
// or subscribe
let sub = client.newSubscription('object_GwAAAAEAAAA=.gps_position')

Return value is a table with three fields - lat (f32), lon (f32), alt (f32).

object.rotation_angles(object_id)

Returns object rotation in euler angles (roll, pitch, yaw). Return value is a bivector (YZ is roll, ZX is pitch, XY is yaw).

let rotation = await client.rpc('object_GwAAAAEAAAA=.rotation_angles')
// or subscribe
let sub = client.newSubscription('object_GwAAAAEAAAA=.rotation_angles')

object.rotation_quat(object_id)

Returns object rotation in quaternion form (W, X, Y, Z).

let rotation = await client.rpc('object_GwAAAAEAAAA=.rotation_quat')
// or subscribe
let sub = client.newSubscription('object_GwAAAAEAAAA=.rotation_quat')

object.linear_velocity(object_id)

Returns object linear velocity in local coordinates, world frame of reference.

let lin_vel = await client.rpc('object_GwAAAAEAAAA=.linear_velocity')
// or subscribe
let sub = client.newSubscription('object_GwAAAAEAAAA=.linear_velocity')

object.angular_velocity(object_id)

Returns object angular velocity in local coordinates, world frame of reference.

let ang_vel = await client.rpc('object_GwAAAAEAAAA=.angular_velocity')
// or subscribe
let sub = client.newSubscription('object_GwAAAAEAAAA=.angular_velocity')

object.acceleration(object_id)

Returns object acceleration in local coordinates, world frame of reference.

let accel = await client.rpc('object_GwAAAAEAAAA=.acceleration')
// or subscribe
let sub = client.newSubscription('object_GwAAAAEAAAA=.acceleration')

object.state(object_id)

Returns position, rotation, linear velocity, angular velocity and acceleration of the object in one call.

let state = await client.rpc('object_GwAAAAEAAAA=.state')
// or subscribe
let sub = client.newSubscription('object_GwAAAAEAAAA=.state')

Return value is a table with the following fields:

  • time_us (u64) - time elapsed since start of simulation in microseconds
  • position (vec3) - position of the object in local coordinates, same as object.position
  • rotation (bivec3) - rotation of the object in euler angles, same as object.rotation_angles
  • lin_vel (vec3) - linear velocity of the object in local coordinates, same as object.linear_velocity
  • ang_vel (bivec3) - angular velocity of the object in local coordinates, same as object.angular_velocity
  • accel (vec3) - acceleration of the object in local coordinates, same as object.acceleration

Setting object state

object.set_position(object_id, position)

Sets object position to a given value in local coordinates.

await client.rpc('object_GwAAAAEAAAA=.set_position', { x: 1, y: 2, z: 3 })

object.set_rotation_angles(object_id, rotation)

Sets object rotation to a given value in euler angles (roll, pitch, yaw).

await client.rpc('object_GwAAAAEAAAA=.set_rotation_angles', { yz: 0, zx: 0, xy: 0 })

object.set_rotation_quat(object_id, rotation)

Sets object rotation to a given value in quaternion form.

await client.rpc('object_GwAAAAEAAAA=.set_rotation_quat', { w: 1, x: 0, y: 0, z: 0 })

Controlling vehicles

object.attitude_control(object_id, control)

Activate vehicle controller with given parameters for attitude control.

Parameters are a table with the following fields:

  • z (f32) - altitude
  • vxy (f32) - yaw rate
  • zx (f32) - pitch
  • yz (f32) - roll
await client.rpc('object_HAAAAAEAAAA=.attitude_control', { z: 1, vxy: 0, zx: 0, yz: 0 })

object.velocity_control(object_id, control)

Activate vehicle controller with given parameters for velocity control.

Parameters are a table with the following fields:

  • z (f32) - altitude
  • vxy (f32) - yaw rate
  • vx (f32) - velocity forward
  • vy (f32) - velocity lateral
await client.rpc('object_HAAAAAEAAAA=.velocity_control', { z: 1, vxy: 0, vx: 0, vy: 0 })

object.position_control(object_id, control)

Activate vehicle controller with given parameters for position control.

Parameters are a table with the following fields:

  • z (f32) - altitude
  • x (f32) - forward
  • y (f32) - left
  • xy (f32) - yaw
await client.rpc('object_HAAAAAEAAAA=.position_control', { z: 1, x: 0, y: 0, xy: 0 })

object.actuator_control(object_id, control)

Set actuator values directly instead of using a controller. Control is a list of actuator values (array of f32). Length and meaning of values depend on the vehicle type.

For UAVs, there are 4 actuators, one for each rotor (front-left, front-right, rear-left, rear-right). Values are between 0 and 1.

For UGVs, there are 12 actuators. First 4 are engine forces for each wheel, next 4 are steering, last 4 are brakes.

await client.rpc('object_HAAAAAEAAAA=.actuator_control', [0.5, 0.5, 0.5, 0.5])

Camera images

object.request_image(camera_id)

Request an image from previously created camera.

Please use camera ID returned from map.spawn_camera function, not vehicle ID here. Camera is an object, but it is not usually listed in spatial queries.

This function is returns a table with the following fields:

  • time_us (u64) - time elapsed since start of simulation in microseconds
  • data (string) - image encoded as data URI
let image = await client.rpc('object_HAAAAAEAAAA=.request_image')
console.log(image.data.data) // data:image/png;base64,...

There might be a significant delay after image is requested due to rendering and encoding, so timestamp is provided to help you sync images with other data.

When camera is initializing, first few frames received might be black.

Capturing images is not yet available in LUA.

Getting bounding volumes

object.compute_aabb(object_id)

Compute axis-aligned bounding box of the given object.

This function returns a table with the following fields:

  • min (vec3)
  • max (vec3)
let aabb = await client.rpc('object_HAAAAAEAAAA=.compute_aabb')

object.compute_bounding_sphere(object_id)

Compute bounding sphere of the given object.

This function returns a table with the following fields:

  • center (vec3)
  • radius (f32)
let sphere = await client.rpc('object_HAAAAAEAAAA=.compute_bounding_sphere')

Despawning objects

object.despawn(object_id)

Remove an object from the map.

All objects are removevd when the simulation restarts, so this method is mainly used to remove objects in the middle of simulation.

let sphere = await client.rpc('object_HAAAAAEAAAA=.compute_bounding_sphere')