.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/10_animation/viz_robot_arm_animation.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_10_animation_viz_robot_arm_animation.py: =================== Arm Robot Animation =================== Tutorial on making a robot arm animation in FURY. .. GENERATED FROM PYTHON SOURCE LINES 8-21 .. code-block:: Python import numpy as np import fury scene = fury.window.Scene() showm = fury.window.ShowManager( scene, size=(900, 768), reset_camera=False, order_transparent=True ) showm.initialize() .. rst-class:: sphx-glr-script-out .. code-block:: none /opt/homebrew/Caskroom/miniforge/base/envs/py39/lib/python3.9/site-packages/sphinx_gallery/gen_rst.py:722: UserWarning: We'll no longer accept the way you call the __init__ function in future versions of FURY. Here's how to call the Function __init__: __init__(self_value, scene='value', title='value', size='value', png_magnify='value', reset_camera='value', order_transparent='value', interactor_style='value', stereo='value', multi_samples='value', max_peels='value', occlusion_ratio='value') exec(self.code, self.fake_main.__dict__) .. GENERATED FROM PYTHON SOURCE LINES 22-23 Creating robot arm components .. GENERATED FROM PYTHON SOURCE LINES 23-45 .. code-block:: Python base = fury.actor.cylinder( np.array([[0, 0, 0]]), np.array([[0, 1, 0]]), colors=(0, 1, 0), radius=1 ) main_arm = fury.actor.box(np.array([[0, 0, 0]]), colors=(1, 0.5, 0), scales=(12, 1, 1)) sub_arm = fury.actor.box( np.array([[0, 0, 0]]), colors=(0, 0.5, 0.8), scales=(8, 0.7, 0.7) ) joint_1 = fury.actor.sphere( np.array([[0, 0, 0]]), colors=np.array([1, 0, 1]), radii=1.2 ) joint_2 = fury.actor.sphere(np.array([[0, 0, 0]]), colors=np.array([1, 0, 1])) end = fury.actor.cone( np.array([[0, 0, 0]]), np.array([[1, 0, 0]]), np.array([[1, 0, 0]]), heights=2.2, resolution=6, ) .. GENERATED FROM PYTHON SOURCE LINES 46-47 Setting the center of both shafts to the beginning. .. GENERATED FROM PYTHON SOURCE LINES 47-50 .. code-block:: Python fury.utils.set_actor_origin(main_arm, np.array([-6, 0, 0])) fury.utils.set_actor_origin(sub_arm, np.array([-4, 0, 0])) .. rst-class:: sphx-glr-script-out .. code-block:: none /opt/homebrew/Caskroom/miniforge/base/envs/py39/lib/python3.9/site-packages/sphinx_gallery/gen_rst.py:722: UserWarning: We'll no longer accept the way you call the set_actor_origin function in future versions of FURY. Here's how to call the Function set_actor_origin: set_actor_origin(actor_value, center='value') exec(self.code, self.fake_main.__dict__) .. GENERATED FROM PYTHON SOURCE LINES 51-52 Creating a timeline .. GENERATED FROM PYTHON SOURCE LINES 52-54 .. code-block:: Python timeline = fury.animation.Timeline(playback_panel=True) .. GENERATED FROM PYTHON SOURCE LINES 55-56 Creating animations .. GENERATED FROM PYTHON SOURCE LINES 56-61 .. code-block:: Python main_arm_animation = fury.animation.Animation([main_arm, joint_1], length=2 * np.pi) child_arm_animation = fury.animation.Animation([sub_arm, joint_2]) drill_animation = fury.animation.Animation(end) .. rst-class:: sphx-glr-script-out .. code-block:: none /opt/homebrew/Caskroom/miniforge/base/envs/py39/lib/python3.9/site-packages/sphinx_gallery/gen_rst.py:722: UserWarning: We'll no longer accept the way you call the __init__ function in future versions of FURY. Here's how to call the Function __init__: __init__(self_value, actors='value', length='value', loop='value', motion_path_res='value') exec(self.code, self.fake_main.__dict__) .. GENERATED FROM PYTHON SOURCE LINES 62-63 Adding other Animations in hierarchical order .. GENERATED FROM PYTHON SOURCE LINES 63-67 .. code-block:: Python main_arm_animation.add_child_animation(child_arm_animation) child_arm_animation.add_child_animation(drill_animation) .. GENERATED FROM PYTHON SOURCE LINES 68-69 Creating Arm joints time dependent animation functions. .. GENERATED FROM PYTHON SOURCE LINES 69-83 .. code-block:: Python def rot_main_arm(t): return np.array([np.sin(t / 2) * 180, np.cos(t / 2) * 180, 0]) def rot_sub_arm(t): return np.array([np.sin(t) * 180, np.cos(t) * 70, np.cos(t) * 40]) def rot_drill(t): return np.array([t * 1000, 0, 0]) .. GENERATED FROM PYTHON SOURCE LINES 84-86 Setting timelines (joints) relative position 1- Placing the main arm on the cube static base. .. GENERATED FROM PYTHON SOURCE LINES 86-88 .. code-block:: Python main_arm_animation.set_position(0, np.array([0, 1.3, 0])) .. GENERATED FROM PYTHON SOURCE LINES 89-91 2- Translating the timeline containing the sub arm to the end of the first arm. .. GENERATED FROM PYTHON SOURCE LINES 91-93 .. code-block:: Python child_arm_animation.set_position(0, np.array([12, 0, 0])) .. GENERATED FROM PYTHON SOURCE LINES 94-95 3- Translating the timeline containing the drill to the end of the sub arm. .. GENERATED FROM PYTHON SOURCE LINES 95-97 .. code-block:: Python drill_animation.set_position(0, np.array([8, 0, 0])) .. GENERATED FROM PYTHON SOURCE LINES 98-99 Setting rotation time-based evaluators .. GENERATED FROM PYTHON SOURCE LINES 99-103 .. code-block:: Python main_arm_animation.set_rotation_interpolator(rot_main_arm, is_evaluator=True) child_arm_animation.set_rotation_interpolator(rot_sub_arm, is_evaluator=True) drill_animation.set_rotation_interpolator(rot_drill, is_evaluator=True) .. GENERATED FROM PYTHON SOURCE LINES 104-105 Setting camera position to observe the robot arm. .. GENERATED FROM PYTHON SOURCE LINES 105-107 .. code-block:: Python scene.camera().SetPosition(0, 0, 90) .. GENERATED FROM PYTHON SOURCE LINES 108-109 Adding the base actor to the scene .. GENERATED FROM PYTHON SOURCE LINES 109-111 .. code-block:: Python scene.add(base) .. GENERATED FROM PYTHON SOURCE LINES 112-113 Adding the main parent animation to the Timeline. .. GENERATED FROM PYTHON SOURCE LINES 113-115 .. code-block:: Python timeline.add_animation(main_arm_animation) .. GENERATED FROM PYTHON SOURCE LINES 116-117 Now we add the timeline to the ShowManager .. GENERATED FROM PYTHON SOURCE LINES 117-125 .. code-block:: Python showm.add_animation(timeline) interactive = False if interactive: showm.start() fury.window.record(scene, out_path="viz_robot_arm.png", size=(900, 768)) .. image-sg:: /auto_examples/10_animation/images/sphx_glr_viz_robot_arm_animation_001.png :alt: viz robot arm animation :srcset: /auto_examples/10_animation/images/sphx_glr_viz_robot_arm_animation_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /opt/homebrew/Caskroom/miniforge/base/envs/py39/lib/python3.9/site-packages/sphinx_gallery/gen_rst.py:722: UserWarning: We'll no longer accept the way you call the record function in future versions of FURY. Here's how to call the Function record: record(scene='value', cam_pos='value', cam_focal='value', cam_view='value', out_path='value', path_numbering='value', n_frames='value', az_ang='value', magnification='value', size='value', reset_camera='value', screen_clip='value', stereo='value', verbose='value') exec(self.code, self.fake_main.__dict__) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.115 seconds) .. _sphx_glr_download_auto_examples_10_animation_viz_robot_arm_animation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: viz_robot_arm_animation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: viz_robot_arm_animation.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_