本文整理汇总了Python中pybullet.setGravity方法的典型用法代码示例。如果您正苦于以下问题:Python pybullet.setGravity方法的具体用法?Python pybullet.setGravity怎么用?Python pybullet.setGravity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pybullet
的用法示例。
在下文中一共展示了pybullet.setGravity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setupWorld
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import setGravity [as 别名]
def setupWorld(self):
numObjects = 50
maximalCoordinates = False
p.resetSimulation()
p.setPhysicsEngineParameter(deterministicOverlappingPairs=1)
p.loadURDF("planeMesh.urdf",useMaximalCoordinates=maximalCoordinates)
kukaId = p.loadURDF("kuka_iiwa/model_free_base.urdf",[0,0,10], useMaximalCoordinates=maximalCoordinates)
for i in range (p.getNumJoints(kukaId)):
p.setJointMotorControl2(kukaId,i,p.POSITION_CONTROL,force=0)
for i in range (numObjects):
cube = p.loadURDF("cube_small.urdf",[0,i*0.02,(i+1)*0.2])
#p.changeDynamics(cube,-1,mass=100)
p.stepSimulation()
p.setGravity(0,0,-10)
示例2: test_rolling_friction
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import setGravity [as 别名]
def test_rolling_friction(self):
import pybullet as p
p.connect(p.DIRECT)
p.loadURDF("plane.urdf")
sphere = p.loadURDF("sphere2.urdf",[0,0,1])
p.resetBaseVelocity(sphere,linearVelocity=[1,0,0])
p.changeDynamics(sphere,-1,linearDamping=0,angularDamping=0)
#p.changeDynamics(sphere,-1,rollingFriction=0)
p.setGravity(0,0,-10)
for i in range (1000):
p.stepSimulation()
vel = p.getBaseVelocity(sphere)
self.assertLess(vel[0][0],1e-10)
self.assertLess(vel[0][1],1e-10)
self.assertLess(vel[0][2],1e-10)
self.assertLess(vel[1][0],1e-10)
self.assertLess(vel[1][1],1e-10)
self.assertLess(vel[1][2],1e-10)
p.disconnect()
示例3: _reset
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import setGravity [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)
示例4: _reset
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import setGravity [as 别名]
def _reset(self):
self.terminated = 0
p.resetSimulation()
p.setPhysicsEngineParameter(numSolverIterations=150)
p.setTimeStep(self._timeStep)
p.loadURDF(os.path.join(self._urdfRoot,"plane.urdf"),[0,0,-1])
p.loadURDF(os.path.join(self._urdfRoot,"table/table.urdf"), 0.5000000,0.00000,-.820000,0.000000,0.000000,0.0,1.0)
xpos = 0.5 +0.2*random.random()
ypos = 0 +0.25*random.random()
ang = 3.1415925438*random.random()
orn = p.getQuaternionFromEuler([0,0,ang])
self.blockUid =p.loadURDF(os.path.join(self._urdfRoot,"block.urdf"), xpos,ypos,-0.1,orn[0],orn[1],orn[2],orn[3])
p.setGravity(0,0,-10)
self._kuka = kuka.Kuka(urdfRootPath=self._urdfRoot, timeStep=self._timeStep)
self._envStepCounter = 0
p.stepSimulation()
self._observation = self.getExtendedObservation()
return np.array(self._observation)
示例5: reset
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import setGravity [as 别名]
def reset(self, robot_base_offset=[0, 0, 0], task='scratch_itch_pr2'):
self.human, self.wheelchair, self.robot, self.robot_lower_limits, self.robot_upper_limits, self.human_lower_limits, self.human_upper_limits, self.robot_right_arm_joint_indices, self.robot_left_arm_joint_indices, self.gender = self.world_creation.create_new_world(furniture_type=None, static_human_base=True, human_impairment='none', print_joints=False, gender='random')
p.resetDebugVisualizerCamera(cameraDistance=1.2, cameraYaw=0, cameraPitch=-20, cameraTargetPosition=[0, 0, 1.0], physicsClientId=self.id)
joints_positions = []
# self.human_controllable_joint_indices = []
self.human_controllable_joint_indices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
# self.human_controllable_joint_indices = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
self.world_creation.setup_human_joints(self.human, joints_positions, self.human_controllable_joint_indices, use_static_joints=True, human_reactive_force=None)
p.setGravity(0, 0, 0, physicsClientId=self.id)
# Enable rendering
p.configureDebugVisualizer(p.COV_ENABLE_RENDERING, 1, physicsClientId=self.id)
return []
示例6: _setup
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import setGravity [as 别名]
def _setup(self):
"""Sets up the robot + tray + objects.
"""
pybullet.resetSimulation(physicsClientId=self.cid)
pybullet.setPhysicsEngineParameter(numSolverIterations=150,
physicsClientId=self.cid)
# pybullet.setTimeStep(self._time_step, physicsClientId=self.cid)
pybullet.setGravity(0, 0, -10, physicsClientId=self.cid)
plane_path = os.path.join(self._urdf_root, 'plane.urdf')
pybullet.loadURDF(plane_path, [0, 0, -1],
physicsClientId=self.cid)
table_path = os.path.join(self._urdf_root, 'table/table.urdf')
pybullet.loadURDF(table_path, [0.0, 0.0, -.65],
[0., 0., 0., 1.], physicsClientId=self.cid)
# Load the target object
duck_path = os.path.join(self._urdf_root, 'duck_vhacd.urdf')
pos = [0]*3
orn = [0., 0., 0., 1.]
self._target_uid = pybullet.loadURDF(
duck_path, pos, orn, physicsClientId=self.cid)
示例7: open
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import setGravity [as 别名]
def open(self):
'''
Decide how we will create our interface to the underlying simulation.
We can create a GUI connection or something else.
'''
options = ""
if self.opengl2:
connect_type = pb.GUI
options = "--opengl2"
elif self.gui:
connect_type = pb.GUI
else:
connect_type = pb.DIRECT
self.client = pb.connect(connect_type, options=options)
GRAVITY = (0,0,-9.8)
pb.setGravity(*GRAVITY)
# place the robot in the world and set up the task
self.task.setup()
示例8: _reset
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import setGravity [as 别名]
def _reset(self):
# reset is called once at initialization of simulation
self.vt = 0
self.vd = 0
self.maxV = 24.6 # 235RPM = 24,609142453 rad/sec
self._envStepCounter = 0
p.resetSimulation()
p.setGravity(0,0,-10) # m/s^2
p.setTimeStep(0.01) # sec
planeId = p.loadURDF("plane.urdf")
cubeStartPos = [0,0,0.001]
cubeStartOrientation = p.getQuaternionFromEuler([0,0,0])
path = os.path.abspath(os.path.dirname(__file__))
self.botId = p.loadURDF(os.path.join(path, "balancebot_simple.xml"),
cubeStartPos,
cubeStartOrientation)
# you *have* to compute and return the observation from reset()
self._observation = self._compute_observation()
return np.array(self._observation)
示例9: setupWorld
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import setGravity [as 别名]
def setupWorld():
p.resetSimulation()
p.setPhysicsEngineParameter(deterministicOverlappingPairs=1)
p.loadURDF("planeMesh.urdf")
kukaId = p.loadURDF("kuka_iiwa/model_free_base.urdf",[0,0,10])
for i in range (p.getNumJoints(kukaId)):
p.setJointMotorControl2(kukaId,i,p.POSITION_CONTROL,force=0)
for i in range (numObjects):
cube = p.loadURDF("cube_small.urdf",[0,i*0.02,(i+1)*0.2])
#p.changeDynamics(cube,-1,mass=100)
p.stepSimulation()
p.setGravity(0,0,-10)
示例10: evaluate_params
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import setGravity [as 别名]
def evaluate_params(evaluateFunc, params, objectiveParams, urdfRoot='', timeStep=0.01, maxNumSteps=10000, sleepTime=0):
print('start evaluation')
beforeTime = time.time()
p.resetSimulation()
p.setTimeStep(timeStep)
p.loadURDF("%s/plane.urdf" % urdfRoot)
p.setGravity(0,0,-10)
global minitaur
minitaur = Minitaur(urdfRoot)
start_position = current_position()
last_position = None # for tracing line
total_energy = 0
for i in range(maxNumSteps):
torques = minitaur.getMotorTorques()
velocities = minitaur.getMotorVelocities()
total_energy += np.dot(np.fabs(torques), np.fabs(velocities)) * timeStep
joint_values = evaluate_func_map[evaluateFunc](i, params)
minitaur.applyAction(joint_values)
p.stepSimulation()
if (is_fallen()):
break
if i % 100 == 0:
sys.stdout.write('.')
sys.stdout.flush()
time.sleep(sleepTime)
print(' ')
alpha = objectiveParams[0]
final_distance = np.linalg.norm(start_position - current_position())
finalReturn = final_distance - alpha * total_energy
elapsedTime = time.time() - beforeTime
print ("trial for ", params, " final_distance", final_distance, "total_energy", total_energy, "finalReturn", finalReturn, "elapsed_time", elapsedTime)
return finalReturn
示例11: _reset
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import setGravity [as 别名]
def _reset(self):
"""Environment reset called at the beginning of an episode.
"""
# Set the camera settings.
look = [0.23, 0.2, 0.54]
distance = 1.
pitch = -56 + self._cameraRandom*np.random.uniform(-3, 3)
yaw = 245 + self._cameraRandom*np.random.uniform(-3, 3)
roll = 0
self._view_matrix = p.computeViewMatrixFromYawPitchRoll(
look, distance, yaw, pitch, roll, 2)
fov = 20. + self._cameraRandom*np.random.uniform(-2, 2)
aspect = self._width / self._height
near = 0.01
far = 10
self._proj_matrix = p.computeProjectionMatrixFOV(
fov, aspect, near, far)
self._attempted_grasp = False
self._env_step = 0
self.terminated = 0
p.resetSimulation()
p.setPhysicsEngineParameter(numSolverIterations=150)
p.setTimeStep(self._timeStep)
p.loadURDF(os.path.join(self._urdfRoot,"plane.urdf"),[0,0,-1])
p.loadURDF(os.path.join(self._urdfRoot,"table/table.urdf"), 0.5000000,0.00000,-.820000,0.000000,0.000000,0.0,1.0)
p.setGravity(0,0,-10)
self._kuka = kuka.Kuka(urdfRootPath=self._urdfRoot, timeStep=self._timeStep)
self._envStepCounter = 0
p.stepSimulation()
# Choose the objects in the bin.
urdfList = self._get_random_object(
self._numObjects, self._isTest)
self._objectUids = self._randomly_place_objects(urdfList)
self._observation = self._get_observation()
return np.array(self._observation)
示例12: set_gravity
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import setGravity [as 别名]
def set_gravity(self, gravity):
self._gravity = gravity
p.setGravity(gravity[0], gravity[1], gravity[2])
示例13: __init__
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import setGravity [as 别名]
def __init__(self, im_width, im_height, fov, near_plane, far_plane, DEBUG=False):
self.im_width = im_width
self.im_height = im_height
self.fov = fov
self.near_plane = near_plane
self.far_plane = far_plane
aspect = self.im_width/self.im_height
self.pm = pb.computeProjectionMatrixFOV(fov, aspect, near_plane, far_plane)
self.camera_pos = np.array([0, 0, 0.5])
self.camera_rot = self._rotation_matrix([0, np.pi, 0])
self.objects = []
if DEBUG:
self.cid = pb.connect(pb.GUI)
else:
self.cid = pb.connect(pb.DIRECT)
pb.setAdditionalSearchPath(pybullet_data.getDataPath())
pb.setGravity(0, 0, -10)
self.draw_camera_pos()
self._rendered = None
self._rendered_pos = None
self._rendered_rot = None
示例14: setup
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import setGravity [as 别名]
def setup(self):
'''
Create task by adding objects to the scene, including the robot.
'''
rospack = rospkg.RosPack()
path = rospack.get_path('costar_simulation')
static_plane_path = os.path.join(path, 'meshes', 'world', 'plane.urdf')
pb.loadURDF(static_plane_path)
self.world = self.makeWorld()
self.task = self._makeTask()
self._setup()
handle = self.robot.load()
pb.setGravity(0, 0, -9.807)
self._setupRobot(handle)
state = self.robot.getState()
self.world.addActor(SimulationRobotActor(
robot=self.robot,
dynamics=SimulationDynamics(self.world),
policy=NullPolicy(),
state=state))
self._updateWorld()
for handle, (obj_type, obj_name) in self._type_and_name_by_obj.items():
# Create an object and add it to the World
state = GetObjectState(handle)
self.world.addObject(obj_name, obj_type, handle, state)
self.task.compile(self.getObjects())
示例15: apply_action
# 需要导入模块: import pybullet [as 别名]
# 或者: from pybullet import setGravity [as 别名]
def apply_action(self, action):
if self.is_discrete:
realaction = self.action_list[action]
else:
realaction = action
p.setGravity(0, 0, 0)
p.resetBaseVelocity(self.robot_ids[0], realaction[:3], realaction[3:])