def load_model(self, path, pose=None, fixed_base=True, scaling=1.0): """ Load the objects in the scene :param path: str Path to the object :param pose: Pose Position and Quaternion :param fixed_base: str Fixed in the scene :param scaling: float Scale object :return: int ID of the loaded object """ if path.endswith('.urdf'): body = p.loadURDF(path, useFixedBase=fixed_base, flags=0, globalScaling=scaling, physicsClientId=self.client_id) elif path.endswith('.sdf'): body = p.loadSDF(path, physicsClientId=self.client_id) elif path.endswith('.xml'): body = p.loadMJCF(path, physicsClientId=self.client_id) elif path.endswith('.bullet'): body = p.loadBullet(path, physicsClientId=self.client_id) else: raise ValueError(path) if pose is not None: self.set_pose(body, pose) return body
def __init__(self, path, axis, angle): self.orientation = [0, 0, 0] self.orientation[axis] = angle * 2 * 3.14159 / 360 self.position = [0, 0, 0] self.path = path self.wobble_counter = 0 self.wobble_direction = 1 if '.urdf' in self.path: self.ID = p.loadURDF(self.path, self.position, p.getQuaternionFromEuler(self.orientation)) elif '.sdf' in self.path: self.ID = p.loadSDF(self.path) elif '.bullet' in self.path: self.ID = p.loadBullet(self.path) elif '.mjcf' in self.path: self.ID = p.loadMJCF(self.path)
def load_pybullet(filename, fixed_base=False, scale=1., **kwargs): # fixed_base=False implies infinite base mass with LockRenderer(): if filename.endswith('.urdf'): flags = get_urdf_flags(**kwargs) body = p.loadURDF(filename, useFixedBase=fixed_base, flags=flags, globalScaling=scale, physicsClientId=CLIENT) elif filename.endswith('.sdf'): body = p.loadSDF(filename, physicsClientId=CLIENT) elif filename.endswith('.xml'): body = p.loadMJCF(filename, physicsClientId=CLIENT) elif filename.endswith('.bullet'): body = p.loadBullet(filename, physicsClientId=CLIENT) elif filename.endswith('.obj'): # TODO: fixed_base => mass = 0? body = create_obj(filename, scale=scale, **kwargs) else: raise ValueError(filename) INFO_FROM_BODY[CLIENT, body] = ModelInfo(None, filename, fixed_base, scale) return body
def load_model(rel_path, pose=None, fixed_base=True): # TODO: error with loadURDF when loading MESH visual and CYLINDER collision abs_path = rel_path #get_model_path(rel_path) flags = 0 # by default, Bullet disables self-collision # add_data_path() if abs_path.endswith('.urdf'): body = p.loadURDF(abs_path, useFixedBase=fixed_base, flags=flags, physicsClientId=CLIENT) elif abs_path.endswith('.sdf'): body = p.loadSDF(abs_path, physicsClientId=CLIENT) elif abs_path.endswith('.xml'): body = p.loadMJCF(abs_path, physicsClientId=CLIENT) elif abs_path.endswith('.bullet'): body = p.loadBullet(abs_path, physicsClientId=CLIENT) else: raise ValueError(abs_path) if pose is not None: set_pose(body, pose) # BODIES[CLIENT][body] = URDFInfo(None, abs_path) return body
def __init__(self, description_path, uid=None, config=None, realtime_sim=False): """ :param description_path: path to description file (urdf, .bullet, etc.) :param config: optional config file for specifying robot information :param uid: optional server id of bullet :type description_path: str :type config: dict :type uid: int """ # if uid is None: # uid = pb.connect(pb.SHARED_MEMORY) # if uid < 0: uid = pb.connect(pb.GUI_SERVER) self._uid = uid pb.resetSimulation(physicsClientId=self._uid) extension = description_path.split('.')[-1] if extension == "urdf": robot_id = pb.loadURDF(description_path, useFixedBase=True, physicsClientId=self._uid) elif extension == 'sdf': robot_id = pb.loadSDF(description_path, useFixedBase=True, physicsClientId=self._uid) elif extension == 'bullet': robot_id = pb.loadBullet(description_path, useFixedBase=True, physicsClientId=self._uid) else: robot_id = pb.loadMJCF(description_path, useFixedBase=True, physicsClientId=self._uid) self._id = robot_id pb.setGravity(0.0, 0.0, 0.0, physicsClientId=self._uid) if realtime_sim: pb.setRealTimeSimulation(1, physicsClientId=self._uid) pb.setTimeStep(0.01, physicsClientId=self._uid) self._rt_sim = realtime_sim self._all_joints = np.array( range(pb.getNumJoints(self._id, physicsClientId=self._uid))) self._movable_joints = self.get_movable_joints() self._nu = len(self._movable_joints) self._nq = self._nu joint_information = self.get_joint_info() self._all_joint_names = [ info['jointName'].decode("utf-8") for info in joint_information ] self._all_joint_dict = dict( zip(self._all_joint_names, self._all_joints)) if config is not None and config['ee_link_name'] is not None: self._ee_link_name = config['ee_link_name'] self._ee_link_idx = config['ee_link_idx'] else: self._ee_link_idx, self._ee_link_name = self._use_last_defined_link( ) self._joint_limits = self.get_joint_limits() self._ft_joints = [self._all_joints[-1]] # by default, set FT sensor at last fixed joint self.set_ft_sensor_at(self._ft_joints[0])
import pybullet as p import time timeStep = 0.01 c = -1 if (c < 0): c = p.connect(p.GUI) p.resetSimulation() p.setTimeStep(timeStep) p.loadBullet("spider.bullet") p.setGravity(0, 0, -10) p.setRealTimeSimulation(1) while True: print("TEST")
def __init__(self, description_path, uid=None, config=None): """ @param robot_description: path to description file (urdf, .bullet, etc.) @param config : optional config file for specifying robot information @param uid : optional server id of bullet @type robot_description : str @type config : dict @type uid : int """ if uid is None: uid = pb.connect(pb.SHARED_MEMORY) if uid < 0: uid = pb.connect(pb.GUI_SERVER) self._uid = uid pb.resetSimulation(physicsClientId=self._uid) extension = description_path.split('.')[-1] if extension == "urdf": robot_id = pb.loadURDF(description_path, useFixedBase=True, physicsClientId=self._uid) elif extension == 'sdf': robot_id = pb.loadSDF(description_path, useFixedBase=True, physicsClientId=self._uid) elif extension == 'bullet': robot_id = pb.loadBullet(description_path, useFixedBase=True, physicsClientId=self._uid) else: robot_id = pb.loadMJCF(description_path, useFixedBase=True, physicsClientId=self._uid) self._id = robot_id pb.setGravity(0.0, 0.0, -9.8, physicsClientId=self._uid) pb.setRealTimeSimulation(1, physicsClientId=self._uid) pb.setTimeStep(0.01, physicsClientId=self._uid) self._all_joints = np.array( range(pb.getNumJoints(self._id, physicsClientId=self._uid))) self._movable_joints = self.get_movable_joints() self._nu = len(self._movable_joints) self._nq = self._nu joint_information = self.get_joint_info() self._all_joint_names = [ info['jointName'] for info in joint_information ] self._all_joint_dict = dict( zip(self._all_joint_names, self._all_joints)) if config is not None and config['ee_link_name'] is not None: self._ee_link_name = config['ee_link_name'] self._ee_link_idx = config['ee_link_idx'] else: self._ee_link_idx, self._ee_link_name = self._use_last_defined_link( ) self._joint_limits = self.get_joint_limits()
import pybullet as p import time timeStep = 0.01 c = -1 if (c<0): c = p.connect(p.GUI) p.resetSimulation() p.setTimeStep(timeStep) p.loadURDF("plane/plane.urdf") p.loadBullet("slope.bullet") p.setGravity(0,0,-10) p.setRealTimeSimulation(1) while True: continue
import pybullet as p import time import math p.connect(p.GUI) plane = p.createCollisionShape(p.GEOM_PLANE) p.createMultiBody(0, plane) sphereUid = p.loadBullet("snakebot_simple.bullet") sphereRadius = 0.05 dt = 1. / 240. SNAKE_NORMAL_PERIOD = 0.1 # 1.5 m_wavePeriod = SNAKE_NORMAL_PERIOD m_waveLength = 4 m_wavePeriod = 1.5 m_waveAmplitude = 0.4 m_waveFront = 0.0 # our steering value m_steering = 0.0 m_segmentLength = sphereRadius * 2.0 forward = 0 while (1): keys = p.getKeyboardEvents() for k, v in keys.items(): if (k == p.B3G_RIGHT_ARROW and (v & p.KEY_WAS_TRIGGERED)): m_steering = -.2
import pybullet as p import time timeStep = 0.01 c = -1 if (c<0): c = p.connect(p.GUI) p.resetSimulation() p.setTimeStep(timeStep) p.loadBullet("multibody.bullet") p.setGravity(0,0,-10) p.setRealTimeSimulation(1) while True: continue