There is no example illustrating how to use robot_object.attach_tool() and display it on the Viewer.screen below, nor how to change the joint and have the end follow the changes. The example below only displays the robot, but not the tool attached to the robotic arm. Could the official provide a corresponding example that displays the robotic arm and end claw on the Viewer, without necessarily using ROS or Rhino for display.
Can you provide an example related to attach_tool and demonstrate how to display and update joint changes in the Viewer, ensuring that the tool at the end follows the changes, without utilizing ROS or other CAD environments。Thankyou very much。
programe:Only Robot is displayed below。
from compas_robots.viewer.scene.robotmodelobject import RobotModelObject
from compas_viewer.components import Slider
from compas_viewer import Viewer
There is no example illustrating how to use robot_object.attach_tool() and display it on the Viewer.screen below, nor how to change the joint and have the end follow the changes. The example below only displays the robot, but not the tool attached to the robotic arm. Could the official provide a corresponding example that displays the robotic arm and end claw on the Viewer, without necessarily using ROS or Rhino for display.
Can you provide an example related to attach_tool and demonstrate how to display and update joint changes in the Viewer, ensuring that the tool at the end follows the changes, without utilizing ROS or other CAD environments。Thankyou very much。
programe:Only Robot is displayed below。
from compas_robots.viewer.scene.robotmodelobject import RobotModelObject from compas_viewer.components import Slider from compas_viewer import Viewer
from compas.datastructures import Mesh from compas.geometry import Frame from compas_robots import RobotModel from compas_robots.model.tool import ToolModel from compas_robots.resources import LocalPackageMeshLoader import compas_fab viewer = Viewer() viewer.renderer.rendermode="lighted" urdf_filename ='./ur5.urdf' model = RobotModel.from_urdf_file(urdf_filename) model.load_geometry(LocalPackageMeshLoader(compas_fab.get("universal_robot"), "ur_description"), precision=5) configuration = model.zero_configuration() robot_object: RobotModelObject = viewer.scene.add(model, show_lines=False, configuration=configuration) # type: ignore viewer.ui.sidedock.show = True ##############attach_tool_model################## mesh = Mesh.from_stl("./vacuum_gripper.stl") frame_t = Frame([0, 0, 0.07], [1, 0, 0], [0, 1, 0]) tool_model = ToolModel(mesh, frame_t, connected_to="wrist_3_link") robot_object.attach_tool_model(tool_model)###TODO not work!!!! viewer.renderer.update() ##############attach_tool_model##################
def make_rotate_function(index): def rotate(slider: Slider, value: int): config = robot_object.configuration config.joint_values[index] = value / 360 2 3.14159 robot_object.update_joints(config) return rotate
for i, joint in enumerate(robot_object.configuration.joint_names): rotate_function = make_rotate_function(i) viewer.ui.sidedock.add(Slider(title=joint, starting_val=0, min_val=-180, max_val=180, step=1, action=rotate_function)) robot_object.update_joints(robot_object.configuration) viewer.show()