Exemplo n.º 1
0
    def test_render_to_animation(self):
        scene = Scene()
        actor = RigidDynamic()
        actor.attach_shape(Shape.create_box([0.2] * 3, Material()))
        scene.add_actor(actor)

        viewer = MeshcatViewer(render_to_animation=True, animation_fps=2)
        viewer.add_physx_scene(scene)
        viewer.update()
        viewer.update()
        actor.set_global_pose([1., 2., 3.])
        viewer.update()
        self.assertEqual(
            len(
                list(list(viewer.animation.clips.values())[0].tracks.values())
                [0].frames), 3)
        self.assertEqual(
            len(
                list(list(viewer.animation.clips.values())[0].tracks.values())
                [1].frames), 3)
        pos0 = list(list(
            viewer.animation.clips.values())[0].tracks.values())[0].values[0]
        pos2 = list(list(
            viewer.animation.clips.values())[0].tracks.values())[0].values[2]
        self.assertAlmostEqual(pos0[0], 0.)
        self.assertAlmostEqual(pos0[1], 0.)
        self.assertAlmostEqual(pos0[2], 0.)
        self.assertAlmostEqual(pos2[0], 1.)
        self.assertAlmostEqual(pos2[1], 2.)
        self.assertAlmostEqual(pos2[2], 3.)
Exemplo n.º 2
0
    def test_scene_size(self):
        scene = Scene()
        actor = RigidDynamic()
        actor.attach_shape(Shape.create_box([0.2] * 3, Material()))
        scene.add_actor(actor)

        viewer = MeshcatViewer()
        viewer.add_physx_scene(scene)
        self.assertEqual(len(viewer.actors_and_offsets), 1)
        viewer.clear_physx_scenes()
        self.assertEqual(len(viewer.actors_and_offsets), 0)
Exemplo n.º 3
0
        s.set_user_data(dict(color='tab:grey'))
    elif i in [0, 1, 4, 5]:
        s.set_user_data(dict(color='tab:green'))
    else:
        s.set_user_data(dict(color='green'))

actor.set_global_pose([0.5, -0.5, 1.0])
actor.set_mass(1.)
scene.add_actor(actor)

robot = URDFRobot("franka_panda/panda.urdf", kinematic=False, use_random_collision_colors=True)
robot.attach_root_node_to_pose([0.0, 0.0, 1.0])
q = dict()
for i, value in enumerate([0, -np.pi / 4, 0, -3 * np.pi / 4, 0, np.pi / 2, np.pi / 4]):
    q['panda_joint{}'.format(i + 1)] = value
robot.reset_pose(q)  # reset pose of all links based on default values for joints (0 m or 0 deg)
scene.add_aggregate(robot.get_aggregate())  # add robot into the scene, robot is an aggregate of actors with self


""" Create a viewer and add the scene into it. """
render = MeshcatViewer(wait_for_open=True, open_meshcat=True, show_frames=False)
render.add_physx_scene(scene)

""" Simulate forever. Note, that meschat viewer is always active. """
rate = Rate(120)
while render.is_active:
    robot.update(rate.period())
    scene.simulate(rate.period())
    render.update()
    rate.sleep()