4 from pathlib 
import Path
 
    6 import meshcat.geometry 
as g
 
    8 import pinocchio 
as pin
 
   13     rotate = pin.utils.rotate
 
   14     R = rotate(
"x", xyzrpy[3]) @ rotate(
"y", xyzrpy[4]) @ rotate(
"z", xyzrpy[5])
 
   15     p = np.array(xyzrpy[:3])
 
   20 pinocchio_model_dir = Path(__file__).parent.parent / 
"models" 
   22 model_path = pinocchio_model_dir / 
"example-robot-data/robots" 
   23 mesh_dir = pinocchio_model_dir
 
   25 urdf_path = model_path / 
"panda_description/urdf/panda.urdf" 
   26 srdf_path = model_path / 
"panda_description/srdf/panda.srdf" 
   28 robot, collision_model, visual_model = pin.buildModelsFromUrdf(urdf_path, mesh_dir)
 
   29 data = robot.createData()
 
   34     [0.40, 0.0, 0.30, np.pi / 2, 0, 0],
 
   35     [-0.08, -0.0, 0.75, np.pi / 2, 0, 0],
 
   36     [0.23, -0.0, 0.04, np.pi / 2, 0, 0],
 
   40 color = [1.0, 0.2, 0.2, 1.0]  
 
   41 rad, length = 0.1, 0.4  
 
   42 for i, xyzrpy 
in enumerate(oMobs):
 
   43     obs = pin.GeometryObject.CreateCapsule(rad, length)  
 
   44     obs.meshColor = np.array(
 
   50     collision_model.addGeometryObject(obs)  
 
   51     visual_model.addGeometryObject(obs)  
 
   54 collision_model.addAllCollisionPairs()
 
   55 pin.removeCollisionPairs(robot, collision_model, srdf_path)
 
   59 nbodies = collision_model.ngeoms - nobs
 
   60 robotBodies = range(nbodies)
 
   61 envBodies = range(nbodies, nbodies + nobs)
 
   62 for a, b 
in itertools.product(robotBodies, envBodies):
 
   73     viz.initViewer(open=
True)
 
   74 except ImportError 
as err:
 
   76         "Error while initializing the viewer. " 
   77         "It seems you should install Python meshcat" 
   85 q0 = (robot.upperPositionLimit.T + robot.lowerPositionLimit.T) / 2
 
   87 frame = robot.getFrameId(
 
   98     verts, faces = pin.reachableWorkspaceWithCollisionsHull(
 
   99         robot, collision_model, q0, horizon, frame, n_samples, facet_dims
 
  108         from CGAL.CGAL_Polyhedron_3 
import Polyhedron_3
 
  109     except ModuleNotFoundError:
 
  110         print(
"To compute non convex Polytope CGAL library needs to be installed.")
 
  114         return v.x(), v.y(), v.z()
 
  128         Compute the alpha shape of a set of points. (Code thanks to A. Skuric) 
  129         Retrieved from http://blog.thehumangeo.com/2014/05/12/drawing-boundaries-in-python/ 
  131         :param coords : Coordinates of points 
  132         :param alpha: List of alpha values to influence the gooeyness of the border. 
  133         Smaller numbers don't fall inward as much as larger numbers. 
  134         Too large, and you lose everything! 
  135         :return: Shapely.MultiPolygons which is the hull of the input set of points 
  138             bbox_diag = np.linalg.norm(np.max(coords, 0) - np.min(coords, 0))
 
  139             alpha_value = bbox_diag / 5
 
  141             alpha_value = np.mean(alpha)
 
  143         points = [Point_3(pt[0], pt[1], pt[2]) 
for pt 
in coords]  
 
  146         _a = alpha_wrap_3(points, alpha_value, 0.01, Q)  
 
  147         alpha_shape_vertices = np.array(
 
  151         alpha_shape_faces = np.array(
 
  155         return alpha_shape_vertices, alpha_shape_faces
 
  157     verts = pin.reachableWorkspaceWithCollisions(
 
  158         robot, collision_model, q0, horizon, frame, n_samples, facet_dims
 
  164     verts = faces.reshape(-1, 3)
 
  165     faces = np.arange(len(verts)).reshape(-1, 3)
 
  167 print(
"------------------- Display Vertex")
 
  171 poly = g.TriangularMeshGeometry(vertices=verts, faces=faces)
 
  172 viz.viewer[
"poly"].set_object(
 
  173     poly, g.MeshBasicMaterial(color=0x000000, wireframe=
True, linewidth=12, opacity=0.2)
 
  178     viz.viewer[
"poly"].set_object(
 
  180         g.MeshBasicMaterial(color=0x000000, wireframe=
True, linewidth=2, opacity=0.2),