C++ API Reference
Units of Measurement
All units in the Zivid Motion API are SI units, meaning meters for length and position and radians for angles.
Top-level Classes
-
class Application
Manager class for Zivid Motion.
The Application class manages resources used by the Zivid Motion. It is required to have one instance of this class alive while using Zivid Motion. Using any part of Zivid Motion without a live Application is undefined behavior.
It is not possible to have more than one Application instance at a time. Creating a second Application instance before the first Application instance has been destroyed will trigger an exception.
Public Functions
-
Planner createPlanner(PlannerSettings plannerSettings) const
Initializes a Planner instance from planner settings.
- Parameters:
plannerSettings – Planner settings
-
Planner createPlanner(PlannerSettings plannerSettings) const
-
class Planner
Public Functions
-
Goals computeInverseKinematics(const std::vector<Pose> &poses, const Configuration &referenceConfiguration)
Computes the robot’s joint configurations corresponding to the given TCP poses.
This method performs inverse kinematics to find joint configurations. There are possibly multiple joint configurations that correspond to the same TCP pose, denoted by different robot postures. The reference configuration is used to select which posture the solution should be computed for.
- Parameters:
poses – The poses for which the corresponding configurations will be computed
referenceConfiguration – A reference configuration used to preserve the robot’s posture
- Returns:
An object containing one IK result per input pose. The result is the configuration that represents the desired pose with the same posture as the reference configuration, or
std::nulloptif no such solution is found.
-
PathResult path(const InitialState &initialState, const PathRequest &request)
Calculates a path to one of multiple goal configurations from the initial state.
- Parameters:
initialState – The initial state for the path
request – Request for the path call
-
void setObstacles(const std::vector<Obstacle> &obstacles)
Register objects in the environment for collision avoidance.
Obstacles are unique by name, if you set a new obstacle with the same name as an existing obstacle, the existing one will be replaced. When possible, it is preferred to set all obstacles at once with a single call, rather than iterative calls to this method which will be slower.
For colored obstacles, the alpha value is ignored. Note that adding color also has some overhead and is therefore not recommended in performance-critical code.
- Parameters:
obstacles – Obstacles
-
void clearObstacles()
Clears all registered obstacles from the planner’s collision model.
-
void setCarriedObject(const Mesh &carriedObject)
Updates the robot’s collision model with the carried object it’s now holding.
The carried object geometry is defined in the robot TCP frame.
- Parameters:
carriedObject – The mesh of the carried object to be set
-
void clearCarriedObject()
Clears the carried object from the robot’s collision model.
-
void setReplaceableTool(const Mesh &replaceableTool, std::optional<std::reference_wrapper<const Mesh>> compliantSection = std::nullopt)
Updates the robot’s collision model with the current configuration of a modifiable or exchangeable end-effector tool.
The replaceable tool geometry is defined in the robot flange frame.
- Parameters:
replaceableTool – The mesh of the rigid section of the replaceable tool to be set
compliantSection – Optional mesh representing the compliant geometry of the tool element during Touch motions. This could represent the deformable part of a suction tool. Environment contact will be allowed for the specified geometry during Touch motions, while it will be considered rigid all other times.
-
void clearReplaceableTool()
Clears the replaceable tool from the robot’s collision model.
-
void setAttachments(const std::vector<std::string> &attachments)
Sets the active attachments connected to the last link of the robot in the robot’s collision model.
Multiple attachments can be added. Only attachments defined in the configuration file can be added.
- Parameters:
attachments – Specifies the name of the attachments to be set. Only attachments defined in the configuration file can be set. If an empty vector is provided, all attachments are removed.
-
void setTcp(const Tcp &tcp)
Updates the current Tool Center Point of the robot.
The new TCP frame is used for path planning to goal poses, and it is the reference frame for setting carried objects.
- Parameters:
tcp – The TCP to be set
-
void clipPointCloudWithBox(const BottomCenteredTransformedBox &box)
Updates the environment point cloud by removing all points inside the specified box.
This is useful when picking up objects from the scene in e.g. de-palletizing applications, where the object being picked up should no longer be considered part of the environment.
- Parameters:
box – The box volume where points should be removed. The transform is relative to the cell base frame.
-
void clipPointCloudWithMesh(const Pose &transform, const Mesh &mesh)
Updates the environment point cloud by removing all points inside the specified mesh.
This is useful when picking up objects from the scene in e.g. de-palletizing applications, where the object being picked up should no longer be considered part of the environment.
- Parameters:
transform – The transformation from the cell base frame to the mesh.
mesh – The mesh to clip with. Note: The mesh must be closed. Using a mesh that is not closed is currently undefined behavior.
-
std::filesystem::path exportApiLog(const std::optional<std::filesystem::path> &outputDirectory = std::nullopt)
Exports and saves the API log to file.
- Parameters:
outputDirectory – If specified, overrides the default output directory specified in RuntimeConfiguration.yaml.
- Returns:
The path to the stored API log file.
-
void replayApiLog(const std::filesystem::path &path)
Replays a previously exported API log file.
Restores the environment state (obstacles, TCP, carried object, replaceable tool, attachments) from the log, then replays all recorded API calls.
- Parameters:
path – The path to the API log file to replay.
-
Goals computeInverseKinematics(const std::vector<Pose> &poses, const Configuration &referenceConfiguration)
-
class Visualizer
Visualizer for viewing a robot cell.
The Visualizer opens a window that displays a robot cell. The window remains open until the user closes it or the Visualizer is destroyed. The destructor will immediately close the window if it is still open.
Public Functions
-
void wait()
Blocks until the user closes the visualization window.
If the window has already been closed, this method returns immediately.
Public Static Functions
-
static Visualizer viewPlanner(Planner &planner)
Opens a visualization window for a running Planner.
Use this overload to visualize a planner during path planning. To visualize a cell before generation, use Visualizer::viewCell() instead. The planner must remain alive for the lifetime of the Visualizer.
- Parameters:
planner – The Planner instance to visualize
- Returns:
A Visualizer instance that manages the visualization window
-
static Visualizer viewCell(const Application &application, const std::string &cellName)
Opens a visualization window for the given cell.
Use this overload to visualize a cell before generation. To visualize a cell while planning, use Visualizer::viewPlanner() instead.
- Parameters:
application – The Zivid Motion Application instance
cellName – The name of the cell to visualize
- Returns:
A Visualizer instance that manages the visualization window
-
void wait()
Helper Classes and Structs
-
class InitialState
Represents the context required for path planning.
It is used as an argument to the Planner.path() method.
The InitialState class encapsulates the start configuration or the result of a path planning operation. It is used to provide the necessary context for planning paths to goal configurations.
Public Functions
-
InitialState(const Configuration &startConfiguration)
Initializes the InitialState from a start Configuration.
This should only be utilized when a previous path result is not available. For consecutive motions, it is recommended to use the PathResult constructor.
- Parameters:
startConfiguration – The robot’s start configuration for the path planning
-
InitialState(const PathResult &previousResult)
Initializes the InitialState from a PathResult.
This overload is intended for consecutive robot motions. It requires that the provided PathResult has status Success.
- Parameters:
previousResult – A previous successful PathResult
Public Static Functions
-
static InitialState FromTouch(const Configuration &startConfiguration)
Initializes the InitialState from a start Configuration in touch.
In contrast to the regular constructor, this function is used when the robot is in a touch state.
This should only be utilized when a previous path result is not available. For consecutive motions, it is recommended to use the PathResult constructor.
- Parameters:
startConfiguration – The robot’s start configuration for the path planning in touch
-
InitialState(const Configuration &startConfiguration)
-
struct PathRequest
Request to pass to a path call.
Public Types
-
enum class Type
Used to specify the motion type.
Values:
-
enumerator free
For moving in free space.
-
enumerator touch
For interacting with the environment, like gripping or placing an object.
A touch call will include a linear motion at the end of the trajectory to approach the object safely. If the InitialState for the path call is constructed from a touch result, then the next trajectory will also start with a linear retraction.
-
enumerator free
-
enum class GoalPrioritizationMethod
Used to specify the goal prioritization method.
Values:
-
enumerator listOrder
Among the reachable goals, the one that appears first in the list of goals is selected.
-
enumerator shortestPath
Among the reachable goals, the one that gives the shortest trajectory is selected.
-
enumerator listOrder
Public Members
-
GoalPrioritizationMethod goalPrioritizationMethod = GoalPrioritizationMethod::shortestPath
Decides which goal is used when multiple reachable goals are provided to the path call.
-
std::optional<Vector3f> retractDirection = {}
Optional retract direction when retracting from a Touch configuration.
When retracting from Touch, this field can be used to specify the desired retraction direction when clearing the surrounding objects. If not provided, the retract direction will be calculated based on the parameters specified in RegionOfInterest. The direction should be given in the cell base frame.
-
Goals goals
The goals to plan to.
The path will be planned according to the selected goal prioritization method.
-
std::optional<std::string> description
Description can be used to easily distinguish between path calls in the visualizer.
-
std::optional<float> maxCarriedObjectCompressionDistance = {}
Optional parameter for specifying the maximum compression distance, beyond initial contact, for the carried object along the Touch approach.
-
enum class Type
-
struct BlendRadius
Represents a blend radius for a given waypoint.
See Blending parameters for how to interpret these values for a particular robot type.
Public Functions
-
std::string toString() const
Get string representation of the BlendRadius.
Public Members
-
float entry
Entry is the distance from the waypoint to the point along the trajectory from the previous waypoint to the current one where safe blending can start.
-
float exit
Exit is the distance from the waypoint to the point along the trajectory from the current waypoint to the next one where safe blending must end.
-
std::string toString() const
-
struct Waypoint
A waypoint in joint space, describing where and how the robot should move as part of a path.
Public Types
Public Members
-
Configuration configuration
The joint configuration of the waypoint.
-
Movement movement
Describes with what movement type the robot should move to this waypoint.
Note that this can affect how the BlendRadius should be interpreted for both this and the previous waypoint in the path.
-
BlendRadius blendRadius
The blend radius for this waypoint guaranteed to give a collision-free blending motion.
Do not use a smaller non-zero blend radius than what is reported. Either use the value(s) provided or zero. Smaller non-zero values are not guaranteed to give collision-free blending motions in all scenarios.
Note that the blend radius will never be more than half the distance between consecutive waypoints.
-
Configuration configuration
-
class Path
An ordered sequence of waypoints describing how the robot should move.
Public Types
Public Functions
-
const_iterator begin() const
Iterator to the beginning of the waypoints.
-
const_iterator end() const
Iterator to the end of the waypoints.
-
const_iterator cbegin() const
Iterator to the beginning of the waypoints.
-
const_iterator cend() const
Iterator to the end of the waypoints.
-
std::size_t size() const
The number of waypoints in the path.
-
bool empty() const
Check whether the path contains no waypoints.
-
const_iterator begin() const
-
class PathResult
PathResult is the result of calculating a path to a set of potential goals.
It’s the return value from Planner.path().
Public Types
-
enum class Error
Enum describing why the planner did not find a path to any goal.
Values:
-
enumerator blockedStart
The start configuration is blocked.
-
enumerator blockedEnd
All the valid goal configurations are blocked.
-
enumerator blockedPath
The start configuration and at least one goal configuration are not blocked, but the planner failed to connect them with a collision-free path.
-
enumerator kinematicViolation
All the goal configurations are outside the robot’s joint limits.
-
enumerator blockedStart
Public Functions
-
Path path() const
Returns the computed path, as a list of waypoints.
The path does not include the start configuration provided to the Planner.path() call. And the final waypoint in the path is the joint configuration of the selected goal, i.e.:
pathResult.finalConfiguration() == goals[pathResult.selectedGoalIdx].configuration.If there is a planning error, the list is empty.
- Returns:
A list of waypoints
-
Configuration finalConfiguration() const
Returns the final configuration of the robot in the computed path.
This is the same as the selected goal and performs the same operation as calling
.path().back().configuration. This throws if the path planning failed.- Returns:
The final configuration of the path
-
explicit operator bool() const
Returns true if there is no planning error, false otherwise.
Makes it convenient to do
if(pathResult): ...
Public Members
-
std::optional<Error> error
The PathResult will have an error set if the planner did not find a collision-free path to any of the goals.
-
std::optional<uint32_t> selectedGoalIdx
If there is a planning error, this is std::nullopt.
Otherwise, this is the index to the selected goal in the goals vector.
-
Tcp tcp
The TCP when the PathResult was computed.
-
enum class Error
-
class Obstacle
Represents an obstacle in the robot environment, to be used with the setObstacles() method.
The obstacle coordinates must be expressed in the cell base frame.
Public Types
Public Static Functions
-
static Obstacle fromPointCloud(std::string name, PointCloud pointCloud)
Initializes an Obstacle instance from a point cloud.
-
static Obstacle fromColoredPointCloud(std::string name, PointCloud pointCloud, Colors colors)
Initializes a colored Obstacle instance from a point cloud.
The number of points and colors must be the same. Note that adding color has some overhead and is therefore not recommended in performance-critical code.
-
static Obstacle fromPointCloud(std::string name, PointCloud pointCloud)
-
class Mesh
A triangle mesh.
Public Functions
-
Triangles toTriangles() const
Converts the mesh to a vector of triangles.
This method is effectively the inverse of Mesh::fromTriangles.
- Returns:
A vector of triangles representing the contents of the mesh.
-
std::size_t triangleCount() const
Returns the number of triangles in the mesh.
- Returns:
The number of triangles.
-
Mesh &transformInPlace(const Pose &pose) &
Applies the given transform to the vertices of this mesh.
This method modifies the mesh in-place and does not create a new Mesh instance.
- Parameters:
pose – The transform to apply to the mesh vertices.
- Returns:
This mesh which is now transformed by the given pose.
-
Mesh transform(const Pose &pose) const
Applies the given transform to the vertices of this mesh.
This method creates a copy of the mesh and leaves the original unchanged.
- Parameters:
pose – The transform to apply to the mesh vertices.
- Returns:
A copy of this mesh which is transformed by the given pose.
-
Mesh &bottomCenterTransformInPlace() &
Transforms this mesh such that its bottom center is at the origin.
This method can be used in conjunction with e.g. Planner::setReplaceableTool where the attachment point for the mesh is usually at the bottom. This method modifies the mesh in-place and does not create a new Mesh instance.
- Returns:
This mesh which is now transformed such that its bottom center is at the origin.
-
Mesh bottomCenterTransform() const
Transforms this mesh such that its bottom center is at the origin.
This method can be used in conjunction with e.g. Planner::setReplaceableTool where the attachment point for the mesh is usually at the bottom. This method creates a copy of the mesh and leaves the original unchanged.
- Returns:
A copy of this mesh which is transformed such that its bottom center is at the origin.
-
Mesh &setColor(const ColorRGBA &color)
Sets a uniform color on all vertices of the mesh, replacing any existing color.
This method modifies the mesh in-place and does not create a new Mesh instance.
- Parameters:
color – The color to apply to the mesh. The alpha component is ignored.
- Returns:
This mesh which now has the given uniform color.
Public Static Functions
-
static Mesh fromTriangles(const Triangles &triangles)
Creates a Mesh from a vector of triangles.
- Parameters:
triangles – The triangles to construct the mesh out of.
- Returns:
A mesh consisting of the given triangles.
-
static Mesh createBox(const Vector3f &extents)
Creates a box-shaped mesh with the given extents.
The created mesh is centered on the origin.
- Parameters:
extents – The dimensions of the box.
- Returns:
A box-shaped mesh.
-
static Mesh createCylinder(float radius, float height, unsigned resolution = 64)
Creates a cylinder-shaped mesh.
The created mesh is centered on the origin. The side of the cylinder is constructed from rectangular segments that approximate the circular surface at the provided angular resolution. I.e., the side of the cylinder is made up of ‘resolution’ rectangular segments, each covering an angle of (360 / resolution) degrees.
- Parameters:
radius – The radius of the cylinder.
height – The height of the cylinder.
resolution – The number of rectangular segments approximating the side of the cylinder. (Default: 64)
- Returns:
A cylinder-shaped mesh.
-
static Mesh createSphere(float radius, unsigned resolution = 64)
Creates a sphere-shaped mesh.
The created mesh is centered on the origin. The surface of the sphere is constructed from square segments that approximate the circular surface at the provided angular resolution.
- Parameters:
radius – The radius of the sphere.
resolution – The number of square segments along each axis used to cover 180 degrees along the sphere, from pole to pole. (Default: 64)
- Returns:
A sphere-shaped mesh.
-
Triangles toTriangles() const
-
struct Tcp
Represents a tool center point (TCP) of the robot.
It contains the transform and tool direction.
-
struct Goals
A collection of path-planning goals.
Public Functions
-
bool noneValid() const
A utility method to check if all the joint configurations are
std::nulloptor not.
-
std::string toString() const
Get a string representation of the object.
Public Members
-
std::vector<std::optional<Configuration>> jointConfigurations
Vector of optional joint configurations.
These are optionals to preserve the mapping to the input poses when calling Planner::computeInverseKinematics().
Public Static Functions
-
static Goals fromConfigurations(const std::vector<Configuration> &jointConfigurations)
Initializes a Goals instance directly from a vector of configurations.
- Parameters:
jointConfigurations – The joint configurations
-
bool noneValid() const
-
class Pose
Describes a rigid transform (rotation+translation), such as a robot pose.
The translation part of the transform is expressed in meters.
-
class Matrix4x4
A fixed size 4x4 matrix of floats in row major order.
Public Types
-
using ValueType = float
The type stored in the matrix.
-
using Iterator = std::array<float, 16>::iterator
Iterator type for mutable access, iterating over elements in row major order.
-
using ConstIterator = std::array<float, 16>::const_iterator
Iterator type for immutable access, iterating over elements in row major order.
Public Functions
-
Matrix4x4() = default
Default-constructs a zero-initialized matrix.
-
explicit Matrix4x4(const std::array<float, rows * cols> &data)
Constructs a Matrix4x4 from a flat array of elements in row major order.
-
explicit Matrix4x4(std::initializer_list<float> values)
Constructs a Matrix4x4 from a flat initializer list of elements in row major order.
-
explicit Matrix4x4(std::initializer_list<std::initializer_list<float>> values)
Constructs a Matrix4x4 from a nested initializer list. Each inner list is a row.
-
ConstIterator begin() const
Iterator to the beginning of the matrix.
-
ConstIterator end() const
Iterator to the end of the matrix.
-
ConstIterator cbegin() const
Iterator to the beginning of the matrix.
-
ConstIterator cend() const
Iterator to the end of the matrix.
-
float &at(std::size_t row, std::size_t col)
Access specified element with bounds checking.
-
const float &at(std::size_t row, std::size_t col) const
Access specified element with bounds checking.
-
float &operator()(std::size_t row, std::size_t col)
Access specified element without bounds checking.
-
const float &operator()(std::size_t row, std::size_t col) const
Access specified element without bounds checking.
-
float *data()
Pointer to the underlying row major data.
-
const float *data() const
Pointer to the underlying row major data.
-
using ValueType = float
-
enum class Zivid::Motion::Profile
Used to specify a testing or production profile for a robot cell.
Values:
-
enumerator testing
-
enumerator production
-
enumerator testing
-
struct BottomCenteredTransformedBox
Represents a box whose transform points to the box’s bottom center.
Public Functions
-
std::string toString() const
Get string representation of the BottomCenteredTransformedBox.
-
std::string toString() const
-
struct ColorRGBA
Color with red, green, blue and alpha channels.
-
struct Vector3f
Vector of three coordinates as float, expressed in meters.
-
class Configuration
Joint angles of the robot, expressed in radians.
Public Types
-
using value_type = float
The type stored in the configuration.
-
using const_iterator = Storage::const_iterator
Iterator type for immutable access to the joint angles.
Public Functions
-
Configuration() = default
Default-constructs an empty configuration.
-
explicit Configuration(std::initializer_list<float> values)
Constructs a Configuration from a list of joint angles.
-
template<typename Iterator>
inline Configuration(const Iterator beginIt, const Iterator endIt) Constructs a Configuration from the joint angles in the range [beginIt, endIt).
-
const_iterator begin() const
Iterator to the beginning of the joint angles.
-
const_iterator end() const
Iterator to the end of the joint angles.
-
const_iterator cbegin() const
Iterator to the beginning of the joint angles.
-
const_iterator cend() const
Iterator to the end of the joint angles.
-
std::size_t size() const
The number of joint angles.
-
const float &operator[](std::size_t index) const
Access the specified joint angle.
-
const float *data() const
Pointer to the underlying joint angle data.
-
bool operator==(const Configuration &other) const
Check if two configurations have equal joint angles.
-
std::string toString() const
Get string representation of the Configuration.
-
using value_type = float
Typedefs
-
using Zivid::Motion::Triangles = std::vector<Triangle>
Vector of triangles, for example a triangle mesh.
-
using Zivid::Motion::ProgressCallback = std::function<void(double, const std::string&)>
A progress callback function type.
- Param progressPercentage:
The progress completion percentage (0 - 100%).
- Param updateStageDescription:
A textual description of the progress stage.
Free Functions
-
void Zivid::Motion::generate(const Application &application, const PlannerSettings &plannerSettings, const ProgressCallback &progressCallback = {})
Generate cell data.
- Parameters:
application – Motion application
plannerSettings – Settings for generation
progressCallback – An optional progress callback function
-
void Zivid::Motion::packageCell(const Application &application, const std::string &cellName, const std::filesystem::path &outputPath, const std::vector<Profile> &includeGeneratedData)
Packages a cell into a zip archive.
This function collects all files required to run the motion planner with the specified cell and packages them into a zip file at the given output path.
Throws if the specified cell does not exist, if the output file already exists, or if the parent folder of the output path does not exist.
- Parameters:
application – Motion application
cellName – The name of the cell to package.
outputPath – The destination path for the generated zip archive, including the filename with “.zip” extension.
includeGeneratedData – What generated data to include.
-
std::filesystem::path Zivid::Motion::packageApiLog(const Application &application, const std::filesystem::path &apiLogPath)
Packages the data related to an API log into a zip archive.
This function collects the files required to replay a motion session with a specified API log, and packages them into a zip file with the same name as the API log, but with the
-resources.zipsuffix instead of the.jsonextension. The API log itself is not packaged.- Parameters:
application – Motion application
apiLogPath – The path to the API log
- Returns:
The path to the created zip archive.
-
void Zivid::Motion::installPackage(const Application &application, const std::filesystem::path &packagePath)
Installs a packaged cell to be used by the motion planner.
This function extracts the contents of a packaged cell (zip archive) and installs them into the appropriate directory so they can be used by the motion planner.
- Parameters:
application – Motion application
packagePath – The path to the cell package (zip archive) to install.
Experimental
-
Mesh Zivid::Motion::Experimental::merge(const MeshReferences &meshes)
Merges several meshes into a single mesh.
This function creates a new Mesh instance and leaves the input meshes unchanged.
This is an experimental feature. It may be changed or removed without notice in a future release.
- Parameters:
meshes – A vector of references to the meshes to merge.
- Returns:
The merged Mesh instance.
-
std::vector<bool> Zivid::Motion::Experimental::checkMeshCollisions(const Planner &planner, const std::vector<Configuration> &configurations, unsigned numIgnoredLinksFromTip)
Checks if the robot is in collision with any environment meshes for the given joint configurations
This is an experimental feature. It may be changed or removed without notice in a future release.
Also checks for self-collision. Any environment point clouds are ignored.
Use numIgnoredLinksFromTip to disregard links of the robot from collision checking, counting from the tip of your robot model. Use the value zero to include the whole robot model. Note that if you have a tool modeled as part of the last link, then setting this to 1 ignores the tool as well. Any carried objects or replaceable tools are also ignored when numIgnoredLinksFromTip > 0.
Also note that including multiple configurations in the same call is faster than iterative calls to this function.
- Parameters:
planner – The planner holding the robot model and environment
configurations – Configurations
numIgnoredLinksFromTip – Number of ignored links from tip
- Returns:
One bool per input configuration. True if the configuration is in collision, False otherwise.