Object
- API Reference -
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 subscribelet sub = client.newSubscription('object_GwAAAAEAAAA=.position')
local position = object.position("GwAAAAEAAAA=")
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 subscribelet sub = client.newSubscription('object_GwAAAAEAAAA=.gps_position')
local gps_position = object.gps_position("GwAAAAEAAAA=")
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 subscribelet sub = client.newSubscription('object_GwAAAAEAAAA=.rotation_angles')
local rotation = object.rotation_angles("GwAAAAEAAAA=")
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 subscribelet sub = client.newSubscription('object_GwAAAAEAAAA=.rotation_quat')
local rotation = object.rotation_quat("GwAAAAEAAAA=")
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 subscribelet sub = client.newSubscription('object_GwAAAAEAAAA=.linear_velocity')
local lin_vel = object.linear_velocity("GwAAAAEAAAA=")
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 subscribelet sub = client.newSubscription('object_GwAAAAEAAAA=.angular_velocity')
local ang_vel = object.angular_velocity("GwAAAAEAAAA=")
object.acceleration(object_id)
Returns object acceleration in local coordinates, world frame of reference.
let accel = await client.rpc('object_GwAAAAEAAAA=.acceleration')// or subscribelet sub = client.newSubscription('object_GwAAAAEAAAA=.acceleration')
local accel = object.acceleration("GwAAAAEAAAA=")
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 subscribelet sub = client.newSubscription('object_GwAAAAEAAAA=.state')
local state = object.state("GwAAAAEAAAA=")
Return value is a table with the following fields:
time_us
(u64) - time elapsed since start of simulation in microsecondsposition
(vec3) - position of the object in local coordinates, same asobject.position
rotation
(bivec3) - rotation of the object in euler angles, same asobject.rotation_angles
lin_vel
(vec3) - linear velocity of the object in local coordinates, same asobject.linear_velocity
ang_vel
(bivec3) - angular velocity of the object in local coordinates, same asobject.angular_velocity
accel
(vec3) - acceleration of the object in local coordinates, same asobject.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_position("GwAAAAEAAAA=", { 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_angles("GwAAAAEAAAA=", { 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 })
object.set_rotation_quat("GwAAAAEAAAA=", { 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) - altitudevxy
(f32) - yaw ratezx
(f32) - pitchyz
(f32) - roll
await client.rpc('object_HAAAAAEAAAA=.attitude_control', { z: 1, vxy: 0, zx: 0, yz: 0 })
object.attitude_control("HAAAAAEAAAA=", { 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) - altitudevxy
(f32) - yaw ratevx
(f32) - velocity forwardvy
(f32) - velocity lateral
await client.rpc('object_HAAAAAEAAAA=.velocity_control', { z: 1, vxy: 0, vx: 0, vy: 0 })
object.velocity_control("HAAAAAEAAAA=", { 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) - altitudex
(f32) - forwardy
(f32) - leftxy
(f32) - yaw
await client.rpc('object_HAAAAAEAAAA=.position_control', { z: 1, x: 0, y: 0, xy: 0 })
object.position_control("HAAAAAEAAAA=", { 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])
object.actuator_control("HAAAAAEAAAA=", { 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 microsecondsdata
(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')
local aabb = object.compute_aabb("HAAAAAEAAAA=")
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')
local sphere = object.compute_bounding_sphere("HAAAAAEAAAA=")
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')
object.despawn("HAAAAAEAAAA=")