Python pybullet.changeVisualShape() Examples

The following are 9 code examples of pybullet.changeVisualShape(). 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: world_creation.py    From assistive-gym with MIT License 5 votes vote down vote up
def init_pr2(self, print_joints=False):
        if self.task == 'arm_manipulation':
            robot = p.loadURDF(os.path.join(self.directory, 'PR2', 'pr2_no_torso_lift_tall_arm_manipulation.urdf'), useFixedBase=True, basePosition=[0, 0, 0], physicsClientId=self.id)
            robot_right_arm_joint_indices = [42, 43, 44, 46, 47, 49, 50]
            robot_left_arm_joint_indices = [65, 66, 67, 69, 70, 72, 73]
        else:
            robot = p.loadURDF(os.path.join(self.directory, 'PR2', 'pr2_no_torso_lift_tall.urdf'), useFixedBase=True, basePosition=[0, 0, 0], flags=p.URDF_USE_INERTIA_FROM_FILE, physicsClientId=self.id)
            robot_right_arm_joint_indices = [42, 43, 44, 46, 47, 49, 50]
            robot_left_arm_joint_indices = [64, 65, 66, 68, 69, 71, 72]
        if print_joints:
            self.print_joint_info(robot, show_fixed=True)

        # Initialize and position PR2
        p.resetBasePositionAndOrientation(robot, [-2, -2, 0], [0, 0, 0, 1], physicsClientId=self.id)

        # Recolor PR2
        if self.task == 'arm_manipulation':
            for i in [19, 42, 65]:
                p.changeVisualShape(robot, i, rgbaColor=[1.0, 1.0, 1.0, 1.0], physicsClientId=self.id)
            for i in [43, 46, 49, 59, 61, 66, 69, 72, 82, 84]:
                p.changeVisualShape(robot, i, rgbaColor=[0.4, 0.4, 0.4, 1.0], physicsClientId=self.id)
            for i in [45, 51, 68, 74]:
                p.changeVisualShape(robot, i, rgbaColor=[0.7, 0.7, 0.7, 1.0], physicsClientId=self.id)
        else:
            for i in [19, 42, 64]:
                p.changeVisualShape(robot, i, rgbaColor=[1.0, 1.0, 1.0, 1.0], physicsClientId=self.id)
            for i in [43, 46, 49, 58, 60, 65, 68, 71, 80, 82]:
                p.changeVisualShape(robot, i, rgbaColor=[0.4, 0.4, 0.4, 1.0], physicsClientId=self.id)
            for i in [45, 51, 67, 73]:
                p.changeVisualShape(robot, i, rgbaColor=[0.7, 0.7, 0.7, 1.0], physicsClientId=self.id)
        p.changeVisualShape(robot, 20, rgbaColor=[0.8, 0.8, 0.8, 1.0], physicsClientId=self.id)
        p.changeVisualShape(robot, 40, rgbaColor=[0.6, 0.6, 0.6, 1.0], physicsClientId=self.id)

        # Grab and enforce robot arm joint limits
        lower_limits, upper_limits = self.enforce_joint_limits(robot)

        return robot, lower_limits, upper_limits, robot_right_arm_joint_indices, robot_left_arm_joint_indices 
Example #2
Source File: world_creation.py    From assistive-gym with MIT License 5 votes vote down vote up
def init_baxter(self, print_joints=False):
        if self.task == 'arm_manipulation':
            robot = p.loadURDF(os.path.join(self.directory, 'baxter', 'baxter_custom_arm_manipulation.urdf'), useFixedBase=True, basePosition=[0, 0, 0], physicsClientId=self.id)
            robot_right_arm_joint_indices = [12, 13, 14, 15, 16, 18, 19]
            robot_left_arm_joint_indices = [35, 36, 37, 38, 39, 41, 42]
        else:
            robot = p.loadURDF(os.path.join(self.directory, 'baxter', 'baxter_custom.urdf'), useFixedBase=True, basePosition=[0, 0, 0], physicsClientId=self.id)
            robot_right_arm_joint_indices = [12, 13, 14, 15, 16, 18, 19]
            robot_left_arm_joint_indices = [34, 35, 36, 37, 38, 40, 41]
        if print_joints:
            self.print_joint_info(robot, show_fixed=True)

        # Initialize and position
        p.resetBasePositionAndOrientation(robot, [-2, -2, 0.975], [0, 0, 0, 1], physicsClientId=self.id)

        if self.task == 'arm_manipulation':
            for i in [20, 21, 23, 32, 33, 43, 44, 46, 55, 56]:
                p.changeVisualShape(robot, i, rgbaColor=[1.0, 1.0, 1.0, 0.0], physicsClientId=self.id)
        else:
            for i in [20, 21, 23, 31, 32, 42, 43, 45, 53, 54]:
                p.changeVisualShape(robot, i, rgbaColor=[1.0, 1.0, 1.0, 0.0], physicsClientId=self.id)

        # Grab and enforce robot arm joint limits
        lower_limits, upper_limits = self.enforce_joint_limits(robot)

        return robot, lower_limits, upper_limits, robot_right_arm_joint_indices, robot_left_arm_joint_indices 
Example #3
Source File: robot_locomotors.py    From GtS with MIT License 5 votes vote down vote up
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 #4
Source File: husky_env.py    From midlevel-reps with MIT License 5 votes vote down vote up
def step(self, action):
        obs, rew, env_done, info = SemanticRobotEnv.step(self,action=action)
        self.close_semantic_ids = self.get_close_semantic_pos(dist_max=1.0, orn_max=np.pi/5)
        for i in self.close_semantic_ids:
            flagId = self.semantic_flagIds[i]
            p.changeVisualShape(flagId, -1, rgbaColor=[0, 1, 0, 1])
        return obs,rew,env_done,info 
Example #5
Source File: husky_env.py    From midlevel-reps with MIT License 5 votes vote down vote up
def _reset(self):
        CameraRobotEnv._reset(self)
        for flagId in self.semantic_flagIds:
            p.changeVisualShape(flagId, -1, rgbaColor=[1, 0, 0, 1]) 
Example #6
Source File: robot_locomotors.py    From midlevel-reps with MIT License 5 votes vote down vote up
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 #7
Source File: scene_stadium.py    From midlevel-reps with MIT License 5 votes vote down vote up
def __init__(self, robot, gravity, timestep, frame_skip, env=None):
        Scene.__init__(self, gravity, timestep, frame_skip, env)

        filename = os.path.join(pybullet_data.getDataPath(), "stadium_no_collision.sdf")
        self.stadium = p.loadSDF(filename)
        planeName = os.path.join(pybullet_data.getDataPath(), "mjcf/ground_plane.xml")
        self.ground_plane_mjcf = p.loadMJCF(planeName)
        for i in self.ground_plane_mjcf:
            pos, orn = p.getBasePositionAndOrientation(i)
            p.resetBasePositionAndOrientation(i, [pos[0], pos[1], pos[2] - 0.005], orn)

        for i in self.ground_plane_mjcf:
            p.changeVisualShape(i, -1, rgbaColor=[1, 1, 1, 0.5])

        self.scene_obj_list = self.stadium 
Example #8
Source File: client.py    From costar_plan with Apache License 2.0 4 votes vote down vote up
def __init__(self, robot, task,
                 gui=False,
                 opengl2=False,
                 ros=False,
                 features="",
                 ros_name="simulation",
                 option=None,
                 plot_task=False,
                 directory='.',
                 capture=False,
                 show_images=False,
                 randomize_color=False,
                 fast_reset=False,
                 agent=None,
                 *args, **kwargs):
        # Do not start the gui if we aren't going to do anything with it.
        self.gui = gui \
                and not plot_task \
                and agent is not None \
                and agent is not "null"
        self.opengl2 = opengl2 and not plot_task \
                and agent is not None \
                and agent is not "null"
        self.robot = GetRobotInterface(robot)
        features = GetFeatures(features)
        self.task = GetTaskDefinition(
            task, self.robot, features, *args, **kwargs)
        self.fast_reset = fast_reset

        # managed list of processes and other metadata
        self.procs = []
        self.ros = ros

        # saving
        self.capture = capture
        self.show_images = show_images
        self.directory = directory
        self.randomize_color = randomize_color
        # self.iterations = 0
        # self.max_iterations = 100

        if ros:
            # boot up ROS and open a connection to the simulation server
            self._start_ros(ros_name)

        self.open()

        if randomize_color:
            for i in xrange(pb.getNumJoints(self.robot.handle)):
                color = np.random.random((4,))
                color[3] = 1.
                pb.changeVisualShape(self.robot.handle, i, rgbaColor=color,
                                     physicsClientId=self.client)

        if plot_task:
            print("SHOWING TASK")
            showTask(self.task.task)
            print("DONE")
            sys.exit(0) 
Example #9
Source File: scene_building.py    From midlevel-reps with MIT License 4 votes vote down vote up
def __init__(self, robot, model_id, gravity, timestep, frame_skip, env = None):
        Scene.__init__(self, gravity, timestep, frame_skip, env)

        # contains cpp_world.clean_everything()
        # stadium_pose = cpp_household.Pose()
        # if self.zero_at_running_strip_start_line:
        #    stadium_pose.set_xyz(27, 21, 0)  # see RUN_STARTLINE, RUN_RAD constants
        
        filename = os.path.join(get_model_path(model_id), "mesh_z_up.obj")
        #filename = os.path.join(get_model_path(model_id), "3d", "blender.obj")
        #textureID = p.loadTexture(os.path.join(get_model_path(model_id), "3d", "rgb.mtl"))

        if robot.model_type == "MJCF":
            MJCF_SCALING = robot.mjcf_scaling
            scaling = [1.0/MJCF_SCALING, 1.0/MJCF_SCALING, 0.6/MJCF_SCALING]
        else:
            scaling  = [1, 1, 1]
        magnified = [2, 2, 2]

        collisionId = p.createCollisionShape(p.GEOM_MESH, fileName=filename, meshScale=scaling, flags=p.GEOM_FORCE_CONCAVE_TRIMESH)


        view_only_mesh = os.path.join(get_model_path(model_id), "mesh_view_only_z_up.obj")
        if os.path.exists(view_only_mesh):
            visualId = p.createVisualShape(p.GEOM_MESH,
                                       fileName=view_only_mesh,
                                       meshScale=scaling, flags=p.GEOM_FORCE_CONCAVE_TRIMESH)
        else:
            visualId = -1

        boundaryUid = p.createMultiBody(baseCollisionShapeIndex = collisionId, baseVisualShapeIndex = visualId)
        p.changeDynamics(boundaryUid, -1, lateralFriction=1)
        #print(p.getDynamicsInfo(boundaryUid, -1))
        self.scene_obj_list = [(boundaryUid, -1)]       # baselink index -1
        

        planeName = os.path.join(pybullet_data.getDataPath(), "mjcf/ground_plane.xml")
        self.ground_plane_mjcf = p.loadMJCF(planeName)
        
        if "z_offset" in self.env.config:
            z_offset = self.env.config["z_offset"]
        else:
            z_offset = -10 #with hole filling, we don't need ground plane to be the same height as actual floors

        p.resetBasePositionAndOrientation(self.ground_plane_mjcf[0], posObj = [0,0,z_offset], ornObj = [0,0,0,1])
        p.changeVisualShape(boundaryUid, -1, rgbaColor=[168 / 255.0, 164 / 255.0, 92 / 255.0, 1.0],
                            specularColor=[0.5, 0.5, 0.5])