当前位置: 首页>>代码示例>>Python>>正文


Python pybullet.getJointState方法代码示例

本文整理汇总了Python中pybullet.getJointState方法的典型用法代码示例。如果您正苦于以下问题:Python pybullet.getJointState方法的具体用法?Python pybullet.getJointState怎么用?Python pybullet.getJointState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pybullet的用法示例。


在下文中一共展示了pybullet.getJointState方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _step

# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import getJointState [as 别名]
def _step(self, action):
    p.stepSimulation()
#    time.sleep(self.timeStep)
    self.state = p.getJointState(self.cartpole, 1)[0:2] + p.getJointState(self.cartpole, 0)[0:2]
    theta, theta_dot, x, x_dot = self.state

    dv = 0.1
    deltav = [-10.*dv,-5.*dv, -2.*dv, -0.1*dv, 0, 0.1*dv, 2.*dv,5.*dv, 10.*dv][action]

    p.setJointMotorControl2(self.cartpole, 0, p.VELOCITY_CONTROL, targetVelocity=(deltav + self.state[3]))

    done =  x < -self.x_threshold \
                or x > self.x_threshold \
                or theta < -self.theta_threshold_radians \
                or theta > self.theta_threshold_radians
    reward = 1.0

    return np.array(self.state), reward, done, {} 
开发者ID:utra-robosoccer,项目名称:soccer-matlab,代码行数:20,代码来源:cartpole_bullet.py

示例2: _reset

# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import getJointState [as 别名]
def _reset(self):
#    print("-----------reset simulation---------------")
    p.resetSimulation()
    self.cartpole = p.loadURDF(os.path.join(pybullet_data.getDataPath(),"cartpole.urdf"),[0,0,0])
    self.timeStep = 0.01
    p.setJointMotorControl2(self.cartpole, 1, p.VELOCITY_CONTROL, force=0)
    p.setGravity(0,0, -10)
    p.setTimeStep(self.timeStep)
    p.setRealTimeSimulation(0)

    initialCartPos = self.np_random.uniform(low=-0.5, high=0.5, size=(1,))
    initialAngle = self.np_random.uniform(low=-0.5, high=0.5, size=(1,))
    p.resetJointState(self.cartpole, 1, initialAngle)
    p.resetJointState(self.cartpole, 0, initialCartPos)

    self.state = p.getJointState(self.cartpole, 1)[0:2] + p.getJointState(self.cartpole, 0)[0:2]

    return np.array(self.state) 
开发者ID:utra-robosoccer,项目名称:soccer-matlab,代码行数:20,代码来源:cartpole_bullet.py

示例3: step

# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import getJointState [as 别名]
def step(self, action):
        yaw = 0

        while True:
            yaw += -0.75
            p.resetDebugVisualizerCamera(cameraDistance=1.2, cameraYaw=yaw, cameraPitch=-20, cameraTargetPosition=[0, 0, 1.0], physicsClientId=self.id)
            indices = [4, 5, 6]
            # indices = [14, 15, 16]
            deltas = [0.01, 0.01, -0.01]
            indices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
            deltas = [0, 0, 0, 0, 0.01, 0.01, -0.01, 0, 0, 0]
            # indices = []
            # deltas = []
            # indices = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) + 10
            # deltas = [0, 0, 0, 0, -0.01, 0.01, -0.01, 0, 0, 0]
            for i, d in zip(indices, deltas):
                joint_position = p.getJointState(self.human, jointIndex=i, physicsClientId=self.id)[0]
                if joint_position + d > self.human_lower_limits[i] and joint_position + d < self.human_upper_limits[i]:
                    p.resetJointState(self.human, jointIndex=i, targetValue=joint_position+d, targetVelocity=0, physicsClientId=self.id)
            p.stepSimulation(physicsClientId=self.id)
            print('cameraYaw=%.2f, cameraPitch=%.2f, distance=%.2f' % p.getDebugVisualizerCamera(physicsClientId=self.id)[-4:-1])
            self.enforce_realistic_human_joint_limits()
            time.sleep(0.05)

        return [], None, None, None 
开发者ID:Healthcare-Robotics,项目名称:assistive-gym,代码行数:27,代码来源:human_testing.py

示例4: setRobot

# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import getJointState [as 别名]
def setRobot(self, robot, physicsClientId=None):
        self._robot = robot
        if physicsClientId != None:
            self._physicsClientId = physicsClientId
        jointNameToId = {}
        joint_id_list = []
        joint_pos_list = []
        self._joint_number = 0
        for i in range(p.getNumJoints(self._robot, physicsClientId=self._physicsClientId)):
            jointInfo = p.getJointInfo(self._robot, i, physicsClientId=self._physicsClientId)
            if jointInfo[2] == 0:
                joint_id_list.append(jointInfo[0])
                joint_pos_list.append(p.getJointState(self._robot, jointInfo[0], physicsClientId=self._physicsClientId)[0])
                jointNameToId[jointInfo[1].decode('UTF-8')] = jointInfo[0]
                self._joint_number += 1
        self._joint_id = np.array(joint_id_list, dtype=np.int32)
        self._joint_targetPos = np.array(joint_pos_list, dtype=np.float)
        self._joint_currentPos = np.array(joint_pos_list, dtype=np.float) 
开发者ID:Einsbon,项目名称:bipedal-robot-walking-simulation,代码行数:20,代码来源:motorController.py

示例5: setRobot

# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import getJointState [as 别名]
def setRobot(self, robot, physicsClientId=None):
        self._robot = robot
        if physicsClientId != None:
            self._physicsClientId = physicsClientId

        joint_id_list = []
        joint_pos_list = []
        self._joint_number = 0
        for i in range(p.getNumJoints(robot)):
            jointInfo = p.getJointInfo(robot, i)
            if jointInfo[2] == 0:
                joint_id_list.append(jointInfo[0])
                joint_pos_list.append(p.getJointState(robot, jointInfo[0])[0])
                self._joint_number += 1
        print(self._joint_number)
        self._joint_id = np.array(joint_id_list, dtype=np.int32)
        self._joint_targetPos = np.array(joint_pos_list, dtype=np.float)
        self._joint_currentPos = np.array(joint_pos_list, dtype=np.float) 
开发者ID:llSourcell,项目名称:Boston_Dynamics_Atlas_Explained,代码行数:20,代码来源:motorController.py

示例6: apply_action_fingers

# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import getJointState [as 别名]
def apply_action_fingers(self, action, obj_id=None):
        # move finger joints in position control
        assert len(action) == 2, ('finger joints are 2! The number of actions you passed is ', len(action))

        idx_fingers = [self._joint_name_to_ids['panda_finger_joint1'], self._joint_name_to_ids['panda_finger_joint2']]

        # use object id to check contact force and eventually stop the finger motion
        if obj_id is not None:
            _, forces = self.check_contact_fingertips(obj_id)
            # print("contact forces {}".format(forces))

            if forces[0] >= 20.0:
                action[0] = p.getJointState(self.robot_id, idx_fingers[0], physicsClientId=self._physics_client_id)[0]

            if forces[1] >= 20.0:
                action[1] = p.getJointState(self.robot_id, idx_fingers[1], physicsClientId=self._physics_client_id)[0]

        for i, idx in enumerate(idx_fingers):
            p.setJointMotorControl2(self.robot_id,
                                    idx,
                                    p.POSITION_CONTROL,
                                    targetPosition=action[i],
                                    force=10,
                                    maxVelocity=1,
                                    physicsClientId=self._physics_client_id) 
开发者ID:robotology-playground,项目名称:pybullet-robot-envs,代码行数:27,代码来源:panda_env.py

示例7: getMotorAngles

# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import getJointState [as 别名]
def getMotorAngles(self):
    motorAngles = []
    for i in range(self.nMotors):
      jointState = p.getJointState(self.quadruped, self.motorIdList[i])
      motorAngles.append(jointState[0])
    motorAngles = np.multiply(motorAngles, self.motorDir)
    return motorAngles 
开发者ID:utra-robosoccer,项目名称:soccer-matlab,代码行数:9,代码来源:minitaur.py

示例8: getMotorVelocities

# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import getJointState [as 别名]
def getMotorVelocities(self):
    motorVelocities = []
    for i in range(self.nMotors):
      jointState = p.getJointState(self.quadruped, self.motorIdList[i])
      motorVelocities.append(jointState[1])
    motorVelocities = np.multiply(motorVelocities, self.motorDir)
    return motorVelocities 
开发者ID:utra-robosoccer,项目名称:soccer-matlab,代码行数:9,代码来源:minitaur.py

示例9: getMotorTorques

# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import getJointState [as 别名]
def getMotorTorques(self):
    motorTorques = []
    for i in range(self.nMotors):
      jointState = p.getJointState(self.quadruped, self.motorIdList[i])
      motorTorques.append(jointState[3])
    motorTorques = np.multiply(motorTorques, self.motorDir)
    return motorTorques 
开发者ID:utra-robosoccer,项目名称:soccer-matlab,代码行数:9,代码来源:minitaur.py

示例10: setup_inverse_kinematics

# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import getJointState [as 别名]
def setup_inverse_kinematics(self, urdf_path):
        """
        This function is responsible for doing any setup for inverse kinematics.
        Inverse Kinematics maps end effector (EEF) poses to joint angles that
        are necessary to achieve those poses. 
        """

        # These indices come from the urdf file we're using
        self.effector_right = 27
        self.effector_left = 45

        # Use PyBullet to handle inverse kinematics.
        # Set up a connection to the PyBullet simulator.
        p.connect(p.DIRECT)
        p.resetSimulation()

        self.ik_robot = p.loadURDF(urdf_path, (0, 0, 0), useFixedBase=1)

        # Relevant joints we care about. Many of the joints are fixed and don't count, so
        # we need this second map to use the right ones.
        self.actual = [13, 14, 15, 16, 17, 19, 20, 31, 32, 33, 34, 35, 37, 38]

        self.num_joints = p.getNumJoints(self.ik_robot)
        n = p.getNumJoints(self.ik_robot)
        self.rest = []
        self.lower = []
        self.upper = []
        self.ranges = []
        for i in range(n):
            info = p.getJointInfo(self.ik_robot, i)
            # Retrieve lower and upper ranges for each relevant joint
            if info[3] > -1:
                self.rest.append(p.getJointState(self.ik_robot, i)[0])
                self.lower.append(info[8])
                self.upper.append(info[9])
                self.ranges.append(info[9] - info[8])

        # Simulation will update as fast as it can in real time, instead of waiting for
        # step commands like in the non-realtime case.
        p.setRealTimeSimulation(1) 
开发者ID:StanfordVL,项目名称:robosuite,代码行数:42,代码来源:baxter_ik_controller.py

示例11: setJoints

# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import getJointState [as 别名]
def setJoints(self, joints):
        """Set joint targets for motor control in simulation
        
        Arguments:
            joints {dict} -- dict of joint name -> angle (float, radian)
        
        Raises:
            Exception: if a joint is not found, exception is raised

        Returns:
            applied {dict} -- dict of joint states (position, velocity, reaction forces, applied torque)
        """
        applied = {}

        for name in joints.keys():
            if name in self.joints:
                if name.endswith('_speed'):
                    p.setJointMotorControl2(
                    self.robot, self.joints[name], p.VELOCITY_CONTROL, targetVelocity=joints[name])
                else:
                    if name in self.maxTorques:
                        maxTorque = self.maxTorques[name]
                        p.setJointMotorControl2(
                            self.robot, self.joints[name], p.POSITION_CONTROL, joints[name], force=maxTorque)
                    else:
                        p.setJointMotorControl2(
                            self.robot, self.joints[name], p.POSITION_CONTROL, joints[name])

                applied[name] = p.getJointState(self.robot, self.joints[name])
            else:
                raise Exception("Can't find joint %s" % name)

        return applied 
开发者ID:Rhoban,项目名称:onshape-to-robot,代码行数:35,代码来源:simulation.py

示例12: get_joint_pos

# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import getJointState [as 别名]
def get_joint_pos(body, joint):
        pos, _, react_force, torque = p.getJointState(body, joint)
        return np.array(pos, dtype=np.float32) 
开发者ID:StanfordVL,项目名称:NTP-vat-release,代码行数:5,代码来源:bullet_physics_engine.py

示例13: get_joint_vel

# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import getJointState [as 别名]
def get_joint_vel(body, joint):
        _, vel, react_force, torque = p.getJointState(body, joint)
        return np.array(vel, dtype=np.float32) 
开发者ID:StanfordVL,项目名称:NTP-vat-release,代码行数:5,代码来源:bullet_physics_engine.py

示例14: get_joint_force

# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import getJointState [as 别名]
def get_joint_force(body, joint):
        # TODO: Definition of react_force?
        _, _, react_force, _ = p.getJointState(body, joint)
        return np.array(react_force, dtype=np.float32) 
开发者ID:StanfordVL,项目名称:NTP-vat-release,代码行数:6,代码来源:bullet_physics_engine.py

示例15: get_joint_torque

# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import getJointState [as 别名]
def get_joint_torque(body, joint):
        _, _, _, torque = p.getJointState(body, joint)
        return np.array(torque, dtype=np.float32) 
开发者ID:StanfordVL,项目名称:NTP-vat-release,代码行数:5,代码来源:bullet_physics_engine.py


注:本文中的pybullet.getJointState方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。