ravens/tasks/defs_bags.py
def add_cable_ring(self, env, bag_id=None):
        """Make the cable beads coincide with the vertices of the top ring.

        This should lead to better physics and will make it easy for an
        algorithm to see the bag's top ring. Please see the cable-ring env
        for details, or `scratch/cable_ring_MWE.py`. Notable differences
        (or similarities) between this and `dan_cables.py`:

        (1) We don't need to discretize rotations and manually compute bead
        positions, because the previously created bag 'creates' it for us.

        (2) Beads have anchors with vertices, in addition to constraints with
        adjacent beads.

        (3) Still use `self.cable_bead_IDs` as we want that for the reward.
        """
        num_parts = len(self._top_ring_idxs)
        radius = 0.005
        color = U.COLORS['blue'] + [1]
        beads = []
        bead_positions_l = []
        part_shape = p.createCollisionShape(p.GEOM_BOX, halfExtents=[radius]*3)
        part_visual = p.createVisualShape(p.GEOM_SPHERE, radius=radius*1.5)

        # All tasks OTHER than bag-color-goal use self.bag_id. So if we are not
        # passing it in as an argument, we better have defined self.bag_id to use.
        if bag_id is None:
            bag_id = self.bag_id

        # Fortunately `verts_l` coincides with `self._top_ring_idxs`.
        _, verts_l = p.getMeshData(bag_id, -1, flags=p.MESH_DATA_SIMULATION_MESH)

        # Iterate through parts and create constraints as needed.
        for i in range(num_parts):
            bag_vidx = self._top_ring_idxs[i]
            bead_position = np.float32(verts_l[bag_vidx])
            part_id = p.createMultiBody(0.01, part_shape, part_visual,
                    basePosition=bead_position)
            p.changeVisualShape(part_id, -1, rgbaColor=color)

            if i > 0:
                parent_frame = bead_position - bead_positions_l[-1]
                constraint_id = p.createConstraint(
                        parentBodyUniqueId=beads[-1],
                        parentLinkIndex=-1,
                        childBodyUniqueId=part_id,
                        childLinkIndex=-1,
                        jointType=p.JOINT_POINT2POINT,
                        jointAxis=(0, 0, 0),
                        parentFramePosition=parent_frame,
                        childFramePosition=(0, 0, 0))
                p.changeConstraint(constraint_id, maxForce=100)

            # Make a constraint with i=0. Careful with `parent_frame`!
            if i == num_parts - 1:
                parent_frame = bead_positions_l[0] - bead_position
                constraint_id = p.createConstraint(
                        parentBodyUniqueId=part_id,
                        parentLinkIndex=-1,
                        childBodyUniqueId=beads[0],
                        childLinkIndex=-1,
                        jointType=p.JOINT_POINT2POINT,
                        jointAxis=(0, 0, 0),
                        parentFramePosition=parent_frame,
                        childFramePosition=(0, 0, 0))
                p.changeConstraint(constraint_id, maxForce=100)

            # Create constraint between a bead and certain bag vertices.
            _ = p.createSoftBodyAnchor(
                    softBodyBodyUniqueId=bag_id,
                    nodeIndex=bag_vidx,
                    bodyUniqueId=part_id,
                    linkIndex=-1,)

            # Track beads.
            beads.append(part_id)
            bead_positions_l.append(bead_position)

            # The usual for tracking IDs. Four things to add.
            self.cable_bead_IDs.append(part_id)
            self._IDs[part_id] = f'cable_part_{str(part_id).zfill(2)}'
            env.objects.append(part_id)
            self.object_points[part_id] = np.float32((0, 0, 0)).reshape(3, 1)
Make the cable beads coincide with the vertices of the top ring.

        This should lead to better physics and will make it easy for an
        algorithm to see the bag's top ring. Please see the cable-ring env
        for details, or `scratch/cable_ring_MWE.py`. Notable differences
        (or similarities) between this and `dan_cables.py`:

        (1) We don't need to discretize rotations and manually compute bead
        positions, because the previously created bag 'creates' it for us.

        (2) Beads have anchors with vertices, in addition to constraints with
        adjacent beads.

        (3) Still use `self.cable_bead_IDs` as we want that for the reward.
        
Make the cable beads coincide with the vertices of the top ring.
This should lead to better physics and will make it easy for an
algorithm to see the bag's top ring. Please see the cable-ring env
for details, or `scratch/cable_ring_MWE.py`. Notable differences
(or similarities) between this and `dan_cables.py`.

(1) We don't need to discretize rotations and manually compute bead
positions, because the previously created bag 'creates' it for us.

(2) Beads have anchors with vertices, in addition to constraints with
adjacent beads.

(3) Still use `self.cable_bead_IDs` as we want that for the reward.
Make the cable beads coincide with the vertices of the top ring . This should lead to better physics and will make it easy for an algorithm to see the bag ' s top ring . Please see the cable - ring env for details or ` scratch / cable_ring_MWE . py ` . Notable differences ( or similarities ) between this and ` dan_cables . py ` . ( 1 ) We don ' t need to discretize rotations and manually compute bead positions because the previously created bag ' creates ' it for us . ( 2 ) Beads have anchors with vertices in addition to constraints with adjacent beads . ( 3 ) Still use ` self . cable_bead_IDs ` as we want that for the reward .
def add_cable_ring(self, env, bag_id=None):
        num_parts = len(self._top_ring_idxs)
        radius = 0.005
        color = U.COLORS['blue'] + [1]
        beads = []
        bead_positions_l = []
        part_shape = p.createCollisionShape(p.GEOM_BOX, halfExtents=[radius]*3)
        part_visual = p.createVisualShape(p.GEOM_SPHERE, radius=radius*1.5)
        if bag_id is None:
            bag_id = self.bag_id
        _, verts_l = p.getMeshData(bag_id, -1, flags=p.MESH_DATA_SIMULATION_MESH)
        for i in range(num_parts):
            bag_vidx = self._top_ring_idxs[i]
            bead_position = np.float32(verts_l[bag_vidx])
            part_id = p.createMultiBody(0.01, part_shape, part_visual,
                    basePosition=bead_position)
            p.changeVisualShape(part_id, -1, rgbaColor=color)
            if i > 0:
                parent_frame = bead_position - bead_positions_l[-1]
                constraint_id = p.createConstraint(
                        parentBodyUniqueId=beads[-1],
                        parentLinkIndex=-1,
                        childBodyUniqueId=part_id,
                        childLinkIndex=-1,
                        jointType=p.JOINT_POINT2POINT,
                        jointAxis=(0, 0, 0),
                        parentFramePosition=parent_frame,
                        childFramePosition=(0, 0, 0))
                p.changeConstraint(constraint_id, maxForce=100)
            if i == num_parts - 1:
                parent_frame = bead_positions_l[0] - bead_position
                constraint_id = p.createConstraint(
                        parentBodyUniqueId=part_id,
                        parentLinkIndex=-1,
                        childBodyUniqueId=beads[0],
                        childLinkIndex=-1,
                        jointType=p.JOINT_POINT2POINT,
                        jointAxis=(0, 0, 0),
                        parentFramePosition=parent_frame,
                        childFramePosition=(0, 0, 0))
                p.changeConstraint(constraint_id, maxForce=100)
            _ = p.createSoftBodyAnchor(
                    softBodyBodyUniqueId=bag_id,
                    nodeIndex=bag_vidx,
                    bodyUniqueId=part_id,
                    linkIndex=-1,)
            beads.append(part_id)
            bead_positions_l.append(bead_position)
            self.cable_bead_IDs.append(part_id)
            self._IDs[part_id] = f'cable_part_{str(part_id).zfill(2)}'
            env.objects.append(part_id)
            self.object_points[part_id] = np.float32((0, 0, 0)).reshape(3, 1)
def add_cable_ring ( self , env , bag_id = None ) : num_parts = len ( self . _top_ring_idxs ) radius = 0.005 color = U . COLORS [ 'blue' ] + [ 1 ] beads = [ ] bead_positions_l = [ ] part_shape = p . createCollisionShape ( p . GEOM_BOX , halfExtents = [ radius ] * 3 ) part_visual = p . createVisualShape ( p . GEOM_SPHERE , radius = radius * 1.5 ) if bag_id is None : bag_id = self . bag_id _ , verts_l = p . getMeshData ( bag_id , - 1 , flags = p . MESH_DATA_SIMULATION_MESH ) for i in range ( num_parts ) : bag_vidx = self . _top_ring_idxs [ i ] bead_position = np . float32 ( verts_l [ bag_vidx ] ) part_id = p . createMultiBody ( 0.01 , part_shape , part_visual , basePosition = bead_position ) p . changeVisualShape ( part_id , - 1 , rgbaColor = color ) if i > 0 : parent_frame = bead_position - bead_positions_l [ - 1 ] constraint_id = p . createConstraint ( parentBodyUniqueId = beads [ - 1 ] , parentLinkIndex = - 1 , childBodyUniqueId = part_id , childLinkIndex = - 1 , jointType = p . JOINT_POINT2POINT , jointAxis = ( 0 , 0 , 0 ) , parentFramePosition = parent_frame , childFramePosition = ( 0 , 0 , 0 ) ) p . changeConstraint ( constraint_id , maxForce = 100 ) if i == num_parts - 1 : parent_frame = bead_positions_l [ 0 ] - bead_position constraint_id = p . createConstraint ( parentBodyUniqueId = part_id , parentLinkIndex = - 1 , childBodyUniqueId = beads [ 0 ] , childLinkIndex = - 1 , jointType = p . JOINT_POINT2POINT , jointAxis = ( 0 , 0 , 0 ) , parentFramePosition = parent_frame , childFramePosition = ( 0 , 0 , 0 ) ) p . changeConstraint ( constraint_id , maxForce = 100 ) _ = p . createSoftBodyAnchor ( softBodyBodyUniqueId = bag_id , nodeIndex = bag_vidx , bodyUniqueId = part_id , linkIndex = - 1 , ) beads . append ( part_id ) bead_positions_l . append ( bead_position ) self . cable_bead_IDs . append ( part_id ) self . _IDs [ part_id ] = f'cable_part_{str(part_id).zfill(2)}' env . objects . append ( part_id ) self . object_points [ part_id ] = np . float32 ( ( 0 , 0 , 0 ) ) . reshape ( 3 , 1 )
Make the cable beads coincide with the vertices of the top ring.
Make the cable beads coincide with the vertices of the top ring .
"""Make the cable beads coincide with the vertices of the top ring.

        This should lead to better physics and will make it easy for an
        algorithm to see the bag's top ring. Please see the cable-ring env
        for details, or `scratch/cable_ring_MWE.py`. Notable differences
        (or similarities) between this and `dan_cables.py`:

        (1) We don't need to discretize rotations and manually compute bead
        positions, because the previously created bag 'creates' it for us.

        (2) Beads have anchors with vertices, in addition to constraints with
        adjacent beads.

        (3) Still use `self.cable_bead_IDs` as we want that for the reward.
        """ # All tasks OTHER than bag-color-goal use self.bag_id. So if we are not # passing it in as an argument, we better have defined self.bag_id to use. # Fortunately `verts_l` coincides with `self._top_ring_idxs`. # Iterate through parts and create constraints as needed. # Make a constraint with i=0. Careful with `parent_frame`! # Create constraint between a bead and certain bag vertices. # Track beads. # The usual for tracking IDs. Four things to add.
self
env
bag_id