Beispiel #1
0
def execute_mujoco(ball, table, robot, mujoco_id, model_name):
    # init mujoco
    config = pam_mujoco.MujocoConfig()
    config.graphics = True
    config.extended_graphics = False
    config.realtime = False
    pam_mujoco.init_mujoco(config)
    # adding contact detection between ball and table
    # note: best to add first (i.e. before mirror robot and
    # mirror ball), as controllers are called in sequence,
    # and contact info will change behavior of mirror ball controller
    pam_mujoco.add_robot1_contact_free_joint(
        "racket", ball.index_qpos, ball.index_qvel, ball.geom, robot.geom_racket
    )
    # for detecting contact with the table
    pam_mujoco.add_table_contact_free_joint(
        "table", ball.index_qpos, ball.index_qvel, ball.geom, table.geom_plate
    )
    # adding the mirror ball controller
    # (mirroring will be interrupted upon contact with the racket:
    # the contact controller (added right above) will write contact information
    # in the shared memory (segment: segment_id_contacts). The ball mirroring
    # controller will stop mirroring the ball after the data shared in the memory
    # shows a contact occured).
    pam_mujoco.add_mirror_until_contact_free_joint(
        "ball", ball.joint, ball.index_qpos, ball.index_qvel, "racket"
    )
    # adding robot mirroring controller
    pam_mujoco.add_mirror_robot("robot", robot.joint)
    # starting the thread
    pam_mujoco.execute(mujoco_id, model_name)
    # looping until requested to stop
    while not pam_mujoco.is_stop_requested(mujoco_id):
        time.sleep(0.01)
def execute_mujoco(pam_model_config, robot, mujoco_id, model_name):
    # init mujoco
    pam_mujoco.init_mujoco()
    # adding pressure controller
    pam_mujoco.add_pressure_controller(*pam_model_config)
    # starting the mujoco thread
    pam_mujoco.execute(mujoco_id, model_name)
    # runnign it until requested to stop
    while not pam_mujoco.is_stop_requested(mujoco_id):
        time.sleep(0.01)
def execute_mujoco(segment_id, mujoco_id, model_name, robot):
    # init mujoco
    config = pam_mujoco.MujocoConfig()
    config.graphics = True
    config.extended_graphics = False
    config.realtime = True
    pam_mujoco.init_mujoco(config)
    # adding mirroring robot controller
    pam_mujoco.add_mirror_robot(segment_id, robot.joint)
    # setting bursting mode
    pam_mujoco.add_bursting(mujoco_id, segment_id)
    # starting the mujoco thread (reads pamy.xml in pam_mujoco/models/tmp/)
    pam_mujoco.execute(mujoco_id, model_name)
    # runnign it until requested to stop
    while not pam_mujoco.is_stop_requested(mujoco_id):
        time.sleep(0.01)
Beispiel #4
0
def execute_mujoco(segment_ids, mujoco_id, model_name, balls):
    # init mujoco
    config = pam_mujoco.MujocoConfig()
    config.graphics = True
    config.extended_graphics = False
    config.realtime = False
    pam_mujoco.init_mujoco(config)
    # adding the mirror ball controllers
    for segment_id, ball in zip(segment_ids, balls):
        pam_mujoco.add_mirror_free_joint(
            segment_id, ball.joint, ball.index_qpos, ball.index_qvel
        )
    # staring the thread
    pam_mujoco.execute(mujoco_id, model_name)
    # looping until requested to stop
    while not pam_mujoco.is_stop_requested(mujoco_id):
        time.sleep(0.01)
    def _execute_mujoco(mujoco_id, segment_id, pam_model_config):

        model_name = segment_id

        # init mujoco
        config = pam_mujoco.MujocoConfig()
        config.graphics = graphics
        config.extended_graphics = extended_graphics
        config.realtime = realtime
        pam_mujoco.init_mujoco(config)

        # adding pressure controller
        pam_mujoco.add_pressure_controller(*pam_model_config)

        # starting the thread
        model_path = pam_mujoco.paths.get_model_path(model_name)
        pam_mujoco.execute(mujoco_id, model_path)

        # looping until requested to stop
        while not pam_mujoco.is_stop_requested(mujoco_id):
            time.sleep(0.01)
Beispiel #6
0
def execute_mujoco(mujoco_id, model_name, ball, hit_point, table):
    # init mujoco
    config = pam_mujoco.MujocoConfig()
    config.graphics = True
    config.extended_graphics = False
    config.realtime = True
    pam_mujoco.init_mujoco(config)
    # adding the mirror ball controller
    pam_mujoco.add_mirror_until_contact_free_joint("ball", ball.joint,
                                                   ball.index_qpos,
                                                   ball.index_qvel, "contact")
    # adding the hit point controller
    pam_mujoco.add_mirror_free_joint("hit_point", hit_point.joint,
                                     hit_point.index_qpos,
                                     hit_point.index_qvel)
    # adding detection of contact between ball and table
    pam_mujoco.add_table_contact_free_joint("contact", ball.index_qpos,
                                            ball.index_qvel, ball.geom,
                                            table.geom_plate)
    # starting the thread
    pam_mujoco.execute(mujoco_id, model_name)
    # looping until requested to stop
    while not pam_mujoco.is_stop_requested(mujoco_id):
        time.sleep(0.01)
    def _execute_mujoco(mujoco_id, ball, robot, goal, hit_point, segment_ids):

        model_name = segment_ids["robot"]

        # init mujoco
        config = pam_mujoco.MujocoConfig()
        config.graphics = graphics
        config.extended_graphics = extended_graphics
        config.realtime = realtime
        pam_mujoco.init_mujoco(config)

        active_only = True
        not_active_only = False

        # for detecting contact with the robot
        if segment_ids["contact_robot"] is not None:
            pam_mujoco.add_robot1_contact_free_joint(
                segment_ids["contact_robot"],
                ball.index_qpos,
                ball.index_qvel,
                ball.geom,
                robot.geom_racket,
            )

        # adding the mirror ball controller, will play
        # recorded ball trajectories, until contact with robot
        if segment_ids["contact_robot"] is not None:
            pam_mujoco.add_mirror_until_contact_free_joint(
                segment_ids["ball"],
                ball.joint,
                ball.index_qpos,
                ball.index_qvel,
                segment_ids["contact_robot"],
            )
        else:
            pam_mujoco.add_mirror_free_joint(
                segment_ids["ball"],
                ball.joint,
                ball.index_qpos,
                ball.index_qvel,
                active_only,
            )

        if segment_ids["goal"] is not None:
            pam_mujoco.add_mirror_free_joint(
                segment_ids["goal"],
                goal.joint,
                goal.index_qpos,
                goal.index_qvel,
                not_active_only,
            )

        if segment_ids["hit_point"] is not None:
            pam_mujoco.add_mirror_free_joint(
                segment_ids["hit_point"],
                hit_point.joint,
                hit_point.index_qpos,
                hit_point.index_qvel,
                not_active_only,
            )

        # adding mirroring robot controller
        pam_mujoco.add_mirror_robot(segment_ids["robot"], robot.joint)

        # set bursting mode if requested
        if segment_ids["burst"] is not None:
            pam_mujoco.add_bursting(mujoco_id, segment_ids["burst"])

        # starting the thread
        model_path = pam_mujoco.paths.get_model_path(model_name)
        pam_mujoco.execute(mujoco_id, model_path)

        # looping until requested to stop
        try:
            while not pam_mujoco.is_stop_requested(mujoco_id):
                time.sleep(0.01)
        except Exception:
            pass