Python pybullet.getNumBodies() Examples
The following are 7
code examples of pybullet.getNumBodies().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pybullet
, or try the search function
.
Example #1
Source File: saveRestoreState.py From soccer-matlab with BSD 2-Clause "Simplified" License | 5 votes |
def dumpStateToFile(file): for i in range (p.getNumBodies()): pos,orn = p.getBasePositionAndOrientation(i) linVel,angVel = p.getBaseVelocity(i) txtPos = "pos="+str(pos)+"\n" txtOrn = "orn="+str(orn)+"\n" txtLinVel = "linVel"+str(linVel)+"\n" txtAngVel = "angVel"+str(angVel)+"\n" file.write(txtPos) file.write(txtOrn) file.write(txtLinVel) file.write(txtAngVel)
Example #2
Source File: saveRestoreStateTest.py From soccer-matlab with BSD 2-Clause "Simplified" License | 5 votes |
def dumpStateToFile(self, file): for i in range (p.getNumBodies()): pos,orn = p.getBasePositionAndOrientation(i) linVel,angVel = p.getBaseVelocity(i) txtPos = "pos="+str(pos)+"\n" txtOrn = "orn="+str(orn)+"\n" txtLinVel = "linVel"+str(linVel)+"\n" txtAngVel = "angVel"+str(angVel)+"\n" file.write(txtPos) file.write(txtOrn) file.write(txtLinVel) file.write(txtAngVel)
Example #3
Source File: testEnv.py From soccer-matlab with BSD 2-Clause "Simplified" License | 5 votes |
def test(args): count = 0 env = gym.make(args.env) env.env.configure(args) print("args.render=",args.render) if (args.render==1): env.render(mode="human") env.reset() if (args.resetbenchmark): while (1): env.reset() print("p.getNumBodies()=",p.getNumBodies()) print("count=",count) count+=1 print("action space:") sample = env.action_space.sample() action = sample*0.0 print("action=") print(action) for i in range(args.steps): obs,rewards,done,_ =env.step(action) if (args.rgb): print(env.render(mode="rgb_array")) print("obs=") print(obs) print("rewards") print (rewards) print ("done") print(done)
Example #4
Source File: robot_locomotors.py From GtS with MIT License | 5 votes |
def robot_specific_reset(self): WalkerBase.robot_specific_reset(self) humanoidId = -1 numBodies = p.getNumBodies() for i in range (numBodies): bodyInfo = p.getBodyInfo(i) if bodyInfo[1].decode("ascii") == 'humanoid': humanoidId = i ## Spherical radiance/glass shield to protect the robot's camera if self.glass_id is None: glass_id = p.loadMJCF(os.path.join(self.physics_model_dir, "glass.xml"))[0] #print("setting up glass", glass_id, humanoidId) p.changeVisualShape(glass_id, -1, rgbaColor=[0, 0, 0, 0]) cid = p.createConstraint(humanoidId, -1, glass_id,-1,p.JOINT_FIXED,[0,0,0],[0,0,1.4],[0,0,1]) self.motor_names = ["abdomen_z", "abdomen_y", "abdomen_x"] self.motor_power = [100, 100, 100] self.motor_names += ["right_hip_x", "right_hip_z", "right_hip_y", "right_knee"] self.motor_power += [100, 100, 300, 200] self.motor_names += ["left_hip_x", "left_hip_z", "left_hip_y", "left_knee"] self.motor_power += [100, 100, 300, 200] self.motor_names += ["right_shoulder1", "right_shoulder2", "right_elbow"] self.motor_power += [75, 75, 75] self.motor_names += ["left_shoulder1", "left_shoulder2", "left_elbow"] self.motor_power += [75, 75, 75] self.motors = [self.jdict[n] for n in self.motor_names]
Example #5
Source File: env_modalities.py From GtS with MIT License | 5 votes |
def _reset(self): assert(self._robot_introduced) assert(self._scene_introduced) debugmode = 1 if debugmode: print("Episode: steps:{} score:{}".format(self.nframe, self.reward)) body_xyz = self.robot.body_xyz #print("[{}, {}, {}],".format(body_xyz[0], body_xyz[1], body_xyz[2])) print("Episode count: {}".format(self.eps_count)) self.eps_count += 1 self.nframe = 0 self.eps_reward = 0 BaseEnv._reset(self) if not self.ground_ids: self.parts, self.jdict, self.ordered_joints, self.robot_body = self.robot.addToScene( []) self.ground_ids = set(self.scene.scene_obj_list) ## Todo: (hzyjerry) this part is not working, robot_tracking_id = -1 for i in range (p.getNumBodies()): if (p.getBodyInfo(i)[0].decode() == self.robot_body.get_name()): self.robot_tracking_id=i #print(p.getBodyInfo(i)[0].decode()) i = 0 eye_pos, eye_quat = self.get_eye_pos_orientation() pose = [eye_pos, eye_quat] observations = self.render_observations(pose) pos = self.robot._get_scaled_position() orn = self.robot.get_orientation() pos = (pos[0], pos[1], pos[2] + self.tracking_camera['z_offset']) p.resetDebugVisualizerCamera(self.tracking_camera['distance'],self.tracking_camera['yaw'], self.tracking_camera['pitch'],pos) return observations
Example #6
Source File: env_modalities.py From midlevel-reps with MIT License | 5 votes |
def _reset(self): assert(self._robot_introduced) assert(self._scene_introduced) debugmode = 1 if debugmode: print("Episode: steps:{} score:{}".format(self.nframe, self.reward)) body_xyz = self.robot.body_xyz print("[{}, {}, {}],".format(body_xyz[0], body_xyz[1], body_xyz[2])) print("Episode count: {}".format(self.eps_count)) self.eps_count += 1 self.nframe = 0 self.eps_reward = 0 BaseEnv._reset(self) if not self.ground_ids: self.parts, self.jdict, self.ordered_joints, self.robot_body = self.robot.addToScene( []) self.ground_ids = set(self.scene.scene_obj_list) ## Todo: (hzyjerry) this part is not working, robot_tracking_id = -1 for i in range (p.getNumBodies()): if (p.getBodyInfo(i)[0].decode() == self.robot_body.get_name()): self.robot_tracking_id=i #print(p.getBodyInfo(i)[0].decode()) i = 0 eye_pos, eye_quat = self.get_eye_pos_orientation() pose = [eye_pos, eye_quat] observations = self.render_observations(pose) pos = self.robot._get_scaled_position() orn = self.robot.get_orientation() pos = (pos[0], pos[1], pos[2] + self.tracking_camera['z_offset']) p.resetDebugVisualizerCamera(self.tracking_camera['distance'],self.tracking_camera['yaw'], self.tracking_camera['pitch'],pos) return observations
Example #7
Source File: robot_locomotors.py From midlevel-reps with MIT License | 5 votes |
def robot_specific_reset(self): WalkerBase.robot_specific_reset(self) humanoidId = -1 numBodies = p.getNumBodies() for i in range (numBodies): bodyInfo = p.getBodyInfo(i) if bodyInfo[1].decode("ascii") == 'humanoid': humanoidId = i ## Spherical radiance/glass shield to protect the robot's camera if self.glass_id is None: glass_id = p.loadMJCF(os.path.join(self.physics_model_dir, "glass.xml"))[0] #print("setting up glass", glass_id, humanoidId) p.changeVisualShape(glass_id, -1, rgbaColor=[0, 0, 0, 0]) cid = p.createConstraint(humanoidId, -1, glass_id,-1,p.JOINT_FIXED,[0,0,0],[0,0,1.4],[0,0,1]) self.motor_names = ["abdomen_z", "abdomen_y", "abdomen_x"] self.motor_power = [100, 100, 100] self.motor_names += ["right_hip_x", "right_hip_z", "right_hip_y", "right_knee"] self.motor_power += [100, 100, 300, 200] self.motor_names += ["left_hip_x", "left_hip_z", "left_hip_y", "left_knee"] self.motor_power += [100, 100, 300, 200] self.motor_names += ["right_shoulder1", "right_shoulder2", "right_elbow"] self.motor_power += [75, 75, 75] self.motor_names += ["left_shoulder1", "left_shoulder2", "left_elbow"] self.motor_power += [75, 75, 75] self.motors = [self.jdict[n] for n in self.motor_names]