forked from ediaro23/lab
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsetup_meshcat.py
58 lines (46 loc) · 1.84 KB
/
setup_meshcat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 4 11:09:02 2023
@author: stonneau
"""
from utils.meshcat_viewer_wrapper import MeshcatVisualizer # the meshcat visualiser
import sys
from config import USE_MESHCAT, MESHCAT_URL, LEFT_HAND, RIGHT_HAND, CUBE_PLACEMENT_TARGET
from tools import getcubeplacement
FRAME_NAMES = [LEFT_HAND+"frame",RIGHT_HAND+"frame", ]
FRAME_JOINT_NAMES = [LEFT_HAND,RIGHT_HAND]
hook_frames_names_meshcat = [LEFT_HAND+"HookFrame", RIGHT_HAND+"HookFrame" ]
hook_frames_names = ["LARM_HOOK", "RARM_HOOK"]
def addframes(viz):
for framename in FRAME_NAMES:
viz.addFrame(framename, 0.2)
for framename in hook_frames_names_meshcat:
viz.addFrame(framename, 0.2)
def updaterobotframes(viz, robot):
for jointname, framename in zip(FRAME_JOINT_NAMES,FRAME_NAMES):
frameid = robot.model.getFrameId(jointname)
oMframe = robot.data.oMf[frameid]
viz.applyConfiguration(framename,oMframe)
def updatecubeframes(viz, cube):
for hookframename, framenamemeshcat in zip(hook_frames_names,hook_frames_names_meshcat):
viz.applyConfiguration(framenamemeshcat,getcubeplacement(cube,hookframename))
def setupmeshcat(robot, url=MESHCAT_URL):
if USE_MESHCAT:
viz = MeshcatVisualizer(robot, url=url)
#add target
viz.addBox("target", [0.1,0.1,0.1],[0.,0.9,0.,0.5])
viz.applyConfiguration('target', CUBE_PLACEMENT_TARGET)
viz.loadViewerModel()
viz.display(robot.q0)
viz.displayCollisions(False)
viz.displayVisuals(True)
addframes(viz)
return viz
else:
print("MESHCAT viewer is not selected, this method should not be called")
sys.exit(0)
def updatevisuals(viz, robot, cube, q):
updaterobotframes(viz, robot)
updatecubeframes(viz,cube)
viz.display(q)