首页/文章/ 详情

一个有意思的东西-开源物理仿真引擎newton-Physics

4月前浏览1550
最近关注到了一个很有意思的东西是Newton Physics。这里的newton并不是非线性有限元中的newton迭代,而是 NVIDIA Warp 和 OpenUSD 的开源、可扩展物理引擎,由 NVIDIA、Google DeepMind 和 Disney Research 共同开发,并由 Linux 基金会管理,旨在推动机器人学习与开发的进步。
很显然,这个引擎的名字newton就表明了其仿真的“物理性”。众所周知,牛顿三大定律在真实物理环境中至关重要。一定程度上掌握了牛顿三大定律,可以说就掌握了基本的物理逻辑。在刘慈欣的短篇小说《乡村教师》中,罹患绝症的乡村教师李宝库在临终之际要求懵懂的孩子们背下他们不能理解的牛顿力学三定律。神一般的外星人在清扫战场时鉴定着沿途行星的文明等级,被随机抽作地球样本的孩子们面对一系列测试题时无动于衷,直到正确答出了牛顿定律,才证明了地球值得保存,从而拯救了地球。
在Newton Physics官网中简要介绍了这个引擎的工作原理:物理学在机器人仿真中发挥着至关重要的作用,为在现实环境中准确虚拟呈现机器人行为和交互奠定了基础。
准确模拟机器人行为依赖于遵循基本的物理定律,包括质量和动量守恒、刚体和软体动力学、接触和摩擦以及执行器和传感器建模。这些原则用于预测物理多体系统 (包括机器人) 在各种场景和环境中的行为方式。基于 NVIDIA Warp(一个用于构建与加速仿真和空间计算的开发者框架),Newton 使机器人能够在安全的虚拟环境中获取并提升物理智能,并兼容 MuJoCo Playground 和 NVIDIA Isaac™ Lab 等机器人学习框架。
这表明,newton physics是基于基本的物理定律而非仅仅是视觉效果要求而进行物理仿真的,这与我们CAE中的仿真,可以说是存在一定的关联性的。鉴于目前对这个引擎了解不深,下面仅仅介绍下其基本使用。
这个引擎需要的配置需求很普通,即使是常规的普通个人台式机甚至笔记本,都可以直接使用:
 
 
基本上,需要的就是英伟达的Gpu,cuda和python。有了这三件,我们就可以使用这个引擎了,安装也很简单:
打开命令行浏览器,输入以下命令:
pip install "newton[examples]"
 
 
就安装好了引擎对应需要安装的组件,装完之后就可以运行官方提供的示例了:
python -m newton.examples basic_pendulum
 
 
运行后,就会出现对应的仿真动画:
这是一个两个刚体杆在重力下摆动的仿真,如果注意观察一段时间,会发现其摆动幅度越来越小,表明这其中还施加了阻尼。
同时,我们也可以查看到定义这个仿真的newton Physics的源代码:
























































































































# SPDX-FileCopyrightText: Copyright (c) 2025 The Newton Developers# SPDX-License-Identifier: Apache-2.0############################################################################ Example Basic Pendulum## Shows how to set up a simulation of a simple double pendulum using the# newton.ModelBuilder() class.## Command: python -m newton.examples basic_pendulum############################################################################import warp as wpimport newtonimport newton.examplesclass Example:    def __init__(self, viewer, args):        # setup simulation parameters first        self.fps = 100        self.frame_dt = 1.0 / self.fps        self.sim_time = 0.0        self.sim_substeps = 10        self.sim_dt = self.frame_dt / self.sim_substeps        self.viewer = viewer        self.args = args        builder = newton.ModelBuilder()        hx = 1.0        hy = 0.1        hz = 0.1        # create first link        link_0 = builder.add_link()        builder.add_shape_box(link_0, hx=hx, hy=hy, hz=hz)        link_1 = builder.add_link()        builder.add_shape_box(link_1, hx=hx, hy=hy, hz=hz)        # add joints        rot = wp.quat_from_axis_angle(wp.vec3(0.00.01.0), -wp.pi * 0.5)        j0 = builder.add_joint_revolute(            parent=-1,            child=link_0,            axis=wp.vec3(0.01.00.0),            # rotate pendulum around the z-axis to appear sideways to the viewer            parent_xform=wp.transform(p=wp.vec3(0.00.05.0), q=rot),            child_xform=wp.transform(p=wp.vec3(-hx, 0.00.0), q=wp.quat_identity()),        )        j1 = builder.add_joint_revolute(            parent=link_0,            child=link_1,            axis=wp.vec3(0.01.00.0),            parent_xform=wp.transform(p=wp.vec3(hx, 0.00.0), q=wp.quat_identity()),            child_xform=wp.transform(p=wp.vec3(-hx, 0.00.0), q=wp.quat_identity()),        )        # Create articulation from joints        builder.add_articulation([j0, j1], label="pendulum")        # add ground plane        builder.add_ground_plane()        # finalize model        self.model = builder.finalize()        self.solver = newton.solvers.SolverXPBD(self.model)        self.state_0 = self.model.state()        self.state_1 = self.model.state()        self.control = self.model.control()        # not required for MuJoCo, but required for other solvers        newton.eval_fk(self.model, self.model.joint_q, self.model.joint_qd, self.state_0)        self.contacts = self.model.contacts()        self.viewer.set_model(self.model)        self.capture()    def capture(self):        if wp.get_device().is_cuda:            with wp.ScopedCapture() as capture:                self.simulate()            self.graph = capture.graph        else:            self.graph = None    def simulate(self):        for _ in range(self.sim_substeps):            self.state_0.clear_forces()            # apply forces to the model            self.viewer.apply_forces(self.state_0)            self.model.collide(self.state_0, self.contacts)            self.solver.step(self.state_0, self.state_1, self.control, self.contacts, self.sim_dt)            # swap states            self.state_0, self.state_1 = self.state_1, self.state_0    def step(self):        if self.graph:            wp.capture_launch(self.graph)        else:            self.simulate()        self.sim_time += self.frame_dt    def test_final(self):        # rough check that the pendulum links are in the correct area        newton.examples.test_body_state(            self.model,            self.state_0,            "pendulum links in correct area",            lambda q, qd: abs(q[0]) < 1e-5 and abs(q[1]) < 1.0 and q[2] < 5.0 and q[2] > 0.0,            [01],        )        def check_velocities(_, qd):            # velocity outside the plane of the pendulum should be close to zero            check = abs(qd[0]) < 1e-4 and abs(qd[6]) < 1e-4            # velocity in the plane of the pendulum should be reasonable            check = check and abs(qd[1]) < 10.0 and abs(qd[2]) < 5.0 and abs(qd[3]) < 10.0 and abs(qd[4]) < 10.0            return check        newton.examples.test_body_state(            self.model,            self.state_0,            "pendulum links have reasonable velocities",            check_velocities,            [01],        )    def render(self):        self.viewer.begin_frame(self.sim_time)        self.viewer.log_state(self.state_0)        self.viewer.log_contacts(self.contacts, self.state_0)        self.viewer.end_frame()if __name__ == "__main__":    # Parse arguments and initialize viewer    viewer, args = newton.examples.init()    # Create viewer and run    example = Example(viewer, args)    newton.examples.run(example, args)
十分简洁,仅仅120行代码就完成了这样的仿真。
当然,我们也可以运行更复杂的仿真案例:
总之,newton Physics还有很多东西待我们去挖掘,在当前具身智能火爆的风口下,英伟达等公司强推物理AI概念,知名国产CAE软件云道智造都改名云道智能拥抱物理AI仿真,newton Physics也许能够成为一个对我们十分有用的工具。以上,即是本文全部内容,感谢阅读!
【全文完】

来源:有限元术
ACTSTEPS非线性UGpythonUM机器人
著作权归作者所有,欢迎分享,未经许可,不得转载
首次发布时间:2026-04-21
最近编辑:4月前
寒江雪_123
硕士 | cae工程师 签名征集中
获赞 54粉丝 120文章 92课程 9
点赞
收藏
作者推荐
未登录
还没有评论
课程
培训
服务
行家
VIP会员 学习计划 福利任务
下载APP
联系我们
帮助与反馈