上海找人做网站,邯郸建设网站公司,上海做网站优化,做直播网站需要学什么软件如是我闻#xff1a; 在使用指南01中
演示如何使用独立的Python脚本启动和控制Isaac Sim模拟器。介绍Orbit框架中两个最常用的类app.AppLauncher和sim.SimulationContext。实践在Oribit中设置一个空场景
代码
本指南对应于orbit/source/standalone/tutorials/00_sim目录中的…如是我闻 在使用指南01中
演示如何使用独立的Python脚本启动和控制Isaac Sim模拟器。介绍Orbit框架中两个最常用的类app.AppLauncher和sim.SimulationContext。实践在Oribit中设置一个空场景
代码
本指南对应于orbit/source/standalone/tutorials/00_sim目录中的create_empty.py脚本。
# Copyright (c) 2022-2024, The ORBIT Project Developers.
# All rights reserved.
#
# SPDX-License-Identifier: BSD-3-ClauseThis script demonstrates how to create a simple stage in Isaac Sim... code-block:: bash# Usage./orbit.sh -p source/standalone/tutorials/00_sim/create_empty.pyfrom __future__ import annotationsLaunch Isaac Sim Simulator first.
import argparsefrom omni.isaac.orbit.app import AppLauncher# create argparser
parser argparse.ArgumentParser(descriptionTutorial on creating an empty stage.)
# append AppLauncher cli args
AppLauncher.add_app_launcher_args(parser)
# parse the arguments
args_cli parser.parse_args()
# launch omniverse app
app_launcher AppLauncher(args_cli)
simulation_app app_launcher.appRest everything follows.import tracebackimport carbfrom omni.isaac.orbit.sim import SimulationCfg, SimulationContextdef main():Main function.# Initialize the simulation contextsim_cfg SimulationCfg(dt0.01, substeps1)sim SimulationContext(sim_cfg)# Set main camerasim.set_camera_view([2.5, 2.5, 2.5], [0.0, 0.0, 0.0])# Play the simulatorsim.reset()# Now we are ready!print([INFO]: Setup complete...)# Simulate physicswhile simulation_app.is_running():# perform stepsim.step()if __name__ __main__:try:# run the main executionmain()except Exception as err:carb.log_error(err)carb.log_error(traceback.format_exc())raisefinally:# close sim appsimulation_app.close()代码解析
启动模拟器
在使用Orbit进行独立Python脚本开发时第一步是启动模拟器应用。这一步是必要的因为Isaac Sim的各种依赖模块只有在模拟器应用运行后才可用。
要实现这一步我们可以使用app.AppLauncher类进行导入。这个实用程序类是基于用于启动模拟器的omni.isaac.kit.SimulationApp类进行封装的。app.AppLauncher提供了使用命令行参数和环境变量配置模拟器的功能。
在本指南中我们主要来看如何向用户自定义的argparse.ArgumentParser里来添加命令行选项。通过将解析器实例传递给app.AppLauncher.add_app_launcher_args()方法可以向解析器添加不同的参数。这些参数包括以无显模式启动应用程序、配置不同的实时流选项以及启用离屏渲染。
import argparsefrom omni.isaac.orbit.app import AppLauncher# create argparser
parser argparse.ArgumentParser(descriptionTutorial on creating an empty stage.)
# append AppLauncher cli args
AppLauncher.add_app_launcher_args(parser)
# parse the arguments
args_cli parser.parse_args()
# launch omniverse app
app_launcher AppLauncher(args_cli)
simulation_app app_launcher.app导入python模块
当模拟应用启动后我们可以导入来自Isaac Sim及其他库的多种Python模块。本例中我们引入了两个重要模块 carb这是Omniverse提供的一个库它包含了多种微服务和诊断工具用于增强应用的功能和性能。 omni.isaac.orbit.sim这是Orbit框架中的一个专门子包专注于执行所有与核心模拟器操作相关的任务。 import carbfrom omni.isaac.orbit.sim import SimulationCfg, SimulationContext
设置模拟环境
通过独立脚本启动模拟器我们可以控制模拟器的播放、暂停和逐步执行。这些操作均通过模拟环境simulation context 来实现。模拟环境负责管理时间线上的各种事件并为模拟设置物理场景。
在Orbit平台中sim.SimulationContext类是基于Isaac Sim中的omni.isaac.core.simulation_context.SimulationContext类进行扩展的它通过Python的数据类对象来配置模拟环境并处理模拟步进过程中的复杂情况。
在本指南中我们将物理和渲染的时间间隔设定为0.01秒。这件事通过向sim.SimulationCfg传递物理和渲染的时间间隔的参数完成进而用于创建一个模拟环境的实例。 # Initialize the simulation contextsim_cfg SimulationCfg(dt0.01, substeps1)sim SimulationContext(sim_cfg)# Set main camerasim.set_camera_view([2.5, 2.5, 2.5], [0.0, 0.0, 0.0])在建立了模拟环境之后我们至今为止只完成了对模拟场景中物理作用physics acting的配置。这涉及到选择模拟使用的设备、设定重力向量以及调整其他一些高级求解参数。接下来为了让模拟运行起来我们还需要完成两个核心步骤
构建模拟场景 Designing the simulation scene向场景中添加传感器、机器人及其他模拟物体。执行模拟循环 (Running the simulation loop)操作模拟器进行逐步执行并从模拟器中设置及获取数据。
本指南将首先着眼于第二步我们将从一个空白场景开始优先考虑如何控制模拟过程。在随后的教程中我们会深入讨论第一步并学习如何通过模拟处理与模拟器进行互动。
运行模拟
在设置好模拟场景之后首先要做的就是调用sim.SimulationContext.reset()方法。这个方法会播放时间线并在模拟器中的初始化物理处理。在开始模拟步进过程之前sim.SimulationContext.reset()必须首先被调用否则模拟处理将无法正确初始化。
sim.SimulationContext.reset() 区别于sim.SimulationContext.play() 方法后者只播放时间线并不初始化物理处理
在播放模拟时间线之后我们建立了一个简单的模拟循环在模拟应用程序运行时不断地步进模拟器。sim.SimulationContext.step()方法接收一个参数render该参数决定是否在步进中更新与渲染相关的事件。默认情况下这个标志被设置为True。
while simulation_app.is_running():# perform stepsim.step()
退出模拟
最后通过调用omni.isaac.kit.SimulationApp.close()方法停止模拟应用程序并关闭其窗口。为了在发生错误时能够有品地关闭应用程序我们在try-catch语句中执行这一操作。 # close sim appsimulation_app.close()运行代码
现在我们已经大致浏览了代码的各个部分让我们来执行代码来看看最终的结果
./orbit.sh -p source/standalone/tutorials/00_sim/create_empty.py运行后模拟应该正常运行场景应该正确渲染。要停止模拟可以直接关闭窗口或者在终端中按CtrlC。
向上述脚本传递--help参数将显示app.AppLauncher类之前添加的不同命令行参数。要以无显模式运行脚本可以执行以下操作
./orbit.sh -p source/standalone/tutorials/00_sim/create_empty.py --headless现在我们对如何使用独立的python脚本运行模拟有一个基本的了解了在下一篇指南中我们将一起探索如何向场景中添加物品assets。
愿本文渡一切机器人模拟器苦
非常的有品
以上