Isaac Sim Docker 中使用 Python 脚本
笔记,记录个人尝试过程
主要目的:
1. 直接在代码中运行仿真程序,并对某传感器帧率进行固定化设置,添加噪声等操作。
2. 试多个场景的并行处理,和多用户/账户在远程Docker中的并行使用。
3. 对车辆模型、车辆动力学等进行精细化处理。
原因:
1. 当前设备不支持多场景多小车多传感器同时运行,硬件不足,需要远程使用别的服务器。
2. 若不支持同时多场景同时运行,可以远程服务器中开一个仿真地图,本机开一个仿真地图。
3. 我觉得不会不支持的...先试试看
尝试了用python独立脚本开启直播流和打开场景,但其它脚本无法同步使用。改,换使用扩展。
Isaac Sim教程07 拓展编程Extension_isaac sim extension-CSDN博客
大佬的博客中,很多代码中的意义都翻译了。
在扩展的ui_builder.py中,只有_setup_scene函数是对场景的具体设置,其它都是些ui界面的设置,和重置场景等功能,场景中已经有了完善的内容,不需要在此处添加机器人和一些执行逻辑,全都注释掉。
def _setup_scene(self):"""LOAD 可加载此实例"""usd_file = "/usd_path"# 加载已有场景open_stage(usd_path = usd_file)world = World()# # 加载ur10e模型# robot_prim_path = "/ur10e"# path_to_robot_usd = "omniverse://localhost/NVIDIA/Assets/Isaac/4.1/Isaac/Robots/UniversalRobots/ur10e/ur10e.usd"# # Do not reload assets when hot reloading. This should only be done while extension is under development.# if not is_prim_path_valid(robot_prim_path):# create_new_stage()# add_reference_to_stage(path_to_robot_usd, robot_prim_path)# else:# print("Robot already on Stage")# # 创建新的舞台# create_new_stage()# # 添加光源到舞台# self._add_light_to_stage()# # 将ur10e机械臂的USD参考添加到舞台# add_reference_to_stage(path_to_robot_usd, robot_prim_path)# # 创建固定的立方体# self._cuboid = FixedCuboid(# "/Scenario/cuboid", position=np.array([0.3, 0.3, 0.5]), size=0.05, color=np.array([255, 0, 0])# ) # # 实例化ur10e机械臂的Articulation# self._articulation = Articulation(robot_prim_path)# 获取世界实例# world = World.instance()# # 添加Articulation和Cuboid到世界中# world.scene.add(self._articulation)# world.scene.add(self._cuboid)
在原本的_setup_scenario函数中,调用了scenario.py中的逻辑,我将此处机械臂的运动逻辑改为了差速驱动轮的计算逻辑。
def _setup_scenario(self):"""原本用来控制机械臂做循环移动(圆周)改成了轮式里程计的发布"""Noneself._reset_scenario()# UI managementself._scenario_state_btn.reset()self._scenario_state_btn.enabled = Trueself._reset_btn.enabled = True
isaac sim 扩展仅支持异步发布 rostopic,这里可看官方教程:在扩展中使用ros:
Custom Message — Omniverse IsaacSim
import asyncio
import rospytry:rospy.init_node("hello", anonymous=True, disable_signals=True, log_level=rospy.ERROR)
except rospy.exceptions.ROSException as e:print("Node has already been initialized, do nothing")async def my_task():from std_msgs.msg import Stringpub = rospy.Publisher("/hello_topic", String, queue_size=10)for frame in range(10):pub.publish("hello world " + str(frame))await asyncio.sleep(1.0)pub.unregister()pub = Noneasyncio.ensure_future(my_task())