Examples
This section contains example code snippets demonstrating how to use Zivid Motion in different scenarios. The most primitive are covered by the Quickstart article, and left out from these more complex examples.
Using Zivid point cloud as obstacle
This example shows how to set a point cloud from a Zivid camera, and update the point cloud once the scene changes. This requires having the Zivid SDK and Zivid Python installed, and being connected to a Zivid camera.
import numpy as np
import zivid
from zividmotion.zividmotion import Planner, PlannerSettings, Obstacle
# Retrieved from hand-eye calibration of your setup
handeye_transform = np.eye(4) # replace with your handeye transform
print('Starting planner...', '\n')
# For now, Zivid will provide you with data needed to initialize the planner
planner_settings = PlannerSettings.from_dict(...)
planner = Planner(planner_settings=planner_settings)
print('Planner ready!', '\n')
# Connect to the camera
zivid_app = zivid.Application()
camera = zivid_app.connect_camera()
capture_settings = zivid.Settings("my/capture/settings.yml") # import your capture settings here
# Capture a point cloud
frame = camera.capture(capture_settings)
# Create the obstacle
# Downsampling improves speed, if you dont need the extra resolution
frame.point_cloud().downsample(zivid.PointCloud.Downsampling.by4x4)
frame.point_cloud().transform(handeye_transform)
point_cloud_obstacle = Obstacle(name="myPointCloud", structured_points=frame.point_cloud().copy_data("xyz"))
planner.set_obstacles(obstacles=[point_cloud_obstacle])
# Scene changes, e.g. robot picks from a bin ...
# Recapture and update the obstacle, make sure the obstacle name matches
frame = camera.capture(capture_settings)
frame.point_cloud().downsample(zivid.PointCloud.Downsampling.by4x4)
frame.point_cloud().transform(handeye_transform)
point_cloud_obstacle = Obstacle(name="myPointCloud", structured_points=frame.point_cloud().copy_data("xyz"))
planner.set_obstacles(obstacles=[point_cloud_obstacle])