예제 #1
0
 def get_object_child(self, handle, index):
     """
     Get V-REP handle for child object
     """
     error_code, child_handle = vrep.simxGetObjectChild(
         self.client_id, handle, index, vrep.simx_opmode_blocking)
     return child_handle
예제 #2
0
 def _read_handles(self):
     self.handles = []
     return_code, base_handler = vrep.simxGetObjectHandle(
         self.client_id, 'Bioloid', self.opmode)
     t = [base_handler]
     while len(t) > 0:
         h = t.pop()
         index = 0
         return_code, child_handler = vrep.simxGetObjectChild(
             self.client_id, h, index, self.opmode)
         while child_handler != -1:
             self.handles.append(child_handler)
             t.append(child_handler)
             index += 1
             return_code, child_handler = vrep.simxGetObjectChild(
                 self.client_id, h, index, self.opmode)
예제 #3
0
def get_object_child_handle(clientID, objectHandle, childIndex):
    ret, childObjectHandle = vrep.simxGetObjectChild(
        clientID=clientID,
        parentObjectHandle=objectHandle,
        childIndex=childIndex,
        operationMode=vrep.simx_opmode_oneshot_wait)
    check_return_ok(ret)
    return childObjectHandle
예제 #4
0
def getChildren(object,clientID):
    children = []
    index = 0
    child = None
    while child != -1:
        child = vrep.simxGetObjectChild(clientID,object,index,vrep.simx_opmode_oneshot_wait)
        if child != -1:
            children.append(child)
    return children
예제 #5
0
def get_joints(robot_handle):
    '''
    This is a very costly function due to recursive blocking calls.
    Need to be optimized

    normally, when using the regular API, you could use function simGetObjectsInTree. That function is not (yet) implemented in the remote API.

    As a workaround, you have several possibilities:

    You could modify the remote API in order to support that function. This is rather difficult and not recommended.
    You could use function simxGetObjectGroupData. You would retrieve all objects and all parent objects. From there you could rebuild the desired tree hierarchy.
    You can use simxGetObjectChild as you mention it, in an iterative way, until you have retrieved all objects in the tree.
    You can retrieve (or continuously stream) the tree objects: on the V-REP side, use simGetObjectsInTree. Then pack the returned table in a string signal.
    Then send that signal to the remote API client, that will decode the string and retrieve the handles. On the V-REP side, inside of a non-threaded child script:

    :param robot_handle:
    :return: robot_joints: map of joint handles to their names
    '''
    try:
        return __get_cached(get_joints, robot_handle)
    except:
        pass

    # 0: Return names
    return_code, handles, intData, floatData, stringData = vrep.simxGetObjectGroupData(
        clientID, vrep.sim_object_joint_type, 0, vrep.simx_opmode_blocking)
    handes_name_map = {}
    for i, h in enumerate(handles):
        handes_name_map[h] = stringData[i]

    queue = []
    queue.append(robot_handle)
    robot_joint_handle_name_map = {}

    while len(queue) > 0:
        parent_handle = queue.pop(0)
        child_handle = 0
        child_index = 0
        while child_handle != -1:
            return_code, child_handle = vrep.simxGetObjectChild(
                clientID, parent_handle, child_index,
                vrep.simx_opmode_blocking)
            __check_resp(return_code, vrep.simx_return_ok)
            if child_handle != -1:
                child_index = child_index + 1
                queue.append(child_handle)
                if child_handle in handes_name_map:
                    robot_joint_handle_name_map[
                        child_handle] = handes_name_map.get(child_handle)

    __cache(get_joints, robot_handle, robot_joint_handle_name_map)

    return robot_joint_handle_name_map
예제 #6
0
    def get_children(self, handle):
        """
        Returns a list of handles of all the child objects of a specified object
        """
        child_handles = []
        index = 0
        while True:
            child_handle = vrep.simxGetObjectChild(self.client_id, handle,
                                                   index,
                                                   self.modes['blocking'])
            if child_handle == -1:
                break
            child_handles.append(child_handle)
            index += 1

        return child_handles
 def get_object_childs(self, obj_name):
     """
     Function that return handles of object's childs from the V-REP scene.
     This function is useful when the exact number of objects is unknown
     """
     index = 0
     children_list = []
     child = 0
     parent_handle = self.get_object_handle(obj_name)
     while child != -1:
         res, child = vrep.simxGetObjectChild(self.client_id, parent_handle,
                                              index,
                                              vrep.simx_opmode_blocking)
         if res == vrep.simx_return_ok:
             children_list.append(child)
             index = index + 1
         else:
             print('Remote fucntion get_object_childs call failed.')
             return []
     del children_list[len(children_list) - 1]
     return children_list
 def get_object_child(self, parent_handle, index):
     ret, child_handle = vrep.simxGetObjectChild(self.client_id, \
                         parent_handle, index, vrep.simx_opmode_oneshot_wait)
     return child_handle