当前位置: 首页>>代码示例>>Python>>正文


Python LeafSystem._DoPublish方法代码示例

本文整理汇总了Python中pydrake.systems.framework.LeafSystem._DoPublish方法的典型用法代码示例。如果您正苦于以下问题:Python LeafSystem._DoPublish方法的具体用法?Python LeafSystem._DoPublish怎么用?Python LeafSystem._DoPublish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pydrake.systems.framework.LeafSystem的用法示例。


在下文中一共展示了LeafSystem._DoPublish方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _DoPublish

# 需要导入模块: from pydrake.systems.framework import LeafSystem [as 别名]
# 或者: from pydrake.systems.framework.LeafSystem import _DoPublish [as 别名]
 def _DoPublish(self, context, events):
     # Call base method to ensure we do not get recursion.
     LeafSystem._DoPublish(self, context, events)
     # N.B. We do not test for a singular call to `DoPublish`
     # (checking `assertFalse(self.called_publish)` first) because
     # the above `_DeclareInitializationEvent` will call both its
     # callback and this event when invoked via
     # `Simulator::Initialize` from `call_leaf_system_overrides`,
     # even when we explicitly say not to publish at initialize.
     self.called_publish = True
开发者ID:naveenoid,项目名称:drake,代码行数:12,代码来源:custom_test.py

示例2: test_deprecated_protected_aliases

# 需要导入模块: from pydrake.systems.framework import LeafSystem [as 别名]
# 或者: from pydrake.systems.framework.LeafSystem import _DoPublish [as 别名]
    def test_deprecated_protected_aliases(self):
        """Tests a subset of protected aliases, pursuant to #9651."""

        class OldSystem(LeafSystem):
            def __init__(self):
                LeafSystem.__init__(self)
                self.called_publish = False
                # Check a non-overridable method
                with catch_drake_warnings(expected_count=1):
                    self._DeclareVectorInputPort("x", BasicVector(1))

            def _DoPublish(self, context, events):
                self.called_publish = True

        # Ensure old overrides are still used
        system = OldSystem()
        context = system.CreateDefaultContext()
        with catch_drake_warnings(expected_count=1):
            system.Publish(context)
        self.assertTrue(system.called_publish)

        # Ensure documentation doesn't duplicate stuff.
        with catch_drake_warnings(expected_count=1):
            self.assertIn("deprecated", LeafSystem._DoPublish.__doc__)
        # This will warn both on (a) calling the method and (b) on the
        # invocation of the override.
        with catch_drake_warnings(expected_count=2):
            LeafSystem._DoPublish(system, context, [])

        class AccidentallyBothSystem(LeafSystem):
            def __init__(self):
                LeafSystem.__init__(self)
                self.called_old_publish = False
                self.called_new_publish = False

            def DoPublish(self, context, events):
                self.called_new_publish = True

            def _DoPublish(self, context, events):
                self.called_old_publish = True

        system = AccidentallyBothSystem()
        context = system.CreateDefaultContext()
        # This will trigger no deprecations, as the newer publish is called.
        system.Publish(context)
        self.assertTrue(system.called_new_publish)
        self.assertFalse(system.called_old_publish)
开发者ID:weiqiao,项目名称:drake,代码行数:49,代码来源:custom_test.py

示例3: _DoPublish

# 需要导入模块: from pydrake.systems.framework import LeafSystem [as 别名]
# 或者: from pydrake.systems.framework.LeafSystem import _DoPublish [as 别名]
    def _DoPublish(self, context, event):
        # TODO(russt): Change this to declare a periodic event with a
        # callback instead of overriding _DoPublish, pending #9992.
        LeafSystem._DoPublish(self, context, event)

        pose_bundle = self.EvalAbstractInput(context, 0).get_value()

        for frame_i in range(pose_bundle.get_num_poses()):
            # SceneGraph currently sets the name in PoseBundle as
            #    "get_source_name::frame_name".
            [source_name, frame_name] = pose_bundle.get_name(frame_i)\
                .split("::")
            model_id = pose_bundle.get_model_instance_id(frame_i)
            # The MBP parsers only register the plant as a nameless source.
            # TODO(russt): Use a more textual naming convention here?
            self.vis[self.prefix][source_name][str(model_id)][frame_name]\
                .set_transform(pose_bundle.get_pose(frame_i).matrix())
开发者ID:mposa,项目名称:drake,代码行数:19,代码来源:meshcat_visualizer.py

示例4: _DoPublish

# 需要导入模块: from pydrake.systems.framework import LeafSystem [as 别名]
# 或者: from pydrake.systems.framework.LeafSystem import _DoPublish [as 别名]
    def _DoPublish(self, context, event):
        LeafSystem._DoPublish(self, context, event)
        point_cloud_P = self.EvalAbstractInput(context, 0).get_value()

        # `Q` is a point in the point cloud.
        p_PQs = point_cloud_P.xyzs()
        # Use only valid points.
        valid = np.logical_not(np.isnan(p_PQs))
        valid = np.all(valid, axis=0)  # Reduce along XYZ axis.
        p_PQs = p_PQs[:, valid]
        if point_cloud_P.has_rgbs():
            rgbs = point_cloud_P.rgbs()[:, valid]
        else:
            # Need manual broadcasting.
            count = p_PQs.shape[1]
            rgbs = np.tile(np.array([self._default_rgb]).T, (1, count))
        # pydrake `PointCloud.rgbs()` are on [0..255], while meshcat
        # `PointCloud` colors are on [0..1].
        rgbs = rgbs / 255.  # Do not use in-place so we can promote types.
        # Send to meshcat.
        self._meshcat_viz[self._name].set_object(g.PointCloud(p_PQs, rgbs))
        self._meshcat_viz[self._name].set_transform(self._X_WP.matrix())
开发者ID:rpoyner-tri,项目名称:drake,代码行数:24,代码来源:meshcat_visualizer.py

示例5: _DoPublish

# 需要导入模块: from pydrake.systems.framework import LeafSystem [as 别名]
# 或者: from pydrake.systems.framework.LeafSystem import _DoPublish [as 别名]
 def _DoPublish(self, context, event):
     LeafSystem._DoPublish(self, context, event)
     pose_bundle = self.EvalAbstractInput(context, 0).get_value()
     X_WB_map = self._get_pose_map(pose_bundle)
     self._draw_contact_forces(context, X_WB_map)
开发者ID:avalenzu,项目名称:drake,代码行数:7,代码来源:meshcat_visualizer.py


注:本文中的pydrake.systems.framework.LeafSystem._DoPublish方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。