快速入门

介绍

本文是对 Zivid Motion 的快速介绍。它将向您展示如何解包一个工作单元、生成规划数据,以及规划避开简单障碍物的路径。本快速入门指南旨在提供一个简单的示例,而不深入探讨过多细节。

如果您还没有安装 Zivid Motion,请前往 安装 安装 Zivid Motion 后再返回本文。

安装工作单元数据

工作单元的数据以 zip 文件的形式提供,与 Zivid Motion 团队发给您的安装文件放在一起。

~/Downloads/motion-quickstart/
├─ data.zip
├─ zivid_pythonmotion*.whl
├─ zivid-motion*.deb

您首先需要做的就是安装工作单元数据:

python -c 'import zividmotion; app = zividmotion.Application(); zividmotion.install_package(application=app, package_path="path/to/data.zip")'

现在, ~/.local/share/Motion/ 目录中应该已经包含了本快速入门指南所需的数据。如需了解该目录内容的更多信息,请参阅 数据和配置文件 中的 工作单元数据

生成规划数据

您需要先生成规划数据才能开始规划。这是一个预处理步骤,可以加快运行时规划器的计算速度。如果源文件(位于 ~/.local/share/Motion/ 目录下)发生更改,则需要重新生成规划数据;否则,规划器会报错。

运行 生成规划数据 示例中的代码进行生成。生成时间取决于您的系统配置,但对于 testing 环境来说,应该不会超过一分钟左右。

规划路径

是时候规划一下路线了!下面的简单示例将引导您完成四个简单的步骤:

  1. 初始化规划器

  2. 规划从一个关节配置到另一个关节配置的路径

  3. 设置一个简单的几何障碍物来阻挡路径

  4. 重新规划路径,观察规划器是如何找到一条绕过障碍物的新路径的

为了能够快速简单地创建长方体障碍物,我们在这里使用了 trimesh 库。可以通过以下命令进行安装:

pip install trimesh
from typing import Optional

import trimesh
from zividmotion.zividmotion import Application, Obstacle, PathRequest, PlannerSettings, Profile, Visualizer

# A visual representation of the cell will open when USE_VISUALIZER is set to True.
CELL_NAME = "demo_cell"
PROFILE = Profile.testing
USE_VISUALIZER = True


app = Application()


planner_settings = PlannerSettings(
    cell_name=CELL_NAME,
    profile=PROFILE,
)

print("1. Initializing planner...")
planner = app.create_planner(planner_settings)
visualizer: Optional[Visualizer] = Visualizer.view_planner(planner) if USE_VISUALIZER else None
print("Planner successfully initialized.")

start_joint_config = [0.0, 0.0, 0.6, 0.0, 0.9, 0.0]

input("2. Press Enter to plan path to goal...")

# A simple planning problem where the shortest path is to spin the first joint 180 degrees.
goal_configuration = [3.14, 0.0, 0.6, 0.0, 0.9, 0.0]

path_request = PathRequest(goal_configurations=[goal_configuration])
path_result_1 = planner.path(start_joint_config, path_request)

print(path_result_1)

input("3. Press Enter to set an obstacle...")

# This obstacle will block the direct path, forcing the planner to find a new path around it.
box = trimesh.creation.box(extents=[0.12, 0.7, 0.7])
box.apply_translation(translation=[0, 1.3, 0.8])
obstacle = Obstacle.from_mesh(name="box_obstacle", mesh=box.triangles.tolist())
planner.set_obstacles([obstacle])

input("4. Press Enter to plan path to goal again...")

path_result_2 = planner.path(start_joint_config, path_request)

# The planner should now have found a new path around the obstacle. When comparing the two
# path results, you can see that path_result_2 contains multiple waypoints to pass around
# the obstacle.
print(path_result_1)
print(path_result_2)

if visualizer is not None:
    print("Close the window to exit.")
    visualizer.wait()

下一步

以上是对 Zivid Motion 的快速介绍,旨在让您初步了解如何使用运行时 API 来规划路径以及在环境中设置动态障碍物。建议接下来阅读以下内容: