Exemplo n.º 1
0
def parse_sim_params(args, cfg, cfg_train):
    # initialize sim
    sim_params = gymapi.SimParams()
    sim_params.dt = 1. / 60.
    sim_params.num_client_threads = args.slices

    if args.physics_engine == gymapi.SIM_FLEX:
        if args.device != "cpu":
            print("WARNING: Using Flex with GPU instead of PHYSX!")
        sim_params.flex.shape_collision_margin = 0.01
        sim_params.flex.num_outer_iterations = 4
        sim_params.flex.num_inner_iterations = 10
    elif args.physics_engine == gymapi.SIM_PHYSX:
        sim_params.physx.solver_type = 1
        sim_params.physx.num_position_iterations = 4
        sim_params.physx.num_velocity_iterations = 0
        sim_params.physx.num_threads = 4
        sim_params.physx.use_gpu = args.use_gpu
        sim_params.physx.num_subscenes = args.subscenes
        sim_params.physx.max_gpu_contact_pairs = 8 * 1024 * 1024

    sim_params.use_gpu_pipeline = args.use_gpu_pipeline
    sim_params.physx.use_gpu = args.use_gpu

    # if sim options are provided in cfg, parse them and update/override above:
    if "sim" in cfg:
        gymutil.parse_sim_config(cfg["sim"], sim_params)

    # Override num_threads if passed on the command line
    if args.physics_engine == gymapi.SIM_PHYSX and args.num_threads > 0:
        sim_params.physx.num_threads = args.num_threads

    return sim_params
Exemplo n.º 2
0
    def __init__(self,
                 render=True,
                 num_instances=1,
                 middleware=None,
                 **kwargs):
        """
        Initialize Isaac gym simulator.

        Args:
            render (bool): if True, it will open the GUI, otherwise, it will just run the server.
            num_instances (int): number of simulator instances.
            middleware (MiddleWare, None): middleware instance.
            **kwargs (dict): optional arguments (this is not used here).
        """
        super(Isaac, self).__init__(render=render,
                                    num_instances=num_instances,
                                    middleware=middleware,
                                    **kwargs)

        # define variables
        self.gym = gymapi.acquire_gym()
        self.sim = self.gym.create_sim()
        self.params = gymapi.SimParams()
        self.gym.get_sim_params(self.sim, self.params)
        spacing = 10
        lower, upper = gymapi.Vec3(-spacing, -spacing,
                                   0.), gymapi.Vec3(spacing, spacing, spacing)
        self.env = self.gym.create_env(self.sim, lower, upper)
        self.viewer = None

        self.dt = 1. / 60
        self.num_substeps = 2

        if render:  # gui
            self.viewer = self.gym.create_viewer(None, 1920, 1080)

        # keep track of loaded bodies
        self.bodies = OrderedDict()  # {body_id: Body}
        self._body_cnt = 0
Exemplo n.º 3
0
def create_sim(gym, use_viewer, args):
    """Set sim parameters and create a Sim object."""
    # Set simulation parameters
    sim_type = gymapi.SIM_FLEX  # Can also use SIM_PHYSX
    sim_params = gymapi.SimParams()
    sim_params.dt = 1.0 / 1500
    sim_params.substeps = 1
    sim_params.gravity = gymapi.Vec3(0.0, -9.81, 0.0)
    if args.mode in ["shake", "twist"]:
        sim_params.gravity = gymapi.Vec3(0.0, 0.0, 0.0)

    # Set stress visualization parameters
    sim_params.stress_visualization = True
    sim_params.stress_visualization_min = 1.0e2
    sim_params.stress_visualization_max = 1e5

    # Set FleX-specific parameters
    sim_params.flex.solver_type = 5
    sim_params.flex.num_outer_iterations = 10
    sim_params.flex.num_inner_iterations = 200
    sim_params.flex.relaxation = 0.75
    sim_params.flex.warm_start = 0.8

    sim_params.flex.deterministic_mode = True

    # Set contact parameters
    sim_params.flex.shape_collision_distance = 5e-4
    sim_params.flex.contact_regularization = 1.0e-6
    sim_params.flex.shape_collision_margin = 1.0e-4
    sim_params.flex.dynamic_friction = 0.7

    # Create Sim object
    gpu_physics = 0
    gpu_render = 0
    if not use_viewer:
        gpu_render = -1
    return gym.create_sim(gpu_physics, gpu_render, sim_type,
                          sim_params), sim_params
Exemplo n.º 4
0
    def __init__(self, env_type, num_envs):
        args = gymutil.parse_arguments(description="Basketbot Simulaton",
                                       custom_parameters=[{
                                           "name":
                                           "--render",
                                           "action":
                                           "store_true",
                                           "help":
                                           "Render the simulation"
                                       }, {
                                           "name":
                                           "--show_axis",
                                           "action":
                                           "store_true",
                                           "help":
                                           "Visualize DOF axis"
                                       }])
        self.render = args.render

        self.gym = gymapi.acquire_gym()

        # create a simulator
        sim_params = gymapi.SimParams()
        sim_params.substeps = 2
        sim_params.dt = env_type.dt
        sim_params.up_axis = gymapi.UP_AXIS_Z
        sim_params.gravity = gymapi.Vec3(0.0, 0.0, -9.81)

        if args.physics_engine == gymapi.SIM_FLEX:
            raise NotImplementedError(
                "Flex simulation engine is not supported! Choose PhysX.")
        elif args.physics_engine == gymapi.SIM_PHYSX:
            sim_params.physx.use_gpu = True
            # sim_params.physx.solver_type = 1

        self.sim = self.gym.create_sim(args.compute_device_id,
                                       args.graphics_device_id,
                                       args.physics_engine, sim_params)

        # Create the ground plane:
        plane_params = gymapi.PlaneParams()
        plane_params.normal = gymapi.Vec3(0, 0, 1)
        self.gym.add_ground(self.sim, plane_params)

        # Load the robot:
        asset_root = "robot_description"
        asset_file = "urdf/robot/wam_4dof.urdf"
        asset_options = gymapi.AssetOptions()
        asset_options.fix_base_link = True
        robot_asset = self.gym.load_asset(self.sim, asset_root, asset_file,
                                          asset_options)

        # Make ball asset:
        asset_options = gymapi.AssetOptions()
        ball_asset = self.gym.create_sphere(self.sim, 0.0375, asset_options)

        # Env gird:
        envs_per_row = 3
        envs_per_row = int(np.sqrt(num_envs))
        # env_spacing = 1.2
        env_spacing = 0.0
        env_lower = gymapi.Vec3(-env_spacing, 0.0, -env_spacing)
        env_upper = gymapi.Vec3(env_spacing, env_spacing, env_spacing)

        # Create and populate envs:
        self.envs = []
        for i in range(num_envs):
            # env
            env = self.gym.create_env(self.sim, env_lower, env_upper,
                                      envs_per_row)
            # robot
            default_pose = gymapi.Transform()  # Default pose
            robot = self.gym.create_actor(env, robot_asset, default_pose,
                                          "Robot", i)
            # ball 1
            ball1_pose = gymapi.Transform()
            ball1_pose.p = gymapi.Vec3(0.87, 0.086, 1.07)
            ball1 = self.gym.create_actor(env, ball_asset, ball1_pose, "Ball1",
                                          i)
            # ball 2
            ball2_pose = gymapi.Transform()
            ball2_pose.p = gymapi.Vec3(0.87, -0.086, 2.0)
            ball2 = self.gym.create_actor(env, ball_asset, ball2_pose, "Ball2",
                                          i)

            self.envs.append(
                IsaacJugglingWam4(self.gym, env, [robot], [ball1, ball2]))

        # Create viewer (if rendering)
        self.viewer = None
        if self.render:
            self.viewer = self.gym.create_viewer(self.sim,
                                                 gymapi.CameraProperties())
            cam_pos = gymapi.Vec3(1.7, 1.7, 1.5)
            cam_target = gymapi.Vec3(0.8, 0, 1.3)
            self.gym.viewer_camera_look_at(self.viewer, None, cam_pos,
                                           cam_target)

            if self.viewer is None:
                self.render = False
                print("*** Failed to create viewer -> rendering deactivated")
Exemplo n.º 5
0
    # parse arguments
    args = gymutil.parse_arguments(
        description="Kuka Bin Test",
        custom_parameters=[
            {"name": "--num_envs", "type": int, "default": 1, "help": "Number of environments to create"},
            {"name": "--num_objects", "type": int, "default": 10, "help": "Number of objects in the bin"},
            {"name": "--object_type", "type": int, "default": 0, "help": "Type of bjects to place in the bin: 0 - box, 1 - meat can, 2 - banana, 3 - mug, 4 - brick, 5 - random"}])

    num_envs = args.num_envs
    


    # configure sim
    sim_type = args.physics_engine
    sim_params = gymapi.SimParams()
    sim_params.up_axis = gymapi.UP_AXIS_Z
    sim_params.gravity = gymapi.Vec3(0.0, 0.0, -9.8)
    if sim_type is gymapi.SIM_FLEX:
        sim_params.substeps = 4
        sim_params.flex.solver_type = 5
        sim_params.flex.num_outer_iterations = 6
        sim_params.flex.num_inner_iterations = 50
        sim_params.flex.relaxation = 0.7
        sim_params.flex.warm_start = 0.1
        sim_params.flex.shape_collision_distance = 5e-4
        sim_params.flex.contact_regularization = 1.0e-6
        sim_params.flex.shape_collision_margin = 1.0e-4
        sim_params.flex.deterministic_mode = True

    sim = gym.create_sim(args.compute_device_id, args.graphics_device_id, sim_type, sim_params)