Orbit 使用指南 10|在机器人上安装传感器 | Isaac Sim | Omniverse

2024-03-24 08:20

本文主要是介绍Orbit 使用指南 10|在机器人上安装传感器 | Isaac Sim | Omniverse,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

如是我闻: 资产类(asset classes)允许我们创建和模拟机器人,而传感器 (sensors) 则帮助我们获取关于环境的信息,获取不同的本体感知和外界感知信息。例如,摄像头传感器可用于获取环境的视觉信息,接触传感器可以用来获取机器人与环境的接触信息。

在本指南中,我们将看到如何给机器人添加不同的传感器。我们将在本指南中使用ANYmal-C机器人。ANYmal-C是一款四足机器人,拥有12个自由度,它有4条腿,每条腿有3个自由度。这款机器人配备了以下传感器:

  • 机器人头部的摄像头传感器,提供RGB-D图像
  • 提供地形高度信息的高度扫描传感器
  • 机器人脚部的接触传感器,提供接触信息

本指南对应于orbit/source/standalone/tutorials/04_sensors目录下的add_sensors_on_robot.py脚本。让我们先搂一眼完整的代码

# Copyright (c) 2022-2024, The ORBIT Project Developers.
# All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause"""
This script demonstrates how to add and simulate on-board sensors for a robot.We add the following sensors on the quadruped robot, ANYmal-C (ANYbotics):* USD-Camera: This is a camera sensor that is attached to the robot's base.
* Height Scanner: This is a height scanner sensor that is attached to the robot's base.
* Contact Sensor: This is a contact sensor that is attached to the robot's feet... code-block:: bash# Usage./orbit.sh -p source/standalone/tutorials/04_sensors/add_sensors_on_robot.py"""from __future__ import annotations"""Launch Isaac Sim Simulator first."""import argparsefrom omni.isaac.orbit.app import AppLauncher# add argparse arguments
parser = argparse.ArgumentParser(description="Tutorial on adding sensors on a robot.")
parser.add_argument("--num_envs", type=int, default=2, help="Number of environments to spawn.")
# 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"""Rest everything follows."""import torch
import tracebackimport carbimport omni.isaac.orbit.sim as sim_utils
from omni.isaac.orbit.assets import ArticulationCfg, AssetBaseCfg
from omni.isaac.orbit.scene import InteractiveScene, InteractiveSceneCfg
from omni.isaac.orbit.sensors import CameraCfg, ContactSensorCfg, RayCasterCfg, patterns
from omni.isaac.orbit.utils import configclass##
# Pre-defined configs
##
from omni.isaac.orbit_assets.anymal import ANYMAL_C_CFG  # isort: skip@configclass
class SensorsSceneCfg(InteractiveSceneCfg):"""Design the scene with sensors on the robot."""# ground planeground = AssetBaseCfg(prim_path="/World/defaultGroundPlane", spawn=sim_utils.GroundPlaneCfg())# lightsdome_light = AssetBaseCfg(prim_path="/World/Light", spawn=sim_utils.DomeLightCfg(intensity=3000.0, color=(0.75, 0.75, 0.75)))# robotrobot: ArticulationCfg = ANYMAL_C_CFG.replace(prim_path="{ENV_REGEX_NS}/Robot")# sensorscamera = CameraCfg(prim_path="{ENV_REGEX_NS}/Robot/base/front_cam",update_period=0.1,height=480,width=640,data_types=["rgb", "distance_to_image_plane"],spawn=sim_utils.PinholeCameraCfg(focal_length=24.0, focus_distance=400.0, horizontal_aperture=20.955, clipping_range=(0.1, 1.0e5)),offset=CameraCfg.OffsetCfg(pos=(0.510, 0.0, 0.015), rot=(0.5, -0.5, 0.5, -0.5), convention="ros"),)height_scanner = RayCasterCfg(prim_path="{ENV_REGEX_NS}/Robot/base",update_period=0.02,offset=RayCasterCfg.OffsetCfg(pos=(0.0, 0.0, 20.0)),attach_yaw_only=True,pattern_cfg=patterns.GridPatternCfg(resolution=0.1, size=[1.6, 1.0]),debug_vis=True,mesh_prim_paths=["/World/defaultGroundPlane"],)contact_forces = ContactSensorCfg(prim_path="{ENV_REGEX_NS}/Robot/.*_FOOT", update_period=0.0, history_length=6, debug_vis=True)def run_simulator(sim: sim_utils.SimulationContext,scene: InteractiveScene,
):"""Run the simulator."""# Define simulation steppingsim_dt = sim.get_physics_dt()sim_time = 0.0count = 0# Simulate physicswhile simulation_app.is_running():# Resetif count % 500 == 0:# reset countercount = 0# reset the scene entities# root state# we offset the root state by the origin since the states are written in simulation world frame# if this is not done, then the robots will be spawned at the (0, 0, 0) of the simulation worldroot_state = scene["robot"].data.default_root_state.clone()root_state[:, :3] += scene.env_originsscene["robot"].write_root_state_to_sim(root_state)# set joint positions with some noisejoint_pos, joint_vel = (scene["robot"].data.default_joint_pos.clone(),scene["robot"].data.default_joint_vel.clone(),)joint_pos += torch.rand_like(joint_pos) * 0.1scene["robot"].write_joint_state_to_sim(joint_pos, joint_vel)# clear internal buffersscene.reset()print("[INFO]: Resetting robot state...")# Apply default actions to the robot# -- generate actions/commandstargets = scene["robot"].data.default_joint_pos# -- apply action to the robotscene["robot"].set_joint_position_target(targets)# -- write data to simscene.write_data_to_sim()# perform stepsim.step()# update sim-timesim_time += sim_dtcount += 1# update buffersscene.update(sim_dt)# print information from the sensorsprint("-------------------------------")print(scene["camera"])print("Received shape of rgb   image: ", scene["camera"].data.output["rgb"].shape)print("Received shape of depth image: ", scene["camera"].data.output["distance_to_image_plane"].shape)print("-------------------------------")print(scene["height_scanner"])print("Received max height value: ", torch.max(scene["height_scanner"].data.ray_hits_w[..., -1]).item())print("-------------------------------")print(scene["contact_forces"])print("Received max contact force of: ", torch.max(scene["contact_forces"].data.net_forces_w).item())def main():"""Main function."""# Initialize the simulation contextsim_cfg = sim_utils.SimulationCfg(dt=0.005, substeps=1)sim = sim_utils.SimulationContext(sim_cfg)# Set main camerasim.set_camera_view(eye=[3.5, 3.5, 3.5], target=[0.0, 0.0, 0.0])# design scenescene_cfg = SensorsSceneCfg(num_envs=args_cli.num_envs, env_spacing=2.0)scene = InteractiveScene(scene_cfg)# Play the simulatorsim.reset()# Now we are ready!print("[INFO]: Setup complete...")# Run the simulatorrun_simulator(sim, scene)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()

代码解析

与之前我们在场景中添加资产的教程类似,传感器也是通过场景配置添加到场景中的。所有的传感器都继承自sensors.SensorBase类,并通过各自的配置类进行配置。每个传感器实例都可以定义自己的更新周期,即传感器更新的频率。更新周期通过sensors.SensorBaseCfg.update_period属性以秒为单位指定。

根据指定的路径和传感器类型,传感器会被附加到场景中的原始图元(prims)上。传感器可能直接和在场景中已创建的原始图元关联,或者可能被附加到一个已存在的原始图元上。例如,摄像头传感器会附加在一个已经创建好的原始图元上,而对于接触传感器,激活中的接触报告是刚体原始图元上的一个属性。

接下来,我们将介绍如何使用不同的传感器以及如何配置。要了解更多关于它们的描述,请查看sensors模块。

摄像头传感器 (Camera sensor)

摄像头是使用sensors.CameraCfg类来定义的。它基于USD摄像头传感器,不同的数据类型由Omniverse Replicator API来捕获。由于摄像头在场景中有对应的原始图元(prim),所以在指定的原始图元路径上会创建原始图元。

摄像头传感器的配置包括以下参数:

  • spawn:创建的USD摄像头类型。可以是PinholeCameraCfg(针孔摄像头配置)或FisheyeCameraCfg(鱼眼摄像头配置)。

  • offset:摄像头传感器相对于父原始图元的偏移。

  • data_types:要捕获的数据类型。可以是rgb、distance_to_image_plane(到图像平面的距离)、normals(法线)或其他USD摄像头传感器支持的类型。

为了将RGB-D摄像头传感器附加到机器人的头部,我们指定了一个相对于机器人基座的偏移(offset)。偏移是相对于基座指定的平移和旋转,以及偏移的指定方式。

接下来,我们来看如何使用摄像头传感器配置。我们将更新周期设置为0.1秒,这意味着摄像头传感器以10Hz的频率更新。原始图元路径表达式设置为{ENV_REGEX_NS}/Robot/base/front_cam,其中{ENV_REGEX_NS}是环境命名空间,"Robot"是机器人的名称,"base"是摄像头附加的原始图元的名称,而"front_cam"是与摄像头传感器关联的原始图元的名称。

高度扫描仪(scanner)

高度扫描仪作为一种虚拟传感器,通过使用NVIDIA Warp的光线投射内核来实现。通过sensors.RayCasterCfg,我们可以指定要投射的光线模式以及要对哪些网格进行光线投射。由于它们是虚拟传感器,在场景中没有相应的原始物体(prims)被创建。相反,它们附加到场景中的一个原始物体上,这用于指定传感器的位置。

在本指南中,基于光线投射的高度扫描仪附加到机器人的基座上。光线的模式使用pattern属性指定。对于均匀网格模式,我们使用GridPatternCfg指定模式。由于我们只关心高度信息,我们不需要考虑机器人的滚转和俯仰。因此,我们将attach_yaw_only设置为true。

对于高度扫描仪,我们可以可视化光线击中网格的点。这是通过将debug_vis属性设置为true来完成的。

高度扫描仪的整个配置如下:

   height_scanner = RayCasterCfg(prim_path="{ENV_REGEX_NS}/Robot/base",update_period=0.02,offset=RayCasterCfg.OffsetCfg(pos=(0.0, 0.0, 20.0)),attach_yaw_only=True,pattern_cfg=patterns.GridPatternCfg(resolution=0.1, size=[1.6, 1.0]),debug_vis=True,mesh_prim_paths=["/World/defaultGroundPlane"],)

接触传感器 (Contact sensor)

接触传感器利用PhysX的接触报告API来获取机器人与环境的接触信息。由于它依赖于PhysX,接触传感器期望在机器人的刚体上启用接触报告API。这可以通过在资产配置中设置activate_contact_sensors为true来完成。

通过sensors.ContactSensorCfg,可以指定我们想要获取接触信息的原始物体(prims)。可以设置额外的标志以获取更多关于接触的信息,例如接触空中时间、过滤原始物体之间的接触力等。

在本指南中,我们将接触传感器附加到机器人的脚上。机器人的脚被命名为"LF_FOOT"、“RF_FOOT”、“LH_FOOT"和"RF_FOOT”。我们传递一个正则表达式".*_FOOT"来简化原始物体路径的指定。这个正则表达式匹配所有以"_FOOT"结尾的原始物体。

我们将更新周期设置为0,以使传感器与模拟以相同的频率更新。此外,对于接触传感器,我们可以指定要存储的接触信息的历史长度。对于这个教程,我们将历史长度设置为6,这意味着存储了最后6个模拟步骤的接触信息。

接触传感器的整个配置如下:

    contact_forces = ContactSensorCfg(prim_path="{ENV_REGEX_NS}/Robot/.*_FOOT", update_period=0.0, history_length=6, debug_vis=True)

运行模拟循环

与使用资产时相似,传感器的缓冲区和物理句柄只有在播放模拟时才会初始化,即,在创建场景后调用sim.reset()是很重要的。

    # Play the simulatorsim.reset()

除此之外,模拟循环与之前的指南类似。传感器作为场景更新的一部分进行更新,它们内部处理基于它们更新周期的缓冲区更新。

可以通过它们的data属性访问传感器的数据。作为示例,我们展示如何访问本教程中创建的不同传感器的数据:

        # print information from the sensorsprint("-------------------------------")print(scene["camera"])print("Received shape of rgb   image: ", scene["camera"].data.output["rgb"].shape)print("Received shape of depth image: ", scene["camera"].data.output["distance_to_image_plane"].shape)print("-------------------------------")print(scene["height_scanner"])print("Received max height value: ", torch.max(scene["height_scanner"].data.ray_hits_w[..., -1]).item())print("-------------------------------")print(scene["contact_forces"])print("Received max contact force of: ", torch.max(scene["contact_forces"].data.net_forces_w).item())

代码运行

现在让我们运行脚本并查看结果:

./orbit.sh -p source/standalone/tutorials/04_sensors/add_sensors_on_robot.py --num_envs 2

在这里插入图片描述

这个命令应该会打开一个带有地面平面、灯光和两个四足机器人的舞台。在机器人周围,应该会看到红色的球体,这些球体表示光线击中网格的点。另外,你可以切换视口到摄像机视图,以查看摄像头传感器捕获的RGB图像。请查看这里以了解如何切换视口到摄像机视图的更多信息。

要停止模拟,可以关闭窗口,或在终端中按Ctrl+C。

虽然在这个教程中,我们讲解了创建和使用不同的传感器,但在sensors模块中还有许多其他传感器可用。我们在source/standalone/tutorials/04_sensors目录中包含了使用这些传感器的示例。这些脚本可以使用以下命令运行:

# Frame Transformer
./orbit.sh -p source/standalone/tutorials/04_sensors/run_frame_transformer.py# Ray Caster
./orbit.sh -p source/standalone/tutorials/04_sensors/run_ray_caster.py# Ray Caster Camera
./orbit.sh -p source/standalone/tutorials/04_sensors/run_ray_caster_camera.py# USD Camera
./orbit.sh -p source/standalone/tutorials/04_sensors/run_usd_camera.py

愿本文除一切机器人模拟器苦

以上

这篇关于Orbit 使用指南 10|在机器人上安装传感器 | Isaac Sim | Omniverse的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/840999

相关文章

最详细安装 PostgreSQL方法及常见问题解决

《最详细安装PostgreSQL方法及常见问题解决》:本文主要介绍最详细安装PostgreSQL方法及常见问题解决,介绍了在Windows系统上安装PostgreSQL及Linux系统上安装Po... 目录一、在 Windows 系统上安装 PostgreSQL1. 下载 PostgreSQL 安装包2.

Maven如何手动安装依赖到本地仓库

《Maven如何手动安装依赖到本地仓库》:本文主要介绍Maven如何手动安装依赖到本地仓库问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、下载依赖二、安装 JAR 文件到本地仓库三、验证安装四、在项目中使用该依赖1、注意事项2、额外提示总结一、下载依赖登

如何在Mac上安装并配置JDK环境变量详细步骤

《如何在Mac上安装并配置JDK环境变量详细步骤》:本文主要介绍如何在Mac上安装并配置JDK环境变量详细步骤,包括下载JDK、安装JDK、配置环境变量、验证JDK配置以及可选地设置PowerSh... 目录步骤 1:下载JDK步骤 2:安装JDK步骤 3:配置环境变量1. 编辑~/.zshrc(对于zsh

如何在pycharm安装torch包

《如何在pycharm安装torch包》:本文主要介绍如何在pycharm安装torch包方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录在pycharm安装torch包适http://www.chinasem.cn配于我电脑的指令为适用的torch包为总结在p

在PyCharm中安装PyTorch、torchvision和OpenCV详解

《在PyCharm中安装PyTorch、torchvision和OpenCV详解》:本文主要介绍在PyCharm中安装PyTorch、torchvision和OpenCV方式,具有很好的参考价值,... 目录PyCharm安装PyTorch、torchvision和OpenCV安装python安装PyTor

Python Transformer 库安装配置及使用方法

《PythonTransformer库安装配置及使用方法》HuggingFaceTransformers是自然语言处理(NLP)领域最流行的开源库之一,支持基于Transformer架构的预训练模... 目录python 中的 Transformer 库及使用方法一、库的概述二、安装与配置三、基础使用:Pi

如何解决mmcv无法安装或安装之后报错问题

《如何解决mmcv无法安装或安装之后报错问题》:本文主要介绍如何解决mmcv无法安装或安装之后报错问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录mmcv无法安装或安装之后报错问题1.当我们运行YOwww.chinasem.cnLO时遇到2.找到下图所示这里3.

Python 安装和配置flask, flask_cors的图文教程

《Python安装和配置flask,flask_cors的图文教程》:本文主要介绍Python安装和配置flask,flask_cors的图文教程,本文通过图文并茂的形式给大家介绍的非常详细,... 目录一.python安装:二,配置环境变量,三:检查Python安装和环境变量,四:安装flask和flas

Win11安装PostgreSQL数据库的两种方式详细步骤

《Win11安装PostgreSQL数据库的两种方式详细步骤》PostgreSQL是备受业界青睐的关系型数据库,尤其是在地理空间和移动领域,:本文主要介绍Win11安装PostgreSQL数据库的... 目录一、exe文件安装 (推荐)下载安装包1. 选择操作系统2. 跳转到EDB(PostgreSQL 的

Python Websockets库的使用指南

《PythonWebsockets库的使用指南》pythonwebsockets库是一个用于创建WebSocket服务器和客户端的Python库,它提供了一种简单的方式来实现实时通信,支持异步和同步... 目录一、WebSocket 简介二、python 的 websockets 库安装三、完整代码示例1.