Hi, I had an idea of visualizing a robot in compas_view2
and its trajectory, with a slider changing the state. However, I have trouble adding a robot mesh in the view.
Knowing that compas_view2
only supports compas.data.Data
, I cannot add compas_fab.robots.Robot
to the view, but only compas.robots.RobotModel
(P.S. compas
and compad_fab
are a bit messy and confusing in this part of the concept for me). Yet, I still cannot put a robot mesh that moves.
- I load the robot and initialized the app:
from compas_view2.app import App
from compas.robots import LocalPackageMeshLoader, RobotModel
import compas_fab
viewer = App()
urdf = compas_fab.get("universal_robot/ur_description/urdf/ur5.urdf")
model = RobotModel.from_urdf_file(urdf)
loader = LocalPackageMeshLoader(compas_fab.get("universal_robot"), "ur_description")
model.load_geometry(loader)
- then, I try to change to model a bit, like scaling and re-configuring:
# Scale not working
model.scale(1000)
# Configure not working
for i in range(6): model.joints[i].position = 1
- last, I view it by
viewer. run()
I can see the robot but it is always keeping this state.
I assume using compas.robots.RobotModel
might not be a good idea, but I cannot figure out how to right this part of the code.
Look forward to any insight and thanks in advance.
1 Like
Below is the example code.
import compas_fab
from compas import json_load
from compas.robots import LocalPackageMeshLoader, RobotModel
from compas_view2.app import App
def robot_viewer(trajectory):
viewer = App(enable_sidebar = True)
# * Add geo to the scene -----------
urdf = compas_fab.get("universal_robot/ur_description/urdf/ur5.urdf")
model = RobotModel.from_urdf_file(urdf)
loader = LocalPackageMeshLoader(compas_fab.get("universal_robot"), "ur_description")
model.load_geometry(loader)
model.scale(1000)
robot_object = viewer.add(model)
# * -------------------------------------------
@viewer.slider(title="Trajectory", maxval=len(trajectory.points) - 1, step=1)
def slide(value):
robot_object.update()
viewer.view.update()
run = False
@viewer.button(text="Confirm")
def click():
nonlocal run
if viewer.confirm("The robot will move!") == True:
run = True
else:
run = False
viewer.run()
if run == False:
exit()
return run
if __name__ == "__main__":
trajectory = json_load(r"src\trajectory_test.json")
run = robot_viewer( trajectory=trajectory)
Hey Zac,
In view2, I recommend manipulate the robot through the RobotObject
which is returned by viewer.add()
, The RobotModel
here is purely for getting the geometry. After added into the scene, you can use .rotate_joint()
function from RobotObject
to update it (Assuming your trajectory is a series of FK joint rotation values). You can also move/rotate/scale the RobotObject like any other object classes in view.