Beispiel #1
0
def get_leg(name,
            hip_distance=0.2,
            hip_angle=0.0,
            leg_length=0.4,
            foot_length=0.6):
    leg = e.Body(name=name, pos=[0, 0, 0], euler=[0, 0, hip_angle])

    aux_geom = e.Geom(fromto=[0, 0, 0, hip_distance, 0, 0],
                      name="aux_geom_" + name,
                      size=0.08,
                      type="capsule")
    aux_body = e.Body(name="aux_body_" + name, pos=[hip_distance, 0, 0])
    leg.add_children([aux_geom, aux_body])

    # Body
    hip_joint = e.Joint(axis=[0, 0, 1],
                        name="hip_joint_" + name,
                        pos=[0.0, 0.0, 0.0],
                        range=[-30, 30],
                        type="hinge")
    leg_geom = e.Geom(fromto=[0.0, 0.0, 0.0, leg_length, 0.0, 0.0],
                      name="leg_geom_" + name,
                      size=0.08,
                      type="capsule")
    ankle_body = e.Body(name="ankle_body_" + name, pos=[leg_length, 0.0, 0])
    aux_body.add_children([hip_joint, leg_geom, ankle_body])

    # Body
    ankle_joint = e.Joint(axis=[0, 1, 0],
                          name="ankle_joint_" + name,
                          pos=[0.0, 0.0, 0.0],
                          range=[30, 70],
                          type="hinge")
    ankle_geom = e.Geom(fromto=[0.0, 0.0, 0.0, foot_length, 0.0, 0.0],
                        name="ankle_geom_" + name,
                        size=0.08,
                        type="capsule")
    ankle_body.add_children([ankle_joint, ankle_geom])

    # Actuators
    hip = e.Motor(ctrllimited="true",
                  ctrlrange=[-1.0, 1.0],
                  joint=hip_joint.name,
                  gear=150)
    ankle = e.Motor(ctrllimited=True,
                    ctrlrange=[-1.0, 1.0],
                    joint=ankle_joint.name,
                    gear=150)

    return leg, hip, ankle
Beispiel #2
0
def main():

    mujoco = e.Mujoco(model="reacher", )
    compiler = e.Compiler(
        angle="radian",
        inertiafromgeom="true",
    )
    default = e.Default()
    option = e.Option(
        gravity="0 0 -9.81",
        integrator="RK4",
        timestep="0.01",
    )
    worldbody = e.Worldbody()
    actuator = e.Actuator()
    mujoco.add_children([
        compiler,
        default,
        option,
        worldbody,
        actuator,
    ])
    joint = e.Joint(
        armature="1",
        damping="1",
        limited="true",
    )
    geom = e.Geom(
        contype="0",
        friction="1 0.1 0.1",
        rgba="0.7 0.7 0 1",
    )
    default.add_children([
        joint,
        geom,
    ])
    ground = e.Geom(
        conaffinity="0",
        contype="0",
        name="ground",
        pos="0 0 0",
        rgba="0.9 0.9 0.9 1",
        size="1 1 10",
        type="plane",
    )
    sideS = e.Geom(
        conaffinity="0",
        fromto="-.3 -.3 .01 .3 -.3 .01",
        name="sideS",
        rgba="0.9 0.4 0.6 1",
        size=".02",
        type="capsule",
    )
    sideE = e.Geom(
        conaffinity="0",
        fromto=" .3 -.3 .01 .3  .3 .01",
        name="sideE",
        rgba="0.9 0.4 0.6 1",
        size=".02",
        type="capsule",
    )
    sideN = e.Geom(
        conaffinity="0",
        fromto="-.3  .3 .01 .3  .3 .01",
        name="sideN",
        rgba="0.9 0.4 0.6 1",
        size=".02",
        type="capsule",
    )
    sideW = e.Geom(
        conaffinity="0",
        fromto="-.3 -.3 .01 -.3 .3 .01",
        name="sideW",
        rgba="0.9 0.4 0.6 1",
        size=".02",
        type="capsule",
    )
    root = e.Geom(
        conaffinity="0",
        contype="0",
        fromto="0 0 0 0 0 0.02",
        name="root",
        rgba="0.9 0.4 0.6 1",
        size=".011",
        type="cylinder",
    )
    body0 = e.Body(
        name="body0",
        pos="0 0 .01",
    )
    target = e.Body(
        name="target",
        pos=".1 -.1 .01",
    )
    worldbody.add_children([
        ground,
        sideS,
        sideE,
        sideN,
        sideW,
        root,
        body0,
        target,
    ])
    motor = e.Motor(
        ctrllimited="true",
        ctrlrange="-1.0 1.0",
        gear="200.0",
        joint="joint0",
    )
    motor_1 = e.Motor(
        ctrllimited="true",
        ctrlrange="-1.0 1.0",
        gear="200.0",
        joint="joint1",
    )
    actuator.add_children([
        motor,
        motor_1,
    ])
    link0 = e.Geom(
        fromto="0 0 0 0.1 0 0",
        name="link0",
        rgba="0.0 0.4 0.6 1",
        size=".01",
        type="capsule",
    )
    joint0 = e.Joint(
        axis="0 0 1",
        limited="false",
        name="joint0",
        pos="0 0 0",
        type="hinge",
    )
    body1 = e.Body(
        name="body1",
        pos="0.1 0 0",
    )
    body0.add_children([
        link0,
        joint0,
        body1,
    ])
    target_x = e.Joint(
        armature="0",
        axis="1 0 0",
        damping="0",
        limited="true",
        name="target_x",
        pos="0 0 0",
        range="-.27 .27",
        ref=".1",
        stiffness="0",
        type="slide",
    )
    target_y = e.Joint(
        armature="0",
        axis="0 1 0",
        damping="0",
        limited="true",
        name="target_y",
        pos="0 0 0",
        range="-.27 .27",
        ref="-.1",
        stiffness="0",
        type="slide",
    )
    target_1 = e.Geom(
        conaffinity="0",
        contype="0",
        name="target",
        pos="0 0 0",
        rgba="0.9 0.2 0.2 1",
        size=".009",
        type="sphere",
    )
    target.add_children([
        target_x,
        target_y,
        target_1,
    ])
    joint1 = e.Joint(
        axis="0 0 1",
        limited="true",
        name="joint1",
        pos="0 0 0",
        range="-3.0 3.0",
        type="hinge",
    )
    link1 = e.Geom(
        fromto="0 0 0 0.1 0 0",
        name="link1",
        rgba="0.0 0.4 0.6 1",
        size=".01",
        type="capsule",
    )
    fingertip = e.Body(
        name="fingertip",
        pos="0.11 0 0",
    )
    body1.add_children([
        joint1,
        link1,
        fingertip,
    ])
    fingertip_1 = e.Geom(
        contype="0",
        name="fingertip",
        pos="0 0 0",
        rgba="0.0 0.8 0.6 1",
        size=".01",
        type="sphere",
    )
    fingertip.add_children([
        fingertip_1,
    ])

    model_xml = mujoco.xml()

    # Output
    with open('reacher_gen.xml', 'w') as fh:
        fh.write(model_xml)
Beispiel #3
0
def main():

    mujoco = e.Mujoco(model="humanoidstandup", )
    compiler = e.Compiler(
        angle="degree",
        inertiafromgeom="true",
    )
    default = e.Default()
    option = e.Option(
        integrator="RK4",
        iterations="50",
        solver="PGS",
        timestep="0.003",
    )
    size = e.Size(
        nkey="5",
        nuser_geom="1",
    )
    visual = e.Visual()
    asset = e.Asset()
    worldbody = e.Worldbody()
    tendon = e.Tendon()
    actuator = e.Actuator()
    mujoco.add_children([
        compiler,
        default,
        option,
        size,
        visual,
        asset,
        worldbody,
        tendon,
        actuator,
    ])
    joint = e.Joint(
        armature="1",
        damping="1",
        limited="true",
    )
    geom = e.Geom(
        conaffinity="1",
        condim="1",
        contype="1",
        margin="0.001",
        material="geom",
        rgba="0.8 0.6 .4 1",
    )
    motor = e.Motor(
        ctrllimited="true",
        ctrlrange="-.4 .4",
    )
    default.add_children([
        joint,
        geom,
        motor,
    ])
    map = e.Map(
        fogend="5",
        fogstart="3",
    )
    visual.add_children([
        map,
    ])
    texture = e.Texture(
        builtin="gradient",
        height="100",
        rgb1=".4 .5 .6",
        rgb2="0 0 0",
        type="skybox",
        width="100",
    )
    texgeom = e.Texture(
        builtin="flat",
        height="1278",
        mark="cross",
        markrgb="1 1 1",
        name="texgeom",
        random="0.01",
        rgb1="0.8 0.6 0.4",
        rgb2="0.8 0.6 0.4",
        type="cube",
        width="127",
    )
    texplane = e.Texture(
        builtin="checker",
        height="100",
        name="texplane",
        rgb1="0 0 0",
        rgb2="0.8 0.8 0.8",
        type="2d",
        width="100",
    )
    MatPlane = e.Material(
        name="MatPlane",
        reflectance="0.5",
        shininess="1",
        specular="1",
        texrepeat="60 60",
        texture="texplane",
    )
    geom_1 = e.Material(
        name="geom",
        texture="texgeom",
        texuniform="true",
    )
    asset.add_children([
        texture,
        texgeom,
        texplane,
        MatPlane,
        geom_1,
    ])
    light = e.Light(
        cutoff="100",
        diffuse="1 1 1",
        dir="-0 0 -1.3",
        directional="true",
        exponent="1",
        pos="0 0 1.3",
        specular=".1 .1 .1",
    )
    floor = e.Geom(
        condim="3",
        friction="1 .1 .1",
        material="MatPlane",
        name="floor",
        pos="0 0 0",
        rgba="0.8 0.9 0.8 1",
        size="20 20 0.125",
        type="plane",
    )
    torso = e.Body(
        name="torso",
        pos="0 0 .105",
    )
    worldbody.add_children([
        light,
        floor,
        torso,
    ])
    left_hipknee = e.Fixed(name="left_hipknee", )
    right_hipknee = e.Fixed(name="right_hipknee", )
    tendon.add_children([
        left_hipknee,
        right_hipknee,
    ])
    abdomen_y = e.Motor(
        gear="100",
        joint="abdomen_y",
        name="abdomen_y",
    )
    abdomen_z = e.Motor(
        gear="100",
        joint="abdomen_z",
        name="abdomen_z",
    )
    abdomen_x = e.Motor(
        gear="100",
        joint="abdomen_x",
        name="abdomen_x",
    )
    right_hip_x = e.Motor(
        gear="100",
        joint="right_hip_x",
        name="right_hip_x",
    )
    right_hip_z = e.Motor(
        gear="100",
        joint="right_hip_z",
        name="right_hip_z",
    )
    right_hip_y = e.Motor(
        gear="300",
        joint="right_hip_y",
        name="right_hip_y",
    )
    right_knee = e.Motor(
        gear="200",
        joint="right_knee",
        name="right_knee",
    )
    left_hip_x = e.Motor(
        gear="100",
        joint="left_hip_x",
        name="left_hip_x",
    )
    left_hip_z = e.Motor(
        gear="100",
        joint="left_hip_z",
        name="left_hip_z",
    )
    left_hip_y = e.Motor(
        gear="300",
        joint="left_hip_y",
        name="left_hip_y",
    )
    left_knee = e.Motor(
        gear="200",
        joint="left_knee",
        name="left_knee",
    )
    right_shoulder1 = e.Motor(
        gear="25",
        joint="right_shoulder1",
        name="right_shoulder1",
    )
    right_shoulder2 = e.Motor(
        gear="25",
        joint="right_shoulder2",
        name="right_shoulder2",
    )
    right_elbow = e.Motor(
        gear="25",
        joint="right_elbow",
        name="right_elbow",
    )
    left_shoulder1 = e.Motor(
        gear="25",
        joint="left_shoulder1",
        name="left_shoulder1",
    )
    left_shoulder2 = e.Motor(
        gear="25",
        joint="left_shoulder2",
        name="left_shoulder2",
    )
    left_elbow = e.Motor(
        gear="25",
        joint="left_elbow",
        name="left_elbow",
    )
    actuator.add_children([
        abdomen_y,
        abdomen_z,
        abdomen_x,
        right_hip_x,
        right_hip_z,
        right_hip_y,
        right_knee,
        left_hip_x,
        left_hip_z,
        left_hip_y,
        left_knee,
        right_shoulder1,
        right_shoulder2,
        right_elbow,
        left_shoulder1,
        left_shoulder2,
        left_elbow,
    ])
    track = e.Camera(
        name="track",
        mode="trackcom",
        pos="0 -3 .5",
        xyaxes="1 0 0 0 0 1",
    )
    root = e.Joint(
        armature="0",
        damping="0",
        limited="false",
        name="root",
        pos="0 0 0",
        stiffness="0",
        type="free",
    )
    torso1 = e.Geom(
        fromto="0 -.07 0 0 .07 0",
        name="torso1",
        size="0.07",
        type="capsule",
    )
    head = e.Geom(
        name="head",
        pos="-.15 0 0",
        size=".09",
        type="sphere",
        user="******",
    )
    uwaist = e.Geom(
        fromto=".11 -.06 0 .11 .06 0",
        name="uwaist",
        size="0.06",
        type="capsule",
    )
    lwaist = e.Body(
        name="lwaist",
        pos=".21 0 0",
        quat="1.000 0 -0.002 0",
    )
    right_upper_arm = e.Body(
        name="right_upper_arm",
        pos="0 -0.17 0.06",
    )
    left_upper_arm = e.Body(
        name="left_upper_arm",
        pos="0 0.17 0.06",
    )
    torso.add_children([
        track,
        root,
        torso1,
        head,
        uwaist,
        lwaist,
        right_upper_arm,
        left_upper_arm,
    ])
    joint_1 = e.Joint(
        coef="-1",
        joint="left_hip_y",
    )
    joint_2 = e.Joint(
        coef="1",
        joint="left_knee",
    )
    left_hipknee.add_children([
        joint_1,
        joint_2,
    ])
    joint_3 = e.Joint(
        coef="-1",
        joint="right_hip_y",
    )
    joint_4 = e.Joint(
        coef="1",
        joint="right_knee",
    )
    right_hipknee.add_children([
        joint_3,
        joint_4,
    ])
    lwaist_1 = e.Geom(
        fromto="0 -.06 0 0 .06 0",
        name="lwaist",
        size="0.06",
        type="capsule",
    )
    abdomen_z_1 = e.Joint(
        armature="0.02",
        axis="0 0 1",
        damping="5",
        name="abdomen_z",
        pos="0 0 0.065",
        range="-45 45",
        stiffness="20",
        type="hinge",
    )
    abdomen_y_1 = e.Joint(
        armature="0.02",
        axis="0 1 0",
        damping="5",
        name="abdomen_y",
        pos="0 0 0.065",
        range="-75 30",
        stiffness="10",
        type="hinge",
    )
    pelvis = e.Body(
        name="pelvis",
        pos="0.165 0 0",
        quat="1.000 0 -0.002 0",
    )
    lwaist.add_children([
        lwaist_1,
        abdomen_z_1,
        abdomen_y_1,
        pelvis,
    ])
    right_shoulder1_1 = e.Joint(
        armature="0.0068",
        axis="2 1 1",
        name="right_shoulder1",
        pos="0 0 0",
        range="-85 60",
        stiffness="1",
        type="hinge",
    )
    right_shoulder2_1 = e.Joint(
        armature="0.0051",
        axis="0 -1 1",
        name="right_shoulder2",
        pos="0 0 0",
        range="-85 60",
        stiffness="1",
        type="hinge",
    )
    right_uarm1 = e.Geom(
        fromto="0 0 0 .16 -.16 -.16",
        name="right_uarm1",
        size="0.04 0.16",
        type="capsule",
    )
    right_lower_arm = e.Body(
        name="right_lower_arm",
        pos=".18 -.18 -.18",
    )
    right_upper_arm.add_children([
        right_shoulder1_1,
        right_shoulder2_1,
        right_uarm1,
        right_lower_arm,
    ])
    left_shoulder1_1 = e.Joint(
        armature="0.0068",
        axis="2 -1 1",
        name="left_shoulder1",
        pos="0 0 0",
        range="-60 85",
        stiffness="1",
        type="hinge",
    )
    left_shoulder2_1 = e.Joint(
        armature="0.0051",
        axis="0 1 1",
        name="left_shoulder2",
        pos="0 0 0",
        range="-60 85",
        stiffness="1",
        type="hinge",
    )
    left_uarm1 = e.Geom(
        fromto="0 0 0 .16 .16 -.16",
        name="left_uarm1",
        size="0.04 0.16",
        type="capsule",
    )
    left_lower_arm = e.Body(
        name="left_lower_arm",
        pos=".18 .18 -.18",
    )
    left_upper_arm.add_children([
        left_shoulder1_1,
        left_shoulder2_1,
        left_uarm1,
        left_lower_arm,
    ])
    abdomen_x_1 = e.Joint(
        armature="0.02",
        axis="1 0 0",
        damping="5",
        name="abdomen_x",
        pos="0 0 0.1",
        range="-35 35",
        stiffness="10",
        type="hinge",
    )
    butt = e.Geom(
        fromto="-.02 -.07 0 -.02 .07 0",
        name="butt",
        size="0.09",
        type="capsule",
    )
    right_thigh = e.Body(
        name="right_thigh",
        pos="0 -0.1 0",
    )
    left_thigh = e.Body(
        name="left_thigh",
        pos="0 0.1 0",
    )
    pelvis.add_children([
        abdomen_x_1,
        butt,
        right_thigh,
        left_thigh,
    ])
    right_elbow_1 = e.Joint(
        armature="0.0028",
        axis="0 -1 1",
        name="right_elbow",
        pos="0 0 0",
        range="-90 50",
        stiffness="0",
        type="hinge",
    )
    right_larm = e.Geom(
        fromto="0.01 0.01 0.01 .17 .17 .17",
        name="right_larm",
        size="0.031",
        type="capsule",
    )
    right_hand = e.Geom(
        name="right_hand",
        pos=".18 .18 .18",
        size="0.04",
        type="sphere",
    )
    camera = e.Camera(pos="0 0 0", )
    right_lower_arm.add_children([
        right_elbow_1,
        right_larm,
        right_hand,
        camera,
    ])
    left_elbow_1 = e.Joint(
        armature="0.0028",
        axis="0 -1 -1",
        name="left_elbow",
        pos="0 0 0",
        range="-90 50",
        stiffness="0",
        type="hinge",
    )
    left_larm = e.Geom(
        fromto="0.01 -0.01 0.01 .17 -.17 .17",
        name="left_larm",
        size="0.031",
        type="capsule",
    )
    left_hand = e.Geom(
        name="left_hand",
        pos=".18 -.18 .18",
        size="0.04",
        type="sphere",
    )
    left_lower_arm.add_children([
        left_elbow_1,
        left_larm,
        left_hand,
    ])
    right_hip_x_1 = e.Joint(
        armature="0.01",
        axis="1 0 0",
        damping="5",
        name="right_hip_x",
        pos="0 0 0",
        range="-25 5",
        stiffness="10",
        type="hinge",
    )
    right_hip_z_1 = e.Joint(
        armature="0.01",
        axis="0 0 1",
        damping="5",
        name="right_hip_z",
        pos="0 0 0",
        range="-60 35",
        stiffness="10",
        type="hinge",
    )
    right_hip_y_1 = e.Joint(
        armature="0.0080",
        axis="0 1 0",
        damping="5",
        name="right_hip_y",
        pos="0 0 0",
        range="-110 20",
        stiffness="20",
        type="hinge",
    )
    right_thigh1 = e.Geom(
        fromto="0 0 0 0.34 0.01 0",
        name="right_thigh1",
        size="0.06",
        type="capsule",
    )
    right_shin = e.Body(
        name="right_shin",
        pos="0.403 0.01 0",
    )
    right_thigh.add_children([
        right_hip_x_1,
        right_hip_z_1,
        right_hip_y_1,
        right_thigh1,
        right_shin,
    ])
    left_hip_x_1 = e.Joint(
        armature="0.01",
        axis="-1 0 0",
        damping="5",
        name="left_hip_x",
        pos="0 0 0",
        range="-25 5",
        stiffness="10",
        type="hinge",
    )
    left_hip_z_1 = e.Joint(
        armature="0.01",
        axis="0 0 -1",
        damping="5",
        name="left_hip_z",
        pos="0 0 0",
        range="-60 35",
        stiffness="10",
        type="hinge",
    )
    left_hip_y_1 = e.Joint(
        armature="0.01",
        axis="0 1 0",
        damping="5",
        name="left_hip_y",
        pos="0 0 0",
        range="-120 20",
        stiffness="20",
        type="hinge",
    )
    left_thigh1 = e.Geom(
        fromto="0 0 0 0.34 -0.01 0",
        name="left_thigh1",
        size="0.06",
        type="capsule",
    )
    left_shin = e.Body(
        name="left_shin",
        pos="0.403 -0.01 0",
    )
    left_thigh.add_children([
        left_hip_x_1,
        left_hip_z_1,
        left_hip_y_1,
        left_thigh1,
        left_shin,
    ])
    right_knee_1 = e.Joint(
        armature="0.0060",
        axis="0 -1 0",
        name="right_knee",
        pos="0 0 .02",
        range="-160 -2",
        type="hinge",
    )
    right_shin1 = e.Geom(
        fromto="0 0 0 0.3 0 0",
        name="right_shin1",
        size="0.049",
        type="capsule",
    )
    right_foot = e.Body(
        name="right_foot",
        pos="0.35 0 -.10",
    )
    right_shin.add_children([
        right_knee_1,
        right_shin1,
        right_foot,
    ])
    left_knee_1 = e.Joint(
        armature="0.0060",
        axis="0 -1 0",
        name="left_knee",
        pos="0 0 .02",
        range="-160 -2",
        stiffness="1",
        type="hinge",
    )
    left_shin1 = e.Geom(
        fromto="0 0 0 0.3 0 0",
        name="left_shin1",
        size="0.049",
        type="capsule",
    )
    left_foot = e.Body(
        name="left_foot",
        pos="0.35 0 -.1",
    )
    left_shin.add_children([
        left_knee_1,
        left_shin1,
        left_foot,
    ])
    right_foot_1 = e.Geom(
        name="right_foot",
        pos="0 0 0.1",
        size="0.075",
        type="sphere",
        user="******",
    )
    right_foot.add_children([
        right_foot_1,
    ])
    left_foot_1 = e.Geom(
        name="left_foot",
        type="sphere",
        size="0.075",
        pos="0 0 0.1",
        user="******",
    )
    left_foot.add_children([
        left_foot_1,
    ])

    model_xml = mujoco.xml()

    # Output
    with open('humanoidstandup_gen.xml', 'w') as fh:
        fh.write(model_xml)
Beispiel #4
0
def main():

    mujoco = e.Mujoco(model="cheetah", )
    compiler = e.Compiler(
        angle="radian",
        coordinate="local",
        inertiafromgeom="true",
        settotalmass="14",
    )
    default = e.Default()
    size = e.Size(
        nstack="300000",
        nuser_geom="1",
    )
    option = e.Option(
        gravity="0 0 -9.81",
        timestep="0.01",
    )
    asset = e.Asset()
    worldbody = e.Worldbody()
    actuator = e.Actuator()
    mujoco.add_children([
        compiler,
        default,
        size,
        option,
        asset,
        worldbody,
        actuator,
    ])
    joint = e.Joint(
        armature=".1",
        damping=".01",
        limited="true",
        solimplimit="0 .8 .03",
        solreflimit=".02 1",
        stiffness="8",
    )
    geom = e.Geom(
        conaffinity="0",
        condim="3",
        contype="1",
        friction=".4 .1 .1",
        rgba="0.8 0.6 .4 1",
        solimp="0.0 0.8 0.01",
        solref="0.02 1",
    )
    motor = e.Motor(
        ctrllimited="true",
        ctrlrange="-1 1",
    )
    default.add_children([
        joint,
        geom,
        motor,
    ])
    texture = e.Texture(
        builtin="gradient",
        height="100",
        rgb1="1 1 1",
        rgb2="0 0 0",
        type="skybox",
        width="100",
    )
    texgeom = e.Texture(
        builtin="flat",
        height="1278",
        mark="cross",
        markrgb="1 1 1",
        name="texgeom",
        random="0.01",
        rgb1="0.8 0.6 0.4",
        rgb2="0.8 0.6 0.4",
        type="cube",
        width="127",
    )
    texplane = e.Texture(
        builtin="checker",
        height="100",
        name="texplane",
        rgb1="0 0 0",
        rgb2="0.8 0.8 0.8",
        type="2d",
        width="100",
    )
    MatPlane = e.Material(
        name="MatPlane",
        reflectance="0.5",
        shininess="1",
        specular="1",
        texrepeat="60 60",
        texture="texplane",
    )
    geom_1 = e.Material(
        name="geom",
        texture="texgeom",
        texuniform="true",
    )
    asset.add_children([
        texture,
        texgeom,
        texplane,
        MatPlane,
        geom_1,
    ])
    light = e.Light(
        cutoff="100",
        diffuse="1 1 1",
        dir="-0 0 -1.3",
        directional="true",
        exponent="1",
        pos="0 0 1.3",
        specular=".1 .1 .1",
    )
    floor = e.Geom(
        conaffinity="1",
        condim="3",
        material="MatPlane",
        name="floor",
        pos="0 0 0",
        rgba="0.8 0.9 0.8 1",
        size="40 40 40",
        type="plane",
    )
    torso = e.Body(
        name="torso",
        pos="0 0 .7",
    )
    worldbody.add_children([
        light,
        floor,
        torso,
    ])
    bthigh = e.Motor(
        gear="120",
        joint="bthigh",
        name="bthigh",
    )
    bshin = e.Motor(
        gear="90",
        joint="bshin",
        name="bshin",
    )
    bfoot = e.Motor(
        gear="60",
        joint="bfoot",
        name="bfoot",
    )
    fthigh = e.Motor(
        gear="120",
        joint="fthigh",
        name="fthigh",
    )
    fshin = e.Motor(
        gear="60",
        joint="fshin",
        name="fshin",
    )
    ffoot = e.Motor(
        gear="30",
        joint="ffoot",
        name="ffoot",
    )
    actuator.add_children([
        bthigh,
        bshin,
        bfoot,
        fthigh,
        fshin,
        ffoot,
    ])
    track = e.Camera(
        name="track",
        mode="trackcom",
        pos="0 -3 0.3",
        xyaxes="1 0 0 0 0 1",
    )
    rootx = e.Joint(
        armature="0",
        axis="1 0 0",
        damping="0",
        limited="false",
        name="rootx",
        pos="0 0 0",
        stiffness="0",
        type="slide",
    )
    rootz = e.Joint(
        armature="0",
        axis="0 0 1",
        damping="0",
        limited="false",
        name="rootz",
        pos="0 0 0",
        stiffness="0",
        type="slide",
    )
    rooty = e.Joint(
        armature="0",
        axis="0 1 0",
        damping="0",
        limited="false",
        name="rooty",
        pos="0 0 0",
        stiffness="0",
        type="hinge",
    )
    torso_1 = e.Geom(
        fromto="-.5 0 0 .5 0 0",
        name="torso",
        size="0.046",
        type="capsule",
    )
    head = e.Geom(
        axisangle="0 1 0 .87",
        name="head",
        pos=".6 0 .1",
        size="0.046 .15",
        type="capsule",
    )
    bthigh_1 = e.Body(
        name="bthigh",
        pos="-.5 0 0",
    )
    fthigh_1 = e.Body(
        name="fthigh",
        pos=".5 0 0",
    )
    torso.add_children([
        track,
        rootx,
        rootz,
        rooty,
        torso_1,
        head,
        bthigh_1,
        fthigh_1,
    ])
    bthigh_2 = e.Joint(
        axis="0 1 0",
        damping="6",
        name="bthigh",
        pos="0 0 0",
        range="-.52 1.05",
        stiffness="240",
        type="hinge",
    )
    bthigh_3 = e.Geom(
        axisangle="0 1 0 -3.8",
        name="bthigh",
        pos=".1 0 -.13",
        size="0.046 .145",
        type="capsule",
    )
    bshin_1 = e.Body(
        name="bshin",
        pos=".16 0 -.25",
    )
    bthigh_1.add_children([
        bthigh_2,
        bthigh_3,
        bshin_1,
    ])
    fthigh_2 = e.Joint(
        axis="0 1 0",
        damping="4.5",
        name="fthigh",
        pos="0 0 0",
        range="-1 .7",
        stiffness="180",
        type="hinge",
    )
    fthigh_3 = e.Geom(
        axisangle="0 1 0 .52",
        name="fthigh",
        pos="-.07 0 -.12",
        size="0.046 .133",
        type="capsule",
    )
    fshin_1 = e.Body(
        name="fshin",
        pos="-.14 0 -.24",
    )
    fthigh_1.add_children([
        fthigh_2,
        fthigh_3,
        fshin_1,
    ])
    bshin_2 = e.Joint(
        axis="0 1 0",
        damping="4.5",
        name="bshin",
        pos="0 0 0",
        range="-.785 .785",
        stiffness="180",
        type="hinge",
    )
    bshin_3 = e.Geom(
        axisangle="0 1 0 -2.03",
        name="bshin",
        pos="-.14 0 -.07",
        rgba="0.9 0.6 0.6 1",
        size="0.046 .15",
        type="capsule",
    )
    bfoot_1 = e.Body(
        name="bfoot",
        pos="-.28 0 -.14",
    )
    bshin_1.add_children([
        bshin_2,
        bshin_3,
        bfoot_1,
    ])
    fshin_2 = e.Joint(
        axis="0 1 0",
        damping="3",
        name="fshin",
        pos="0 0 0",
        range="-1.2 .87",
        stiffness="120",
        type="hinge",
    )
    fshin_3 = e.Geom(
        axisangle="0 1 0 -.6",
        name="fshin",
        pos=".065 0 -.09",
        rgba="0.9 0.6 0.6 1",
        size="0.046 .106",
        type="capsule",
    )
    ffoot_1 = e.Body(
        name="ffoot",
        pos=".13 0 -.18",
    )
    fshin_1.add_children([
        fshin_2,
        fshin_3,
        ffoot_1,
    ])
    bfoot_2 = e.Joint(
        axis="0 1 0",
        damping="3",
        name="bfoot",
        pos="0 0 0",
        range="-.4 .785",
        stiffness="120",
        type="hinge",
    )
    bfoot_3 = e.Geom(
        axisangle="0 1 0 -.27",
        name="bfoot",
        pos=".03 0 -.097",
        rgba="0.9 0.6 0.6 1",
        size="0.046 .094",
        type="capsule",
    )
    bfoot_1.add_children([
        bfoot_2,
        bfoot_3,
    ])
    ffoot_2 = e.Joint(
        axis="0 1 0",
        damping="1.5",
        name="ffoot",
        pos="0 0 0",
        range="-.5 .5",
        stiffness="60",
        type="hinge",
    )
    ffoot_3 = e.Geom(
        axisangle="0 1 0 -.6",
        name="ffoot",
        pos=".045 0 -.07",
        rgba="0.9 0.6 0.6 1",
        size="0.046 .07",
        type="capsule",
    )
    ffoot_1.add_children([
        ffoot_2,
        ffoot_3,
    ])

    model_xml = mujoco.xml()

    # Output
    with open('half_cheetah_gen.xml', 'w') as fh:
        fh.write(model_xml)
Beispiel #5
0
def main():

    mujoco = e.Mujoco(model="cartpole", )
    compiler = e.Compiler(
        coordinate="local",
        inertiafromgeom="true",
    )
    custom = e.Custom()
    default = e.Default()
    option = e.Option(
        gravity="1e-5 0 -9.81",
        integrator="RK4",
        timestep="0.01",
    )
    size = e.Size(nstack="3000", )
    worldbody = e.Worldbody()
    actuator = e.Actuator()
    mujoco.add_children([
        compiler,
        custom,
        default,
        option,
        size,
        worldbody,
        actuator,
    ])
    frame_skip = e.Numeric(
        data="2",
        name="frame_skip",
    )
    custom.add_children([
        frame_skip,
    ])
    joint = e.Joint(damping="0.05", )
    geom = e.Geom(
        contype="0",
        friction="1 0.1 0.1",
        rgba="0.7 0.7 0 1",
    )
    default.add_children([
        joint,
        geom,
    ])
    floor = e.Geom(
        name="floor",
        pos="0 0 -3.0",
        rgba="0.8 0.9 0.8 1",
        size="40 40 40",
        type="plane",
    )
    rail = e.Geom(
        name="rail",
        pos="0 0 0",
        quat="0.707 0 0.707 0",
        rgba="0.3 0.3 0.7 1",
        size="0.02 1",
        type="capsule",
    )
    cart = e.Body(
        name="cart",
        pos="0 0 0",
    )
    worldbody.add_children([
        floor,
        rail,
        cart,
    ])
    slide = e.Motor(
        ctrllimited="true",
        ctrlrange="-1 1",
        gear="500",
        joint="slider",
        name="slide",
    )
    actuator.add_children([
        slide,
    ])
    slider = e.Joint(
        axis="1 0 0",
        limited="true",
        margin="0.01",
        name="slider",
        pos="0 0 0",
        range="-1 1",
        type="slide",
    )
    cart_1 = e.Geom(
        name="cart",
        pos="0 0 0",
        quat="0.707 0 0.707 0",
        size="0.1 0.1",
        type="capsule",
    )
    pole = e.Body(
        name="pole",
        pos="0 0 0",
    )
    cart.add_children([
        slider,
        cart_1,
        pole,
    ])
    hinge = e.Joint(
        axis="0 1 0",
        name="hinge",
        pos="0 0 0",
        type="hinge",
    )
    cpole = e.Geom(
        fromto="0 0 0 0 0 0.6",
        name="cpole",
        rgba="0 0.7 0.7 1",
        size="0.045 0.3",
        type="capsule",
    )
    pole2 = e.Body(
        name="pole2",
        pos="0 0 0.6",
    )
    pole.add_children([
        hinge,
        cpole,
        pole2,
    ])
    hinge2 = e.Joint(
        axis="0 1 0",
        name="hinge2",
        pos="0 0 0",
        type="hinge",
    )
    cpole2 = e.Geom(
        fromto="0 0 0 0 0 0.6",
        name="cpole2",
        rgba="0 0.7 0.7 1",
        size="0.045 0.3",
        type="capsule",
    )
    tip = e.Site(
        name="tip",
        pos="0 0 .6",
        size="0.01 0.01",
    )
    pole2.add_children([
        hinge2,
        cpole2,
        tip,
    ])

    model_xml = mujoco.xml()

    # Output
    with open('inverted_double_pendulum_gen.xml', 'w') as fh:
        fh.write(model_xml)
Beispiel #6
0
def main():

    mujoco = e.Mujoco(model="swimmer", )
    compiler = e.Compiler(
        angle="degree",
        coordinate="local",
        inertiafromgeom="true",
    )
    option = e.Option(
        collision="predefined",
        density="4000",
        integrator="RK4",
        timestep="0.01",
        viscosity="0.1",
    )
    default = e.Default()
    asset = e.Asset()
    worldbody = e.Worldbody()
    actuator = e.Actuator()
    mujoco.add_children([
        compiler,
        option,
        default,
        asset,
        worldbody,
        actuator,
    ])
    geom = e.Geom(
        conaffinity="1",
        condim="1",
        contype="1",
        material="geom",
        rgba="0.8 0.6 .4 1",
    )
    joint = e.Joint(armature="0.1", )
    default.add_children([
        geom,
        joint,
    ])
    texture = e.Texture(
        builtin="gradient",
        height="100",
        rgb1="1 1 1",
        rgb2="0 0 0",
        type="skybox",
        width="100",
    )
    texgeom = e.Texture(
        builtin="flat",
        height="1278",
        mark="cross",
        markrgb="1 1 1",
        name="texgeom",
        random="0.01",
        rgb1="0.8 0.6 0.4",
        rgb2="0.8 0.6 0.4",
        type="cube",
        width="127",
    )
    texplane = e.Texture(
        builtin="checker",
        height="100",
        name="texplane",
        rgb1="0 0 0",
        rgb2="0.8 0.8 0.8",
        type="2d",
        width="100",
    )
    MatPlane = e.Material(
        name="MatPlane",
        reflectance="0.5",
        shininess="1",
        specular="1",
        texrepeat="30 30",
        texture="texplane",
    )
    geom_1 = e.Material(
        name="geom",
        texture="texgeom",
        texuniform="true",
    )
    asset.add_children([
        texture,
        texgeom,
        texplane,
        MatPlane,
        geom_1,
    ])
    light = e.Light(
        cutoff="100",
        diffuse="1 1 1",
        dir="-0 0 -1.3",
        directional="true",
        exponent="1",
        pos="0 0 1.3",
        specular=".1 .1 .1",
    )
    floor = e.Geom(
        conaffinity="1",
        condim="3",
        material="MatPlane",
        name="floor",
        pos="0 0 -0.1",
        rgba="0.8 0.9 0.8 1",
        size="40 40 0.1",
        type="plane",
    )
    torso = e.Body(
        name="torso",
        pos="0 0 0",
    )
    worldbody.add_children([
        light,
        floor,
        torso,
    ])
    motor = e.Motor(
        ctrllimited="true",
        ctrlrange="-1 1",
        gear="150.0",
        joint="rot2",
    )
    motor_1 = e.Motor(
        ctrllimited="true",
        ctrlrange="-1 1",
        gear="150.0",
        joint="rot3",
    )
    actuator.add_children([
        motor,
        motor_1,
    ])
    geom_2 = e.Geom(
        density="1000",
        fromto="1.5 0 0 0.5 0 0",
        size="0.1",
        type="capsule",
    )
    slider1 = e.Joint(
        axis="1 0 0",
        name="slider1",
        pos="0 0 0",
        type="slide",
    )
    slider2 = e.Joint(
        axis="0 1 0",
        name="slider2",
        pos="0 0 0",
        type="slide",
    )
    rot = e.Joint(
        axis="0 0 1",
        name="rot",
        pos="0 0 0",
        type="hinge",
    )
    mid = e.Body(
        name="mid",
        pos="0.5 0 0",
    )
    torso.add_children([
        geom_2,
        slider1,
        slider2,
        rot,
        mid,
    ])
    geom_3 = e.Geom(
        density="1000",
        fromto="0 0 0 -1 0 0",
        size="0.1",
        type="capsule",
    )
    rot2 = e.Joint(
        axis="0 0 1",
        limited="true",
        name="rot2",
        pos="0 0 0",
        range="-100 100",
        type="hinge",
    )
    back = e.Body(
        name="back",
        pos="-1 0 0",
    )
    mid.add_children([
        geom_3,
        rot2,
        back,
    ])
    geom_4 = e.Geom(
        density="1000",
        fromto="0 0 0 -1 0 0",
        size="0.1",
        type="capsule",
    )
    rot3 = e.Joint(
        axis="0 0 1",
        limited="true",
        name="rot3",
        pos="0 0 0",
        range="-100 100",
        type="hinge",
    )
    back.add_children([
        geom_4,
        rot3,
    ])

    model_xml = mujoco.xml()

    # Output
    with open('swimmer_gen.xml', 'w') as fh:
        fh.write(model_xml)
Beispiel #7
0
def main():

    mujoco = e.Mujoco(model="arm3d", )
    compiler = e.Compiler(
        inertiafromgeom="true",
        angle="radian",
        coordinate="local",
    )
    option = e.Option(
        timestep="0.01",
        gravity="0 0 0",
        iterations="20",
        integrator="Euler",
    )
    default = e.Default()
    worldbody = e.Worldbody()
    actuator = e.Actuator()
    mujoco.add_children([
        compiler,
        option,
        default,
        worldbody,
        actuator,
    ])
    joint = e.Joint(
        armature="0.04",
        damping="1",
        limited="true",
    )
    geom = e.Geom(
        friction=".0 .0 .0",
        density="300",
        margin="0.002",
        condim="1",
        contype="0",
        conaffinity="0",
    )
    default.add_children([
        joint,
        geom,
    ])
    light = e.Light(
        diffuse=".5 .5 .5",
        pos="0 0 3",
        dir="0 0 -1",
    )
    table = e.Geom(
        name="table",
        type="plane",
        pos="0 0.5 -0.325",
        size="1 1 0.1",
        contype="1",
        conaffinity="1",
    )
    r_shoulder_pan_link = e.Body(
        name="r_shoulder_pan_link",
        pos="0 -0.6 0",
    )
    object = e.Body(
        name="object",
        pos="0 0 -0.270",
    )
    goal = e.Body(
        name="goal",
        pos="0.0 0.0 -0.3230",
    )
    worldbody.add_children([
        light,
        table,
        r_shoulder_pan_link,
        object,
        goal,
    ])
    motor = e.Motor(
        joint="r_shoulder_pan_joint",
        ctrlrange="-3.0 3.0",
        ctrllimited="true",
    )
    motor_1 = e.Motor(
        joint="r_shoulder_lift_joint",
        ctrlrange="-3.0 3.0",
        ctrllimited="true",
    )
    motor_2 = e.Motor(
        joint="r_upper_arm_roll_joint",
        ctrlrange="-3.0 3.0",
        ctrllimited="true",
    )
    motor_3 = e.Motor(
        joint="r_elbow_flex_joint",
        ctrlrange="-3.0 3.0",
        ctrllimited="true",
    )
    motor_4 = e.Motor(
        joint="r_forearm_roll_joint",
        ctrlrange="-3.0 3.0",
        ctrllimited="true",
    )
    motor_5 = e.Motor(
        joint="r_wrist_flex_joint",
        ctrlrange="-3.0 3.0",
        ctrllimited="true",
    )
    motor_6 = e.Motor(
        joint="r_wrist_roll_joint",
        ctrlrange="-3.0 3.0",
        ctrllimited="true",
    )
    actuator.add_children([
        motor,
        motor_1,
        motor_2,
        motor_3,
        motor_4,
        motor_5,
        motor_6,
    ])
    e1 = e.Geom(
        name="e1",
        type="sphere",
        rgba="0.6 0.6 0.6 1",
        pos="-0.06 0.05 0.2",
        size="0.05",
    )
    e2 = e.Geom(
        name="e2",
        type="sphere",
        rgba="0.6 0.6 0.6 1",
        pos=" 0.06 0.05 0.2",
        size="0.05",
    )
    e1p = e.Geom(
        name="e1p",
        type="sphere",
        rgba="0.1 0.1 0.1 1",
        pos="-0.06 0.09 0.2",
        size="0.03",
    )
    e2p = e.Geom(
        name="e2p",
        type="sphere",
        rgba="0.1 0.1 0.1 1",
        pos=" 0.06 0.09 0.2",
        size="0.03",
    )
    sp = e.Geom(
        name="sp",
        type="capsule",
        fromto="0 0 -0.4 0 0 0.2",
        size="0.1",
    )
    r_shoulder_pan_joint = e.Joint(
        name="r_shoulder_pan_joint",
        type="hinge",
        pos="0 0 0",
        axis="0 0 1",
        range="-2.2854 1.714602",
        damping="1.0",
    )
    r_shoulder_lift_link = e.Body(
        name="r_shoulder_lift_link",
        pos="0.1 0 0",
    )
    r_shoulder_pan_link.add_children([
        e1,
        e2,
        e1p,
        e2p,
        sp,
        r_shoulder_pan_joint,
        r_shoulder_lift_link,
    ])
    geom_1 = e.Geom(
        type="sphere",
        rgba="1 1 1 1",
        pos="0 0 0",
        size="0.05 0.05 0.05",
        contype="1",
        conaffinity="0",
    )
    obj_slidey = e.Joint(
        name="obj_slidey",
        armature="0.1",
        type="slide",
        pos="0 0 0",
        axis="0 1 0",
        range="-10.3213 10.3",
        damping="0.5",
    )
    obj_slidex = e.Joint(
        name="obj_slidex",
        armature="0.1",
        type="slide",
        pos="0 0 0",
        axis="1 0 0",
        range="-10.3213 10.3",
        damping="0.5",
    )
    object.add_children([
        geom_1,
        obj_slidey,
        obj_slidex,
    ])
    geom_2 = e.Geom(
        rgba="1. 1. 1. 0",
        pos="0 0 0",
        type="box",
        size="0.01 0.01 0.01",
        contype="0",
        conaffinity="0",
    )
    body = e.Body(pos="0 0 0", )
    coaster = e.Body(
        name="coaster",
        pos="0 0 0",
    )
    body_1 = e.Body(
        pos="0 0 0",
        axisangle="0 0 1 0.785",
    )
    body_2 = e.Body(
        pos="0 0 0",
        axisangle="0 0 1 -0.785",
    )
    goal_free = e.Joint(
        name="goal_free",
        type="free",
        pos="0 0 0",
        limited="false",
        damping="0",
    )
    goal.add_children([
        geom_2,
        body,
        coaster,
        body_1,
        body_2,
        goal_free,
    ])
    sl = e.Geom(
        name="sl",
        type="capsule",
        fromto="0 -0.1 0 0 0.1 0",
        size="0.1",
    )
    r_shoulder_lift_joint = e.Joint(
        name="r_shoulder_lift_joint",
        type="hinge",
        pos="0 0 0",
        axis="0 1 0",
        range="-0.5236 1.3963",
        damping="1.0",
    )
    r_upper_arm_roll_link = e.Body(
        name="r_upper_arm_roll_link",
        pos="0 0 0",
    )
    r_shoulder_lift_link.add_children([
        sl,
        r_shoulder_lift_joint,
        r_upper_arm_roll_link,
    ])
    geom_3 = e.Geom(
        rgba="1. 1. 1. 1",
        pos="0 0.075 0.04",
        type="box",
        size="0.032 0.001 0.04",
        contype="0",
        conaffinity="1",
    )
    body.add_children([
        geom_3,
    ])
    geom_4 = e.Geom(
        rgba="1. 1. 1. 1",
        type="cylinder",
        size="0.08 0.001 0.1",
        density="1000000",
        contype="0",
        conaffinity="0",
    )
    coaster.add_children([
        geom_4,
    ])
    geom_5 = e.Geom(
        rgba="1. 1. 1. 1",
        pos="0 0.075 0.04",
        type="box",
        size="0.032 0.001 0.04",
        contype="0",
        conaffinity="1",
    )
    body_1.add_children([
        geom_5,
    ])
    geom_6 = e.Geom(
        rgba="1. 1. 1. 1",
        pos="0 0.075 0.04",
        type="box",
        size="0.032 0.001 0.04",
        contype="0",
        conaffinity="1",
    )
    body_2.add_children([
        geom_6,
    ])
    uar = e.Geom(
        name="uar",
        type="capsule",
        fromto="-0.1 0 0 0.1 0 0",
        size="0.02",
    )
    r_upper_arm_roll_joint = e.Joint(
        name="r_upper_arm_roll_joint",
        type="hinge",
        pos="0 0 0",
        axis="1 0 0",
        range="-1.5 1.7",
        damping="0.1",
    )
    r_upper_arm_link = e.Body(
        name="r_upper_arm_link",
        pos="0 0 0",
    )
    r_upper_arm_roll_link.add_children([
        uar,
        r_upper_arm_roll_joint,
        r_upper_arm_link,
    ])
    ua = e.Geom(
        name="ua",
        type="capsule",
        fromto="0 0 0 0.4 0 0",
        size="0.06",
    )
    r_elbow_flex_link = e.Body(
        name="r_elbow_flex_link",
        pos="0.4 0 0",
    )
    r_upper_arm_link.add_children([
        ua,
        r_elbow_flex_link,
    ])
    ef = e.Geom(
        name="ef",
        type="capsule",
        fromto="0 -0.02 0 0.0 0.02 0",
        size="0.06",
    )
    r_elbow_flex_joint = e.Joint(
        name="r_elbow_flex_joint",
        type="hinge",
        pos="0 0 0",
        axis="0 1 0",
        range="-2.3213 0",
        damping="0.1",
    )
    r_forearm_roll_link = e.Body(
        name="r_forearm_roll_link",
        pos="0 0 0",
    )
    r_elbow_flex_link.add_children([
        ef,
        r_elbow_flex_joint,
        r_forearm_roll_link,
    ])
    fr = e.Geom(
        name="fr",
        type="capsule",
        fromto="-0.1 0 0 0.1 0 0",
        size="0.02",
    )
    r_forearm_roll_joint = e.Joint(
        name="r_forearm_roll_joint",
        type="hinge",
        limited="true",
        pos="0 0 0",
        axis="1 0 0",
        damping=".1",
        range="-1.5 1.5",
    )
    r_forearm_link = e.Body(
        name="r_forearm_link",
        pos="0 0 0",
    )
    r_forearm_roll_link.add_children([
        fr,
        r_forearm_roll_joint,
        r_forearm_link,
    ])
    fa = e.Geom(
        name="fa",
        type="capsule",
        fromto="0 0 0 0.291 0 0",
        size="0.05",
    )
    r_wrist_flex_link = e.Body(
        name="r_wrist_flex_link",
        pos="0.321 0 0",
    )
    r_forearm_link.add_children([
        fa,
        r_wrist_flex_link,
    ])
    wf = e.Geom(
        name="wf",
        type="capsule",
        fromto="0 -0.02 0 0 0.02 0",
        size="0.01",
    )
    r_wrist_flex_joint = e.Joint(
        name="r_wrist_flex_joint",
        type="hinge",
        pos="0 0 0",
        axis="0 1 0",
        range="-1.094 0",
        damping=".1",
    )
    r_wrist_roll_link = e.Body(
        name="r_wrist_roll_link",
        pos="0 0 0",
    )
    r_wrist_flex_link.add_children([
        wf,
        r_wrist_flex_joint,
        r_wrist_roll_link,
    ])
    r_wrist_roll_joint = e.Joint(
        name="r_wrist_roll_joint",
        type="hinge",
        pos="0 0 0",
        limited="true",
        axis="1 0 0",
        damping="0.1",
        range="-1.5 1.5",
    )
    tips_arm = e.Body(
        name="tips_arm",
        pos="0 0 0",
    )
    geom_7 = e.Geom(
        conaffinity="1",
        contype="1",
        fromto="0 -0.1 0. 0.0 +0.1 0",
        size="0.02",
        type="capsule",
    )
    r_wrist_roll_link.add_children([
        r_wrist_roll_joint,
        tips_arm,
        geom_7,
    ])
    tip_arml = e.Geom(
        conaffinity="1",
        contype="1",
        name="tip_arml",
        pos="0.017 0 0",
        size="0.003 0.12 0.05",
        type="box",
    )
    tips_arm.add_children([
        tip_arml,
    ])

    model_xml = mujoco.xml()

    # Output
    with open('striker_gen.xml', 'w') as fh:
        fh.write(model_xml)
Beispiel #8
0
def main():

    mujoco = e.Mujoco(
        model="inverted pendulum",
    )
    compiler = e.Compiler(
        inertiafromgeom="true",
    )
    default = e.Default(
    )
    option = e.Option(
        gravity="0 0 -9.81",
        integrator="RK4",
        timestep="0.02",
    )
    size = e.Size(
        nstack="3000",
    )
    worldbody = e.Worldbody(
    )
    actuator = e.Actuator(
    )
    mujoco.add_children([
        compiler,
        default,
        option,
        size,
        worldbody,
        actuator,
    ])
    joint = e.Joint(
        armature="0",
        damping="1",
        limited="true",
    )
    geom = e.Geom(
        contype="0",
        friction="1 0.1 0.1",
        rgba="0.7 0.7 0 1",
    )
    tendon = e.Tendon(
    )
    motor = e.Motor(
        ctrlrange="-3 3",
    )
    default.add_children([
        joint,
        geom,
        tendon,
        motor,
    ])
    rail = e.Geom(
        name="rail",
        pos="0 0 0",
        quat="0.707 0 0.707 0",
        rgba="0.3 0.3 0.7 1",
        size="0.02 1",
        type="capsule",
    )
    cart = e.Body(
        name="cart",
        pos="0 0 0",
    )
    worldbody.add_children([
        rail,
        cart,
    ])
    slide = e.Motor(
        gear="100",
        joint="slider",
        name="slide",
    )
    actuator.add_children([
        slide,
    ])
    slider = e.Joint(
        axis="1 0 0",
        limited="true",
        name="slider",
        pos="0 0 0",
        range="-1 1",
        type="slide",
    )
    cart_1 = e.Geom(
        name="cart",
        pos="0 0 0",
        quat="0.707 0 0.707 0",
        size="0.1 0.1",
        type="capsule",
    )
    pole = e.Body(
        name="pole",
        pos="0 0 0",
    )
    cart.add_children([
        slider,
        cart_1,
        pole,
    ])
    hinge = e.Joint(
        axis="0 1 0",
        name="hinge",
        pos="0 0 0",
        range="-90 90",
        type="hinge",
    )
    cpole = e.Geom(
        fromto="0 0 0 0.001 0 0.6",
        name="cpole",
        rgba="0 0.7 0.7 1",
        size="0.049 0.3",
        type="capsule",
    )
    pole.add_children([
        hinge,
        cpole,
    ])

    model_xml = mujoco.xml()

    # Output
    with open('inverted_pendulum_gen.xml', 'w') as fh:
        fh.write(model_xml)
Beispiel #9
0
def main(dataset_file):
    #Path maker
    handle_folder = os.path.join(args.input_dirname.format(knob_type),
                                 dataset_file)
    stl_path = os.path.join('door/{}knobs'.format(knob_type), dataset_file)
    robot_path = "../../robot/{}.xml"
    knob_stl_path = '../../{0}/body_{1}.stl'

    with open(os.path.join(handle_folder, 'info.json'), 'r') as f:
        params_dict = json.load(f)
    #STL parts number
    door_parts_n = 1
    frame_parts_n = 6
    wall_parts_n = 3
    knob_parts_n = params_dict['model_count']

    ###################### Randomize Parameters ######################
    # Lighting property
    light_n = randrange(2, 6)

    # Camera property
    camera_random = False
    camera1_pos = [0.99, -0.5, 1.0]  #1m x 1m
    camera1_ori = [0.0, 1.57, 1.57]
    camera2_pos = [0.5, 0.0, 1.99]  #1m x 1m
    camera2_ori = [0, 0, 0]
    camera_fieldview = 60
    if camera_random:
        for i in range(len(camera1_pos)):
            camera1_pos[i] += randrange(-15, 15) / 1000
            camera2_pos[i] += randrange(-15, 15) / 1000
        for i in range(len(camera1_ori)):
            camera1_ori[i] += randrange(-52, 52) / 1000
            camera2_ori[i] += randrange(-52, 52) / 1000
    camera_poses = [camera1_pos, camera2_pos]
    camera_ories = [camera1_ori, camera2_ori]
    camera_fieldview_noise = [0, 0]

    # Wall property
    wall_shininess = randrange(1, 50) / 100.0
    wall_specular = randrange(1, 50) / 100.0
    wall_rgba = [
        randrange(1, 85) / 100.0,
        randrange(1, 85) / 100.0,
        randrange(1, 85) / 100.0, 1.0
    ]
    wall_location = [0.0, randrange(-100, 100) / 1000.0, 0.0]

    # Frame property
    frame_shininess = randrange(70, 99) / 100.0
    frame_specular = randrange(50, 99) / 100.0
    frame_rgba = [
        randrange(70, 85) / 100.0,
        randrange(70, 85) / 100.0,
        randrange(70, 85) / 100.0, 1.0
    ]

    # Door Frame Joint Property
    if args.righthinge_ratio > randrange(0, 100) / 100.0:
        hinge_loc = "righthinge"
    else:
        hinge_loc = "lefthinge"

    if args.pulldoor_ratio > randrange(0, 100) / 100.0:
        opendir = "pull"
    else:
        opendir = "push"

    door_frame_damper = randrange(10, 20) / 100.0
    # door_frame_spring = randrange(9, 10)
    door_frame_spring = randrange(10, 20) / 100.0
    door_frame_frictionloss = randrange(0, 1)

    # Door property
    door_height = randrange(2000, 2500) / 1000.0
    door_width = randrange(800, 1200) / 1000.0
    door_thickness = randrange(20, 30) / 1000.0
    # knob_height = randrange(864, 1219)/1000.0
    knob_height = randrange(990, 1010) / 1000.0
    knob_horizontal_location_ratio = randrange(
        10, 20) / 100.0  #height-ratio and from-side-ratio of knob
    door_mass = door_height * door_width * door_thickness * randrange(
        200, 300)  # (700,850) Density of MDF
    door_shininess = randrange(1, 50) / 100.0
    door_specular = randrange(1, 80) / 100.0
    door_rgba = [
        randrange(1, 100) / 100.0,
        randrange(1, 100) / 100.0,
        randrange(1, 100) / 100.0, 1.0
    ]

    # Knob Door Joint Property
    knob_door_damper = randrange(10, 20) / 100.0
    knob_door_spring = randrange(10, 15) / 100.0
    knob_door_frictionloss = randrange(0, 1)
    knob_rot_range = randrange(75, 80) * 3.14 / 180

    # Knob property
    if hinge_loc == "righthinge":
        doorknob_pos = [0, 0, 0]
        knob_euler = [-1.57, 1.57, 0]
    else:
        doorknob_pos = [
            0, (0.5 - knob_horizontal_location_ratio) * door_width * 2, 0
        ]
        knob_euler = [1.57, 1.57, 0]

    knob_mass = randrange(1, 2)
    knob_shininess = randrange(50, 100) / 100.0
    knob_specular = randrange(80, 100) / 100.0
    knob_rgba = [
        randrange(1, 100) / 100.0,
        randrange(1, 100) / 100.0,
        randrange(1, 100) / 100.0, 1.0
    ]
    knob_surface_friction = [
        randrange(50, 100) / 100.0,
        randrange(1, 5) / 1000.0,
        randrange(1, 5) / 1000.0
    ]

    # Robot property
    robot_damping = randrange(9, 11) / 100  #OpenAI suggest 0.1-3 loguniform

    ###################### Constant Parameters ######################
    # gravity
    if args.robot_type.find("floating") > -1:
        gravity_vector = [0, 0, 0]
    else:
        gravity_vector = [0, 0, -9.81]

    # Stationaly Camera number
    camera_n = 2

    # Wall property
    sidewall_len = 2000 / 1000.0
    topwall_width = 1000 / 1000.0
    wall_thickness = 300 / 1000.0
    wall_euler = [0, 0, 0]
    wall_mass = 100
    wall_diaginertia = [0.0001, 0.0001, 0.0001]

    # wall Frame Joint Property
    frame_wall_armature = 0.0001
    frame_wall_damper = 100000000
    frame_wall_spring = 1000
    frame_wall_frictionloss = 0
    frame_wall_joint_pos = [0, 0, 0]

    # Frame property
    frame_width = 100 / 1000.0
    overlap_door_frame = 10 / 1000.0
    frame_world_pos = [
        0, -(0.5 - knob_horizontal_location_ratio) * door_width, knob_height
    ]
    frame_euler = [0, 0, 0]
    frame_mass = 500
    frame_diaginertia = [0.0001, 0.0001, 0.0001]
    doorstopper_size = [door_thickness / 2.0, 0.05, 0.025]

    if opendir == "push":
        if hinge_loc == "righthinge":
            doorstopper_pos = [
                door_thickness * 2.3,
                -door_width * knob_horizontal_location_ratio + 0.15,
                door_height - knob_height - 0.05
            ]
        else:
            doorstopper_pos = [
                door_thickness * 2.3, door_width -
                door_width * knob_horizontal_location_ratio - 0.15,
                door_height - knob_height - 0.05
            ]
    else:
        if hinge_loc == "righthinge":
            doorstopper_pos = [
                0 - door_thickness * 0.7,
                -door_width * knob_horizontal_location_ratio + 0.15,
                door_height - knob_height - 0.05
            ]
        else:
            doorstopper_pos = [
                0 - door_thickness * 0.7, door_width -
                door_width * knob_horizontal_location_ratio - 0.15,
                door_height - knob_height - 0.05
            ]

    # Door Frame Joint Property
    door_frame_armature = 0.0001
    door_frame_limited = False
    door_frame_range = [-0.5, 0.5]

    if hinge_loc == "righthinge":
        door_frame_joint_pos = [
            0, door_width - door_width * knob_horizontal_location_ratio, 0
        ]
    else:
        door_frame_joint_pos = [
            0, -door_width * knob_horizontal_location_ratio, 0
        ]
    # Door property
    door_diaginertia = [
        door_mass / 12.0 * (door_height**2 + door_width**2),
        door_mass / 12.0 * (door_height**2 + door_thickness**2),
        door_mass / 12.0 * (door_width**2 + door_thickness**2)
    ]
    door_euler = [0, 0, 0]
    door_pos = [door_thickness * 1.1, 0, 0]

    # Knob Door Joint Property
    knob_door_joint_pos = [0, 0, 0]
    knob_door_armature = 0.0001
    knob_door_limited = True
    knob_door_range = [-knob_rot_range, knob_rot_range]
    latch_thickness = 0.05
    latch_height = 0.05
    latch_width = (door_width * knob_horizontal_location_ratio) * 1.3
    latch_gap = latch_thickness * 1.05

    # Knob property
    if knob_type == "pull":
        knob_pos = [door_thickness / 2 - 0.006, 0, 0]
    else:
        knob_pos = [door_thickness / 2, 0, 0]
    knob_diaginertia = [
        knob_mass / 12.0 * (latch_height**2 + latch_width**2),
        knob_mass / 12.0 * (latch_height**2 + latch_thickness**2),
        knob_mass / 12.0 * (latch_width**2 + latch_thickness**2)
    ]

    ###################### XML Generator ######################
    # Level 1
    mujoco = e.Mujoco(model="door_knob")

    #########################
    # Level 2
    compiler = e.Compiler(angle="radian")

    include = e.Include(file=robot_path.format(robot_type))
    option = e.Option(gravity=gravity_vector, timestep=0.001)
    visual = e.Visual()
    asset = e.Asset()
    contact = e.Contact()
    default = e.Default()
    worldbody = e.Worldbody()

    mujoco.add_children([
        compiler, include, option, visual, asset, contact, default, worldbody
    ])

    ######################
    # Level 3

    # Visual
    visual_list = []
    v_map = e.visual.Map(fogstart=3, fogend=5, force=0.1, znear=0.01, zfar=10)
    v_quality = v.Quality(shadowsize=2048)
    v_global = v.Global(offwidth=256, offheight=256)
    visual_list.append(v_map)
    visual_list.append(v_quality)
    visual_list.append(v_global)
    visual.add_children(visual_list)

    # Asset
    if knob_type == "lever":
        knob_scale = [0.0015, 0.0015, 0.0015]
    else:
        knob_scale = [0.001, 0.001, 0.001]
    mesh_knob = []
    name = 'door_knob_{}'
    for i in range(1, knob_parts_n + 1):
        mesh_knob.append(
            e.Mesh(file=knob_stl_path.format(stl_path, i),
                   name=name.format(i),
                   scale=knob_scale))

    texture_list = []
    texture_name_list = ['wall_geom', 'frame_geom', 'door_geom', 'knob_geom']
    texture_type_list = ['2d', '2d', '2d', '2d']
    for i in range(len(texture_name_list)):
        texture_list.append(
            e.Texture(builtin="flat",
                      name=texture_name_list[i],
                      height=32,
                      width=32,
                      type=texture_type_list[i]))

    #Sky color
    texture_list.append(
        e.Texture(type="skybox",
                  builtin="gradient",
                  width=128,
                  height=128,
                  rgb1=[.4, .6, .8],
                  rgb2=[0, 0, 0]))

    #Floor color
    texture_list.append(
        e.Texture(name='texplane',
                  type='2d',
                  builtin='checker',
                  rgb1=[0.2, 0.3, 0.4],
                  rgb2=[0.1, 0.15, 0.2],
                  width=512,
                  height=512))

    material_list = []
    material_name_list = ['Paint', 'Wood', 'Metal', 'Carpet']
    material_shininess_list = [
        wall_shininess, frame_shininess, door_shininess, knob_shininess
    ]
    material_specular_list = [
        wall_specular, frame_specular, door_specular, knob_specular
    ]
    for i in range(len(material_name_list)):
        material_list.append(
            e.Material(name=material_name_list[i],
                       texture=texture_name_list[i],
                       shininess=material_shininess_list[i],
                       specular=material_specular_list[i]))

    material_list.append(e.Material(name="Floor", texture="texplane"))

    asset_list = mesh_knob
    asset_list.extend(texture_list)
    asset_list.extend(material_list)
    asset.add_children(asset_list)

    #Contact
    doorstopper_contact = e.Pair(geom1="doorstopper",
                                 geom2="door0",
                                 solref="0.01 1")
    latch_contacts = []
    for i in range(4):
        latch_contacts.append(
            e.Pair(geom1="knob_latch",
                   geom2="door_frame_{}".format(i),
                   solref="0.01 1"))

    contact_list = [doorstopper_contact]
    if knob_type != "pull":
        contact_list.extend(latch_contacts)
    contact.add_children(contact_list)

    joint_default = e.Joint(armature=1, damping=1, limited="true")

    wall_default = e.Default(class_='wall')
    wall_geom = e.Geom(type='mesh', rgba=wall_rgba)
    wall_default.add_child(wall_geom)

    frame_default = e.Default(class_='frame')
    frame_geom = e.Geom(type='mesh', rgba=frame_rgba)
    frame_default.add_child(frame_geom)

    door_default = e.Default(class_='door')
    door_geom = e.Geom(type='mesh', rgba=door_rgba)
    door_default.add_child(door_geom)

    knob_default = e.Default(class_='door_knob')
    knob_geom = e.Geom(condim=4, type="mesh", rgba=knob_rgba)
    knob_default.add_child(knob_geom)

    robot_default = e.Default(class_='robot')
    robot_joint = e.Joint(damping=robot_damping)
    robot_motor = e.Motor(ctrllimited='true')
    robot_default.add_children([robot_joint, robot_motor])

    default.add_children([
        joint_default, wall_default, frame_default, door_default, knob_default,
        robot_default
    ])

    # Worldbody
    light_condition_list = []
    for i in range(light_n):
        light_condition_list.append(
            e.Light(directional=True,
                    diffuse=[
                        randrange(0, 10) / 10,
                        randrange(0, 10) / 10,
                        randrange(0, 10) / 10
                    ],
                    pos=[
                        randrange(0, 500) / 100.0,
                        randrange(-500, 500) / 100.0,
                        randrange(300, 700) / 100.0
                    ],
                    dir=[
                        randrange(-50, 50) / 100.0,
                        randrange(-50, 50) / 100.0,
                        randrange(-50, -25) / 100.0
                    ]))

    floor_geom = e.Geom(name='floor',
                        material="Floor",
                        pos=[0, 0, -0.05],
                        size=[40.0, 40.0, 0.05],
                        type='plane')

    #Camera
    camera_list = []
    camera_names = ["camera1", "camera2"]
    for i in range(camera_n):
        camera_list.append(
            e.Camera(name=camera_names[i],
                     mode="fixed",
                     fovy=camera_fieldview + camera_fieldview_noise[i],
                     pos=camera_poses[i],
                     euler=camera_ories[i]))

    ####### All body obj #######
    body0 = e.Body(name='wall_link', pos=wall_location, childclass='wall')

    body1 = e.Body(name='frame_link', pos=frame_world_pos, childclass='frame')

    body2 = e.Body(name='door_link', pos=door_pos, childclass='door')

    body3 = e.Body(name='knob_link'.format(knob_type),
                   pos=doorknob_pos,
                   childclass='door_knob')

    body4 = e.Body(name='{}knob_link'.format(knob_type),
                   pos=knob_pos,
                   childclass='door_knob')

    worldbody.add_children(light_condition_list)
    worldbody.add_child(floor_geom)
    worldbody.add_children(camera_list)
    worldbody.add_children([body0])

    # ######## Level0 body (origin) ########
    body0_inertial = e.Inertial(pos=[0, 0, 0],
                                mass=wall_mass,
                                diaginertia=wall_diaginertia)

    body0_geoms = []
    name = 'wall_{}'
    pos_list = [[
        0, -door_width / 2.0 - frame_width - sidewall_len / 2.0 + 0.03,
        (door_height + frame_width) / 2.0
    ],
                [
                    0, door_width / 2.0 + frame_width + sidewall_len / 2.0,
                    (door_height + frame_width) / 2.0
                ], [0, 0, door_height + frame_width + topwall_width / 2.0]]
    size_list = [[
        wall_thickness / 2.0, sidewall_len / 2.0,
        (door_height + frame_width) / 2.0
    ],
                 [
                     wall_thickness / 2.0, sidewall_len / 2.0,
                     (door_height + frame_width) / 2.0
                 ],
                 [
                     wall_thickness / 2.0,
                     door_width / 2.0 + frame_width + sidewall_len,
                     topwall_width / 2.0
                 ]]
    wall_material = material_name_list[randrange(0, 3)]
    for i in range(wall_parts_n):
        body0_geoms.append(
            e.Geom(name=name.format(i),
                   material=wall_material,
                   pos=pos_list[i],
                   size=size_list[i],
                   type='box',
                   euler=frame_euler))

    body0_children_list = [body0_inertial]
    body0_children_list.extend(body0_geoms)
    body0.add_children(body0_children_list)
    body0.add_children([body1])

    ######## Level1 body (Frame) ########
    body1_inertial = e.Inertial(pos=[0, 0, 0],
                                mass=frame_mass,
                                diaginertia=frame_diaginertia)

    body1_geoms = []

    # door stopper to define the pull/push opening direction
    body1_geoms.append(
        e.Geom(name='doorstopper',
               material='Metal',
               pos=doorstopper_pos,
               size=doorstopper_size,
               type='box',
               euler=frame_euler))

    # Actual frame
    name = 'door_frame_{}'
    pos_list = [
        [
            0, -door_width * knob_horizontal_location_ratio -
            frame_width / 2.0 - overlap_door_frame,
            (door_height + frame_width) / 2.0 - knob_height
        ],
        [
            0, door_width - door_width * knob_horizontal_location_ratio +
            frame_width / 2.0 + overlap_door_frame,
            (door_height + frame_width) / 2.0 - knob_height
        ],
        [
            0, door_width / 2 - door_width * knob_horizontal_location_ratio,
            door_height - knob_height + frame_width / 2
        ],
        [
            -(door_thickness + latch_gap),
            -door_width * knob_horizontal_location_ratio - frame_width / 2.0 -
            overlap_door_frame, (door_height + frame_width) / 2.0 - knob_height
        ],
        [
            -(door_thickness + latch_gap),
            door_width - door_width * knob_horizontal_location_ratio +
            frame_width / 2.0 + overlap_door_frame,
            (door_height + frame_width) / 2.0 - knob_height
        ],
        [
            -(door_thickness + latch_gap),
            door_width / 2 - door_width * knob_horizontal_location_ratio,
            door_height - knob_height + frame_width / 2
        ]
    ]

    size_list = [[
        door_thickness / 2.0, frame_width / 2.0,
        (door_height + frame_width) / 2.0
    ],
                 [
                     door_thickness / 2.0, frame_width / 2.0,
                     (door_height + frame_width) / 2.0
                 ],
                 [
                     door_thickness / 2.0, door_width / 2.0 + frame_width,
                     frame_width / 2.0
                 ],
                 [
                     door_thickness / 2.0, frame_width / 2.0,
                     (door_height + frame_width) / 2.0
                 ],
                 [
                     door_thickness / 2.0, frame_width / 2.0,
                     (door_height + frame_width) / 2.0
                 ],
                 [
                     door_thickness / 2.0, door_width / 2.0 + frame_width,
                     frame_width / 2.0
                 ]]
    for i in range(frame_parts_n):
        body1_geoms.append(
            e.Geom(name=name.format(i),
                   material='Metal',
                   pos=pos_list[i],
                   size=size_list[i],
                   type='box',
                   euler=frame_euler))

    body1_children_list = [body1_inertial]
    body1_children_list.extend(body1_geoms)
    body1.add_children(body1_children_list)
    body1.add_children([body2])

    ######## Level2 body (Door) ########
    body2_joints = e.Joint(name='hinge0',
                           type='hinge',
                           axis=[0, 0, 1],
                           armature=door_frame_armature,
                           stiffness=door_frame_spring,
                           damping=door_frame_damper,
                           frictionloss=door_frame_frictionloss,
                           limited=door_frame_limited,
                           range=door_frame_range,
                           pos=door_frame_joint_pos)

    body2_inertial = e.Inertial(pos=[
        0, door_width / 2.0 - door_width * knob_horizontal_location_ratio,
        door_height / 2.0 - knob_height
    ],
                                mass=door_mass,
                                diaginertia=door_diaginertia)
    door_material = material_name_list[randrange(0, 3)]
    body2_geoms = [
        e.Geom(name='door0',
               material=door_material,
               pos=[
                   0, door_width / 2.0 -
                   door_width * knob_horizontal_location_ratio,
                   door_height / 2.0 - knob_height
               ],
               size=[
                   door_thickness / 2.0, door_width / 2.0,
                   door_height / 2.0 * 0.99
               ],
               type="box",
               euler=door_euler)
    ]

    body2_children_list = [body2_joints]
    body2_children_list.extend(body2_geoms)
    body2_children_list.extend([body2_inertial])
    body2.add_children(body2_children_list)
    body2.add_children([body3])

    ######## Level3 body (Knob Wrapper) ########
    body3_joints = []

    if knob_type != "pull":
        body3_joints.append(
            e.Joint(name='hinge1',
                    type='hinge',
                    axis=[1, 0, 0],
                    armature=knob_door_armature,
                    stiffness=knob_door_spring,
                    damping=knob_door_damper,
                    frictionloss=knob_door_frictionloss,
                    limited=knob_door_limited,
                    range=knob_door_range,
                    pos=knob_door_joint_pos))

    axes = [[0, 1, 0], [0, 0, 1]]
    ranges = [[-0.2, 0.3], [-0.5, 0.5]]
    for i in range(2):
        body3_joints.append(
            e.Joint(name='target{}'.format(i),
                    type='slide',
                    axis=axes[i],
                    armature=0,
                    stiffness=0,
                    damping=30000,
                    frictionloss=0,
                    limited="true",
                    range=ranges[i]))

    body3_inertial = e.Inertial(pos=[0, 0, 0],
                                mass=1,
                                diaginertia=[0.001, 0.001, 0.001])

    body3.add_child(body3_inertial)
    body3.add_children(body3_joints)
    body3.add_children([body4])

    ######## Level4 body (Knob Link) ########
    body4_geoms = []
    name = 'door_knob_{}'
    mesh = 'door_knob_{}'
    doorknob_material = material_name_list[randrange(0, 3)]
    knobparts_start_idx = 1

    for i in range(knobparts_start_idx, knob_parts_n + 1):
        body4_geoms.append(
            e.Geom(name=name.format(i),
                   material=doorknob_material,
                   mesh=mesh.format(i),
                   euler=knob_euler,
                   friction=knob_surface_friction))

    if knob_type != "pull":
        body4_geoms.append(
            e.Geom(name='knob_latch',
                   material=material_name_list[randrange(0, 3)],
                   pos=[-(latch_gap / 2.0 + door_thickness * 1.5), 0, 0],
                   size=[latch_thickness / 2.0, latch_width, latch_height],
                   type="box",
                   euler=[0, 0, 0]))

    body4_inertial = e.Inertial(
        pos=[-(latch_gap / 2.0 + door_thickness * 2.1), 0, 0],
        mass=knob_mass,
        diaginertia=knob_diaginertia)

    body4_children_list = body4_geoms
    if knob_type != "pull":
        body4_children_list.extend([body4_inertial])
    body4.add_children(body4_children_list)

    ######## Write file to Output folder ########
    model_xml = mujoco.xml()
    name = '{0}_{1}_{2}.xml'
    if args.one_dir:
        output_path = args.output_dirname + '/world'
    else:
        output_path = os.path.join(
            args.output_dirname, '{0}_{1}'.format(knob_type, args.robot_type))
    try:
        os.makedirs(output_path)
    except OSError:
        pass
    output_filename = os.path.join(
        output_path, name.format(dataset_file, knob_type, args.robot_type))
    if knob_type == "lever" and knob_parts_n < 4:
        # print("parts are too less!!", dataset_file)
        pass
    else:
        with open(output_filename, 'w') as fh:
            fh.write(model_xml)
Beispiel #10
0
def main():

    mujoco = e.Mujoco(model="arm", )
    compiler = e.Compiler(
        angle="degree",
        coordinate="local",
        inertiafromgeom="true",
    )
    default = e.Default()
    option = e.Option(
        integrator="RK4",
        timestep="0.002",
    )
    visual = e.Visual()
    worldbody = e.Worldbody()
    tendon = e.Tendon()
    sensor = e.Sensor()
    actuator = e.Actuator()
    asset = e.Asset()
    mujoco.add_children([
        compiler,
        default,
        option,
        visual,
        worldbody,
        tendon,
        sensor,
        actuator,
        asset,
    ])

    # Standard assets
    utils.populated_ma_asset(asset)

    # Standard floor and lighting
    utils.populate_ma_worldbody(worldbody)

    geom = e.Geom(
        conaffinity="1",
        condim="1",
        contype="1",
        margin="0.001",
        material="geom",
        rgba="0.8 0.6 .4 1",
        solimp=".8 .8 .01",
        solref=".02 1",
    )
    motor = e.Motor(
        ctrllimited="true",
        ctrlrange="-.4 .4",
    )
    default.add_children([
        geom,
        motor,
    ])
    map = e.visual.Map(znear="0.02", )
    visual.add_children([
        map,
    ])
    # light = e.Light(
    #     cutoff="100",
    #     diffuse="1 1 1",
    #     dir="-0 0 -1.3",
    #     directional="true",
    #     exponent="1",
    #     pos="0 0 1.3",
    #     specular=".1 .1 .1",
    # )
    # floor = e.Geom(
    #     conaffinity="1",
    #     condim="3",
    #     material="MatPlane",
    #     name="floor",
    #     pos="0 0 0",
    #     rgba="0.8 0.9 0.8 1",
    #     size="20 20 .125",
    #     type="plane",
    # )
    block_body = e.Body(
        name="block_body",
        pos="0.0 0.0 3.0",
    )
    worldbody.add_children([
        # light,
        # floor,
        block_body,
    ])
    string = e.Spatial(
        name="string",
        width="0.02",
        rgba=".95 .3 .3 1",
        limited="false",
        range="0.5 2",
        stiffness="3700.0",
        damping="100.0",
    )
    tendon.add_children([
        string,
    ])
    ball_sensor = e.sensor.Force(
        name="ball_sensor",
        site="ball_site",
    )
    sensor.add_children([
        ball_sensor,
    ])
    string_actuator = e.General(
        name="string_actuator",
        tendon="string",
        ctrllimited="true",
        gainprm="2000",
        ctrlrange="-2 0",
    )
    actuator.add_children([
        string_actuator,
    ])
    # texture = e.Texture(
    #     builtin="gradient",
    #     height="100",
    #     rgb1=".4 .5 .6",
    #     rgb2="0 0 0",
    #     type="skybox",
    #     width="100",
    # )
    # texgeom = e.Texture(
    #     builtin="flat",
    #     height="1278",
    #     mark="cross",
    #     markrgb="1 1 1",
    #     name="texgeom",
    #     random="0.01",
    #     rgb1="0.8 0.6 0.4",
    #     rgb2="0.8 0.6 0.4",
    #     type="cube",
    #     width="127",
    # )
    # texplane = e.Texture(
    #     builtin="checker",
    #     height="100",
    #     name="texplane",
    #     rgb1="0 0 0",
    #     rgb2="0.8 0.8 0.8",
    #     type="2d",
    #     width="100",
    # )
    # MatPlane = e.Material(
    #     name="MatPlane",
    #     reflectance="0.5",
    #     shininess="1",
    #     specular="1",
    #     texrepeat="60 60",
    #     texture="texplane",
    # )
    # geom_1 = e.Material(
    #     name="geom",
    #     texture="texgeom",
    #     texuniform="true",
    # )
    # asset.add_children([
    #     texture,
    #     texgeom,
    #     texplane,
    #     MatPlane,
    #     geom_1,
    # ])
    block_geom = e.Geom(
        name="block_geom",
        size="0.2 0.2 0.2",
        type="box",
    )
    box_site = e.Site(
        name="box_site",
        pos="0.0 0.0 -0.2",
        size="0.05",
    )
    ball = e.Body(
        name="ball",
        pos="0.0 0.0 -1.0",
    )
    block_body.add_children([
        block_geom,
        box_site,
        ball,
    ])
    site = e.spatial.Site(site="box_site", )
    site_1 = e.spatial.Site(site="ball_site", )
    string.add_children([
        site,
        site_1,
    ])
    ball_joint = e.Joint(
        name="ball_joint",
        pos="0.0 0.0 -0.2",
        type="ball",
        damping="2.0",
    )
    joint = e.Joint(
        type="slide",
        axis="0 0 1",
        damping="2.0",
    )
    joint_1 = e.Joint(
        type="slide",
        axis="0 1 0",
        damping="2.0",
    )
    joint_2 = e.Joint(
        type="slide",
        axis="1 0 0",
        damping="2.0",
    )
    geom_2 = e.Geom(
        pos="0.0 0.0 0.0",
        size="0.2",
        type="sphere",
    )
    ball_site = e.Site(
        name="ball_site",
        pos="0.0 0.0 0.2",
        size="0.05",
    )
    ball.add_children([
        ball_joint,
        joint,
        joint_1,
        joint_2,
        geom_2,
        ball_site,
    ])

    model_xml = mujoco.xml()

    # Output
    out_path = os.path.join("..", "muscledagents", "envs", "mujoco", "assets",
                            "ballonstring.xml")
    with open(out_path, 'w') as fh:
        fh.write(model_xml)
Beispiel #11
0
def main():

    mujoco = e.Mujoco()
    compiler = e.Compiler(
        angle="degree",
        coordinate="local",
        inertiafromgeom="true",
    )
    option = e.Option(
        integrator="RK4",
        timestep="0.02",
    )
    default = e.Default()
    asset = e.Asset()
    worldbody = e.Worldbody()
    actuator = e.Actuator()
    mujoco.add_children([
        compiler,
        option,
        default,
        asset,
        worldbody,
        actuator,
    ])
    joint = e.Joint(
        armature="0",
        damping="0",
        limited="false",
    )
    geom = e.Geom(
        conaffinity="0",
        condim="3",
        density="100",
        friction="1 0.5 0.5",
        margin="0",
        rgba="0.8 0.6 0.4 1",
    )
    default.add_children([
        joint,
        geom,
    ])
    texture = e.Texture(
        builtin="gradient",
        height="100",
        rgb1="1 1 1",
        rgb2="0 0 0",
        type="skybox",
        width="100",
    )
    texgeom = e.Texture(
        builtin="flat",
        height="1278",
        mark="cross",
        markrgb="1 1 1",
        name="texgeom",
        random="0.01",
        rgb1="0.8 0.6 0.4",
        rgb2="0.8 0.6 0.4",
        type="cube",
        width="127",
    )
    texplane = e.Texture(
        builtin="checker",
        height="100",
        name="texplane",
        rgb1="0 0 0",
        rgb2="0.8 0.8 0.8",
        type="2d",
        width="100",
    )
    MatPlane = e.Material(
        name="MatPlane",
        reflectance="0.5",
        shininess="1",
        specular="1",
        texrepeat="30 30",
        texture="texplane",
    )
    geom_1 = e.Material(
        name="geom",
        texture="texgeom",
        texuniform="true",
    )
    asset.add_children([
        texture,
        texgeom,
        texplane,
        MatPlane,
        geom_1,
    ])
    light = e.Light(
        cutoff="100",
        diffuse="1 1 1",
        dir="-0 0 -1.3",
        directional="true",
        exponent="1",
        pos="0 0 1.3",
        specular=".1 .1 .1",
    )
    floor = e.Geom(
        conaffinity="1",
        condim="3",
        material="MatPlane",
        name="floor",
        pos="0 0 0",
        rgba="0.8 0.9 0.8 1",
        size="40 40 40",
        type="plane",
    )
    torso = e.Body(
        name="torso",
        pos="0 0 0",
    )
    worldbody.add_children([
        light,
        floor,
        torso,
    ])
    motor = e.Motor(
        ctrllimited="true",
        ctrlrange="-1 1",
        joint="ballx",
    )
    motor_1 = e.Motor(
        ctrllimited="true",
        ctrlrange="-0.25 0.25",
        joint="rot",
    )
    actuator.add_children([
        motor,
        motor_1,
    ])
    pointbody = e.Geom(
        name="pointbody",
        pos="0 0 0.5",
        size="0.5",
        type="sphere",
    )
    pointarrow = e.Geom(
        name="pointarrow",
        pos="0.6 0 0.5",
        size="0.5 0.1 0.1",
        type="box",
    )
    ballx = e.Joint(
        axis="1 0 0",
        name="ballx",
        pos="0 0 0",
        type="slide",
    )
    bally = e.Joint(
        axis="0 1 0",
        name="bally",
        pos="0 0 0",
        type="slide",
    )
    rot = e.Joint(
        axis="0 0 1",
        limited="false",
        name="rot",
        pos="0 0 0",
        type="hinge",
    )
    torso.add_children([
        pointbody,
        pointarrow,
        ballx,
        bally,
        rot,
    ])

    model_xml = mujoco.xml()

    # Output
    with open('point_gen.xml', 'w') as fh:
        fh.write(model_xml)
Beispiel #12
0
def main():

    mujoco = e.Mujoco(model="hopper", )
    compiler = e.Compiler(
        angle="degree",
        coordinate="global",
        inertiafromgeom="true",
    )
    default = e.Default()
    option = e.Option(
        integrator="RK4",
        timestep="0.002",
    )
    visual = e.Visual()
    worldbody = e.Worldbody()
    actuator = e.Actuator()
    asset = e.Asset()
    mujoco.add_children([
        compiler,
        default,
        option,
        visual,
        worldbody,
        actuator,
        asset,
    ])
    joint = e.Joint(
        armature="1",
        damping="1",
        limited="true",
    )
    geom = e.Geom(
        conaffinity="1",
        condim="1",
        contype="1",
        margin="0.001",
        material="geom",
        rgba="0.8 0.6 .4 1",
        solimp=".8 .8 .01",
        solref=".02 1",
    )
    motor = e.Motor(
        ctrllimited="true",
        ctrlrange="-.4 .4",
    )
    default.add_children([
        joint,
        geom,
        motor,
    ])
    map = e.Map(znear="0.02", )
    visual.add_children([
        map,
    ])
    light = e.Light(
        cutoff="100",
        diffuse="1 1 1",
        dir="-0 0 -1.3",
        directional="true",
        exponent="1",
        pos="0 0 1.3",
        specular=".1 .1 .1",
    )
    floor = e.Geom(
        conaffinity="1",
        condim="3",
        name="floor",
        pos="0 0 0",
        rgba="0.8 0.9 0.8 1",
        size="20 20 .125",
        type="plane",
        material="MatPlane",
    )
    torso = e.Body(
        name="torso",
        pos="0 0 1.25",
    )
    worldbody.add_children([
        light,
        floor,
        torso,
    ])
    motor_1 = e.Motor(
        ctrllimited="true",
        ctrlrange="-1.0 1.0",
        gear="200.0",
        joint="thigh_joint",
    )
    motor_2 = e.Motor(
        ctrllimited="true",
        ctrlrange="-1.0 1.0",
        gear="200.0",
        joint="leg_joint",
    )
    motor_3 = e.Motor(
        ctrllimited="true",
        ctrlrange="-1.0 1.0",
        gear="200.0",
        joint="foot_joint",
    )
    actuator.add_children([
        motor_1,
        motor_2,
        motor_3,
    ])
    texture = e.Texture(
        type="skybox",
        builtin="gradient",
        rgb1=".4 .5 .6",
        rgb2="0 0 0",
        width="100",
        height="100",
    )
    texgeom = e.Texture(
        builtin="flat",
        height="1278",
        mark="cross",
        markrgb="1 1 1",
        name="texgeom",
        random="0.01",
        rgb1="0.8 0.6 0.4",
        rgb2="0.8 0.6 0.4",
        type="cube",
        width="127",
    )
    texplane = e.Texture(
        builtin="checker",
        height="100",
        name="texplane",
        rgb1="0 0 0",
        rgb2="0.8 0.8 0.8",
        type="2d",
        width="100",
    )
    MatPlane = e.Material(
        name="MatPlane",
        reflectance="0.5",
        shininess="1",
        specular="1",
        texrepeat="60 60",
        texture="texplane",
    )
    geom_1 = e.Material(
        name="geom",
        texture="texgeom",
        texuniform="true",
    )
    asset.add_children([
        texture,
        texgeom,
        texplane,
        MatPlane,
        geom_1,
    ])
    track = e.Camera(
        name="track",
        mode="trackcom",
        pos="0 -3 1",
        xyaxes="1 0 0 0 0 1",
    )
    rootx = e.Joint(
        armature="0",
        axis="1 0 0",
        damping="0",
        limited="false",
        name="rootx",
        pos="0 0 0",
        stiffness="0",
        type="slide",
    )
    rootz = e.Joint(
        armature="0",
        axis="0 0 1",
        damping="0",
        limited="false",
        name="rootz",
        pos="0 0 0",
        ref="1.25",
        stiffness="0",
        type="slide",
    )
    rooty = e.Joint(
        armature="0",
        axis="0 1 0",
        damping="0",
        limited="false",
        name="rooty",
        pos="0 0 1.25",
        stiffness="0",
        type="hinge",
    )
    torso_geom = e.Geom(
        friction="0.9",
        fromto="0 0 1.45 0 0 1.05",
        name="torso_geom",
        size="0.05",
        type="capsule",
    )
    thigh = e.Body(
        name="thigh",
        pos="0 0 1.05",
    )
    torso.add_children([
        track,
        rootx,
        rootz,
        rooty,
        torso_geom,
        thigh,
    ])
    thigh_joint = e.Joint(
        axis="0 -1 0",
        name="thigh_joint",
        pos="0 0 1.05",
        range="-150 0",
        type="hinge",
    )
    thigh_geom = e.Geom(
        friction="0.9",
        fromto="0 0 1.05 0 0 0.6",
        name="thigh_geom",
        size="0.05",
        type="capsule",
    )
    leg = e.Body(
        name="leg",
        pos="0 0 0.35",
    )
    thigh.add_children([
        thigh_joint,
        thigh_geom,
        leg,
    ])
    leg_joint = e.Joint(
        axis="0 -1 0",
        name="leg_joint",
        pos="0 0 0.6",
        range="-150 0",
        type="hinge",
    )
    leg_geom = e.Geom(
        friction="0.9",
        fromto="0 0 0.6 0 0 0.1",
        name="leg_geom",
        size="0.04",
        type="capsule",
    )
    foot = e.Body(
        name="foot",
        pos="0.13/2 0 0.1",
    )
    leg.add_children([
        leg_joint,
        leg_geom,
        foot,
    ])
    foot_joint = e.Joint(
        axis="0 -1 0",
        name="foot_joint",
        pos="0 0 0.1",
        range="-45 45",
        type="hinge",
    )
    foot_geom = e.Geom(
        friction="2.0",
        fromto="-0.13 0 0.1 0.26 0 0.1",
        name="foot_geom",
        size="0.06",
        type="capsule",
    )
    foot.add_children([
        foot_joint,
        foot_geom,
    ])

    model_xml = mujoco.xml()

    # Output
    with open('hopper_gen.xml', 'w') as fh:
        fh.write(model_xml)
Beispiel #13
0
def main():

    mujoco = e.Mujoco(model="humanoid", )
    compiler = e.Compiler(
        angle="degree",
        inertiafromgeom="true",
    )
    default = e.Default()
    worldbody = e.Worldbody()
    mujoco.add_children([
        compiler,
        default,
        worldbody,
    ])
    joint = e.Joint(
        armature="1",
        damping="1",
        limited="true",
    )
    geom = e.Geom(
        conaffinity="1",
        condim="1",
        contype="1",
        margin="0.001",
        material="geom",
        rgba="0.8 0.6 .4 1",
    )
    motor = e.Motor(
        ctrllimited="true",
        ctrlrange="-.4 .4",
    )
    default.add_children([
        joint,
        geom,
        motor,
    ])
    light = e.Light(
        cutoff="100",
        diffuse="1 1 1",
        dir="-0 0 -1.3",
        directional="true",
        exponent="1",
        pos="0 0 1.3",
        specular=".1 .1 .1",
    )
    floor = e.Geom(
        condim="3",
        friction="1 .1 .1",
        material="MatPlane",
        name="floor",
        pos="0 0 0",
        rgba="0.8 0.9 0.8 1",
        size="20 20 0.125",
        type="plane",
    )
    worldbody.add_children([
        light,
        floor,
    ])

    model_xml = mujoco.xml()

    # Output
    with open('minimal_gen.xml', 'w') as fh:
        fh.write(model_xml)
Beispiel #14
0
def main():

    mujoco = e.Mujoco(model="arm3d", )
    compiler = e.Compiler(
        inertiafromgeom="true",
        angle="radian",
        coordinate="local",
    )
    option = e.Option(
        timestep="0.01",
        gravity="0 0 -9.81",
        iterations="20",
        integrator="Euler",
    )
    default = e.Default()
    worldbody = e.Worldbody()
    actuator = e.Actuator()
    mujoco.add_children([
        compiler,
        option,
        default,
        worldbody,
        actuator,
    ])
    joint = e.Joint(
        armature="0.75",
        damping="1",
        limited="true",
    )
    geom = e.Geom(
        friction=".8 .1 .1",
        density="300",
        margin="0.002",
        condim="1",
        contype="0",
        conaffinity="0",
    )
    default.add_children([
        joint,
        geom,
    ])
    light = e.Light(
        diffuse=".5 .5 .5",
        pos="0 0 3",
        dir="0 0 -1",
    )
    geom_1 = e.Geom(
        type="plane",
        pos="0 0.5 -0.325",
        size="1 1 0.1",
        contype="1",
        conaffinity="1",
    )
    r_shoulder_pan_link = e.Body(
        name="r_shoulder_pan_link",
        pos="0 -0.6 0",
    )
    goal = e.Body(
        name="goal",
        pos="0.575 0.5 -0.328",
    )
    ball = e.Body(
        name="ball",
        pos="0.5 -0.8 0.275",
    )
    worldbody.add_children([
        light,
        geom_1,
        r_shoulder_pan_link,
        goal,
        ball,
    ])
    motor = e.Motor(
        joint="r_shoulder_pan_joint",
        ctrlrange="-10.0 10.0",
        ctrllimited="true",
    )
    motor_1 = e.Motor(
        joint="r_shoulder_lift_joint",
        ctrlrange="-10.0 10.0",
        ctrllimited="true",
    )
    motor_2 = e.Motor(
        joint="r_upper_arm_roll_joint",
        ctrlrange="-10.0 10.0",
        ctrllimited="true",
    )
    motor_3 = e.Motor(
        joint="r_elbow_flex_joint",
        ctrlrange="-10.0 10.0",
        ctrllimited="true",
    )
    motor_4 = e.Motor(
        joint="r_forearm_roll_joint",
        ctrlrange="-15.0 15.0",
        ctrllimited="true",
    )
    motor_5 = e.Motor(
        joint="r_wrist_flex_joint",
        ctrlrange="-15.0 15.0",
        ctrllimited="true",
    )
    motor_6 = e.Motor(
        joint="r_wrist_roll_joint",
        ctrlrange="-15.0 15.0",
        ctrllimited="true",
    )
    actuator.add_children([
        motor,
        motor_1,
        motor_2,
        motor_3,
        motor_4,
        motor_5,
        motor_6,
    ])
    e1 = e.Geom(
        name="e1",
        type="sphere",
        rgba="0.6 0.6 0.6 1",
        pos="-0.06 0.05 0.2",
        size="0.05",
        density="0.0001",
    )
    e2 = e.Geom(
        name="e2",
        type="sphere",
        rgba="0.6 0.6 0.6 1",
        pos=" 0.06 0.05 0.2",
        size="0.05",
        density="0.0001",
    )
    e1p = e.Geom(
        name="e1p",
        type="sphere",
        rgba="0.1 0.1 0.1 1",
        pos="-0.06 0.09 0.2",
        size="0.03",
        density="0.0001",
    )
    e2p = e.Geom(
        name="e2p",
        type="sphere",
        rgba="0.1 0.1 0.1 1",
        pos=" 0.06 0.09 0.2",
        size="0.03",
        density="0.0001",
    )
    sp = e.Geom(
        name="sp",
        type="capsule",
        fromto="0 0 -0.4 0 0 0.2",
        size="0.1",
        density="1",
    )
    r_shoulder_pan_joint = e.Joint(
        name="r_shoulder_pan_joint",
        type="hinge",
        pos="0 0 0",
        axis="0 0 1",
        range="-0.4854 1.214602",
        damping="1.0",
    )
    r_shoulder_lift_link = e.Body(
        name="r_shoulder_lift_link",
        pos="0.1 0 0",
    )
    r_shoulder_pan_link.add_children([
        e1,
        e2,
        e1p,
        e2p,
        sp,
        r_shoulder_pan_joint,
        r_shoulder_lift_link,
    ])
    geom_2 = e.Geom(
        rgba="1 1 1 1",
        type="box",
        pos="0 0 0.005",
        size="0.075 0.075 0.001",
        contype="1",
        conaffinity="1",
        density="1000",
    )
    geom_3 = e.Geom(
        rgba="1 1 1 1",
        type="box",
        pos="0.0 0.075 0.034",
        size="0.075 0.001 0.03",
        contype="1",
        conaffinity="0",
    )
    geom_4 = e.Geom(
        rgba="1 1 1 1",
        type="box",
        pos="0.0 -0.075 0.034",
        size="0.075 0.001 0.03",
        contype="1",
        conaffinity="0",
    )
    geom_5 = e.Geom(
        rgba="1 1 1 1",
        type="box",
        pos="0.075 0 0.034",
        size="0.001 0.075 0.03",
        contype="1",
        conaffinity="0",
    )
    geom_6 = e.Geom(
        rgba="1 1 1 1",
        type="box",
        pos="-0.076 0 0.034",
        size="0.001 0.075 0.03",
        contype="1",
        conaffinity="0",
    )
    geom_7 = e.Geom(
        rgba="1 1 1 1",
        type="capsule",
        fromto="0.073 0.073 0.0075 0.073 0.073 0.06",
        size="0.005",
        contype="1",
        conaffinity="0",
    )
    geom_8 = e.Geom(
        rgba="1 1 1 1",
        type="capsule",
        fromto="0.073 -0.073 0.0075 0.073 -0.073 0.06",
        size="0.005",
        contype="1",
        conaffinity="0",
    )
    geom_9 = e.Geom(
        rgba="1 1 1 1",
        type="capsule",
        fromto="-0.073 0.073 0.0075 -0.073 0.073 0.06",
        size="0.005",
        contype="1",
        conaffinity="0",
    )
    geom_10 = e.Geom(
        rgba="1 1 1 1",
        type="capsule",
        fromto="-0.073 -0.073 0.0075 -0.073 -0.073 0.06",
        size="0.005",
        contype="1",
        conaffinity="0",
    )
    goal_slidey = e.Joint(
        name="goal_slidey",
        type="slide",
        pos="0 0 0",
        axis="0 1 0",
        range="-10.3213 10.3",
        damping="1.0",
    )
    goal_slidex = e.Joint(
        name="goal_slidex",
        type="slide",
        pos="0 0 0",
        axis="1 0 0",
        range="-10.3213 10.3",
        damping="1.0",
    )
    goal.add_children([
        geom_2,
        geom_3,
        geom_4,
        geom_5,
        geom_6,
        geom_7,
        geom_8,
        geom_9,
        geom_10,
        goal_slidey,
        goal_slidex,
    ])
    geom_11 = e.Geom(
        rgba="1. 1. 1. 1",
        type="sphere",
        size="0.03 0.03 0.1",
        density="25",
        contype="1",
        conaffinity="1",
    )
    ball_free = e.Joint(
        name="ball_free",
        type="free",
        armature="0",
        damping="0",
        limited="false",
    )
    ball.add_children([
        geom_11,
        ball_free,
    ])
    sl = e.Geom(
        name="sl",
        type="capsule",
        fromto="0 -0.1 0 0 0.1 0",
        size="0.1",
        density="0.0001",
    )
    r_shoulder_lift_joint = e.Joint(
        name="r_shoulder_lift_joint",
        type="hinge",
        pos="0 0 0",
        axis="0 1 0",
        range="-0.5236 0.7963",
        damping="1.0",
    )
    r_upper_arm_roll_link = e.Body(
        name="r_upper_arm_roll_link",
        pos="0 0 0",
    )
    r_shoulder_lift_link.add_children([
        sl,
        r_shoulder_lift_joint,
        r_upper_arm_roll_link,
    ])
    uar = e.Geom(
        name="uar",
        type="capsule",
        fromto="-0.1 0 0 0.1 0 0",
        size="0.02",
        density="0.0001",
    )
    r_upper_arm_roll_joint = e.Joint(
        name="r_upper_arm_roll_joint",
        type="hinge",
        pos="0 0 0",
        axis="1 0 0",
        range="-1.5 1.7",
        damping="1.0",
    )
    r_upper_arm_link = e.Body(
        name="r_upper_arm_link",
        pos="0 0 0",
    )
    r_upper_arm_roll_link.add_children([
        uar,
        r_upper_arm_roll_joint,
        r_upper_arm_link,
    ])
    ua = e.Geom(
        name="ua",
        type="capsule",
        fromto="0 0 0 0.4 0 0",
        size="0.06",
        density="0.0001",
    )
    r_elbow_flex_link = e.Body(
        name="r_elbow_flex_link",
        pos="0.4 0 0",
    )
    r_upper_arm_link.add_children([
        ua,
        r_elbow_flex_link,
    ])
    ef = e.Geom(
        name="ef",
        type="capsule",
        fromto="0 -0.02 0 0.0 0.02 0",
        size="0.06",
        density="0.0001",
    )
    r_elbow_flex_joint = e.Joint(
        name="r_elbow_flex_joint",
        type="hinge",
        pos="0 0 0",
        axis="0 1 0",
        range="-0.7 0.7",
        damping="1.0",
    )
    r_forearm_roll_link = e.Body(
        name="r_forearm_roll_link",
        pos="0 0 0",
    )
    r_elbow_flex_link.add_children([
        ef,
        r_elbow_flex_joint,
        r_forearm_roll_link,
    ])
    fr = e.Geom(
        name="fr",
        type="capsule",
        fromto="-0.1 0 0 0.1 0 0",
        size="0.02",
        density="0.0001",
    )
    r_forearm_roll_joint = e.Joint(
        name="r_forearm_roll_joint",
        type="hinge",
        limited="true",
        pos="0 0 0",
        axis="1 0 0",
        damping="1.0",
        range="-1.5 1.5",
    )
    r_forearm_link = e.Body(
        name="r_forearm_link",
        pos="0 0 0",
        axisangle="1 0 0 0.392",
    )
    r_forearm_roll_link.add_children([
        fr,
        r_forearm_roll_joint,
        r_forearm_link,
    ])
    fa = e.Geom(
        name="fa",
        type="capsule",
        fromto="0 0 0 0 0 0.291",
        size="0.05",
        density="0.0001",
    )
    r_wrist_flex_link = e.Body(
        name="r_wrist_flex_link",
        pos="0 0 0.321",
        axisangle="0 0 1 1.57",
    )
    r_forearm_link.add_children([
        fa,
        r_wrist_flex_link,
    ])
    wf = e.Geom(
        name="wf",
        type="capsule",
        fromto="0 -0.02 0 0 0.02 0",
        size="0.01",
        density="0.0001",
    )
    r_wrist_flex_joint = e.Joint(
        name="r_wrist_flex_joint",
        type="hinge",
        pos="0 0 0",
        axis="0 0 1",
        range="-1.0 1.0",
        damping="1.0",
    )
    r_wrist_roll_link = e.Body(
        name="r_wrist_roll_link",
        pos="0 0 0",
        axisangle="0 1 0 -1.178",
    )
    r_wrist_flex_link.add_children([
        wf,
        r_wrist_flex_joint,
        r_wrist_roll_link,
    ])
    r_wrist_roll_joint = e.Joint(
        name="r_wrist_roll_joint",
        type="hinge",
        pos="0 0 0",
        limited="true",
        axis="0 1 0",
        damping="1.0",
        range="0 2.25",
    )
    geom_12 = e.Geom(
        type="capsule",
        fromto="0 -0.05 0 0 0.05 0",
        size="0.01",
        contype="1",
        conaffinity="1",
        density="0.0001",
    )
    body = e.Body(
        pos="0 0 0",
        axisangle="0 0 1 0.392",
    )
    body_1 = e.Body(
        pos="0 0 0",
        axisangle="0 0 1 1.57",
    )
    body_2 = e.Body(
        pos="0 0 0",
        axisangle="0 0 1 1.178",
    )
    body_3 = e.Body(
        pos="0 0 0",
        axisangle="0 0 1 0.785",
    )
    body_4 = e.Body(
        pos="0 0 0",
        axisangle="0 0 1 1.96",
    )
    body_5 = e.Body(
        pos="0 0 0",
        axisangle="0 0 1 2.355",
    )
    body_6 = e.Body(
        pos="0 0 0",
        axisangle="0 0 1 2.74",
    )
    r_wrist_roll_link.add_children([
        r_wrist_roll_joint,
        geom_12,
        body,
        body_1,
        body_2,
        body_3,
        body_4,
        body_5,
        body_6,
    ])
    geom_13 = e.Geom(
        type="capsule",
        fromto="0 0.025 0 0 0.075 0.075",
        size="0.005",
        contype="1",
        conaffinity="1",
        density="0.0001",
    )
    geom_14 = e.Geom(
        type="capsule",
        fromto="0 0.075 0.075 0 0.075 0.15",
        size="0.005",
        contype="1",
        conaffinity="1",
        density=".0001",
    )
    geom_15 = e.Geom(
        type="capsule",
        fromto="0 0.075 0.15 0 0 0.225",
        size="0.005",
        contype="1",
        conaffinity="1",
        density="0.0001",
    )
    body.add_children([
        geom_13,
        geom_14,
        geom_15,
    ])
    geom_16 = e.Geom(
        type="capsule",
        fromto="0 0.025 0 0 0.075 0.075",
        size="0.005",
        contype="1",
        conaffinity="1",
        density="0.0001",
    )
    geom_17 = e.Geom(
        type="capsule",
        fromto="0 0.075 0.075 0 0.075 0.15",
        size="0.005",
        contype="1",
        conaffinity="1",
        density="0.0001",
    )
    geom_18 = e.Geom(
        type="capsule",
        fromto="0 0.075 0.15 0 0 0.225",
        size="0.005",
        contype="1",
        conaffinity="1",
        density="0.0001",
    )
    body_1.add_children([
        geom_16,
        geom_17,
        geom_18,
    ])
    geom_19 = e.Geom(
        type="capsule",
        fromto="0 0.025 0 0 0.075 0.075",
        size="0.005",
        contype="1",
        conaffinity="1",
        density="0.0001",
    )
    geom_20 = e.Geom(
        type="capsule",
        fromto="0 0.075 0.075 0 0.075 0.15",
        size="0.005",
        contype="1",
        conaffinity="1",
        density="0.0001",
    )
    geom_21 = e.Geom(
        type="capsule",
        fromto="0 0.075 0.15 0 0 0.225",
        size="0.005",
        contype="1",
        conaffinity="1",
        density="0.0001",
    )
    body_2.add_children([
        geom_19,
        geom_20,
        geom_21,
    ])
    geom_22 = e.Geom(
        type="capsule",
        fromto="0 0.025 0 0 0.075 0.075",
        size="0.005",
        contype="1",
        conaffinity="1",
        density="0.0001",
    )
    geom_23 = e.Geom(
        type="capsule",
        fromto="0 0.075 0.075 0 0.075 0.15",
        size="0.005",
        contype="1",
        conaffinity="1",
        density="0.0001",
    )
    geom_24 = e.Geom(
        type="capsule",
        fromto="0 0.075 0.15 0 0 0.225",
        size="0.005",
        contype="1",
        conaffinity="1",
        density="0.0001",
    )
    body_3.add_children([
        geom_22,
        geom_23,
        geom_24,
    ])
    geom_25 = e.Geom(
        type="capsule",
        fromto="0 0.025 0 0 0.075 0.075",
        size="0.005",
        contype="1",
        conaffinity="1",
        density="0.0001",
    )
    geom_26 = e.Geom(
        type="capsule",
        fromto="0 0.075 0.075 0 0.075 0.15",
        size="0.005",
        contype="1",
        conaffinity="1",
        density="0.0001",
    )
    geom_27 = e.Geom(
        type="capsule",
        fromto="0 0.075 0.15 0 0 0.225",
        size="0.005",
        contype="1",
        conaffinity="1",
        density="0.0001",
    )
    body_4.add_children([
        geom_25,
        geom_26,
        geom_27,
    ])
    geom_28 = e.Geom(
        type="capsule",
        fromto="0 0.025 0 0 0.075 0.075",
        size="0.005",
        contype="1",
        conaffinity="1",
        density="0.0001",
    )
    geom_29 = e.Geom(
        type="capsule",
        fromto="0 0.075 0.075 0 0.075 0.15",
        size="0.005",
        contype="1",
        conaffinity="1",
        density="0.0001",
    )
    geom_30 = e.Geom(
        type="capsule",
        fromto="0 0.075 0.15 0 0 0.225",
        size="0.005",
        contype="1",
        conaffinity="1",
        density="0.0001",
    )
    body_5.add_children([
        geom_28,
        geom_29,
        geom_30,
    ])
    geom_31 = e.Geom(
        type="capsule",
        fromto="0 0.025 0 0 0.075 0.075",
        size="0.005",
        contype="1",
        conaffinity="1",
        density="0.0001",
    )
    geom_32 = e.Geom(
        type="capsule",
        fromto="0 0.075 0.075 0 0.075 0.15",
        size="0.005",
        contype="1",
        conaffinity="1",
        density="0.0001",
    )
    geom_33 = e.Geom(
        type="capsule",
        fromto="0 0.075 0.15 0 0 0.225",
        size="0.005",
        contype="1",
        conaffinity="1",
        density="0.0001",
    )
    body_6.add_children([
        geom_31,
        geom_32,
        geom_33,
    ])

    model_xml = mujoco.xml()

    # Output
    with open('thrower_gen.xml', 'w') as fh:
        fh.write(model_xml)
Beispiel #15
0
def main():

    mujoco = e.Mujoco(
        model="ant",
    )
    compiler = e.Compiler(
        angle="degree",
        coordinate="local",
        inertiafromgeom="true",
    )
    option = e.Option(
        integrator="RK4",
        timestep="0.01",
    )
    custom = e.Custom(
    )
    default = e.Default(
    )
    asset = e.Asset(
    )
    worldbody = e.Worldbody(
    )
    actuator = e.Actuator(
    )
    mujoco.add_children([
        compiler,
        option,
        custom,
        default,
        asset,
        worldbody,
        actuator,
    ])
    init_qpos = e.Numeric(
        data="0.0 0.0 0.55 1.0 0.0 0.0 0.0 0.0 1.0 0.0 -1.0 0.0 -1.0 0.0 1.0",
        name="init_qpos",
    )
    custom.add_children([
        init_qpos,
    ])
    joint = e.Joint(
        armature="1",
        damping="1",
        limited="true",
    )
    geom = e.Geom(
        conaffinity="0",
        condim="3",
        density="5.0",
        friction="1 0.5 0.5",
        margin="0.01",
        rgba="0.8 0.6 0.4 1",
    )
    default.add_children([
        joint,
        geom,
    ])
    texture = e.Texture(
        builtin="gradient",
        height="100",
        rgb1="1 1 1",
        rgb2="0 0 0",
        type="skybox",
        width="100",
    )
    texgeom = e.Texture(
        builtin="flat",
        height="1278",
        mark="cross",
        markrgb="1 1 1",
        name="texgeom",
        random="0.01",
        rgb1="0.8 0.6 0.4",
        rgb2="0.8 0.6 0.4",
        type="cube",
        width="127",
    )
    texplane = e.Texture(
        builtin="checker",
        height="100",
        name="texplane",
        rgb1="0 0 0",
        rgb2="0.8 0.8 0.8",
        type="2d",
        width="100",
    )
    MatPlane = e.Material(
        name="MatPlane",
        reflectance="0.5",
        shininess="1",
        specular="1",
        texrepeat="60 60",
        texture="texplane",
    )
    geom_1 = e.Material(
        name="geom",
        texture="texgeom",
        texuniform="true",
    )
    asset.add_children([
        texture,
        texgeom,
        texplane,
        MatPlane,
        geom_1,
    ])
    light = e.Light(
        cutoff="100",
        diffuse="1 1 1",
        dir="-0 0 -1.3",
        directional="true",
        exponent="1",
        pos="0 0 1.3",
        specular=".1 .1 .1",
    )
    floor = e.Geom(
        conaffinity="1",
        condim="3",
        material="MatPlane",
        name="floor",
        pos="0 0 0",
        rgba="0.8 0.9 0.8 1",
        size="40 40 40",
        type="plane",
    )
    torso = e.Body(
        name="torso",
        pos="0 0 0.75",
    )
    worldbody.add_children([
        light,
        floor,
        torso,
    ])
    motor = e.Motor(
        ctrllimited="true",
        ctrlrange="-1.0 1.0",
        joint="hip_4",
        gear="150",
    )
    motor_1 = e.Motor(
        ctrllimited="true",
        ctrlrange="-1.0 1.0",
        joint="ankle_4",
        gear="150",
    )
    motor_2 = e.Motor(
        ctrllimited="true",
        ctrlrange="-1.0 1.0",
        joint="hip_1",
        gear="150",
    )
    motor_3 = e.Motor(
        ctrllimited="true",
        ctrlrange="-1.0 1.0",
        joint="ankle_1",
        gear="150",
    )
    motor_4 = e.Motor(
        ctrllimited="true",
        ctrlrange="-1.0 1.0",
        joint="hip_2",
        gear="150",
    )
    motor_5 = e.Motor(
        ctrllimited="true",
        ctrlrange="-1.0 1.0",
        joint="ankle_2",
        gear="150",
    )
    motor_6 = e.Motor(
        ctrllimited="true",
        ctrlrange="-1.0 1.0",
        joint="hip_3",
        gear="150",
    )
    motor_7 = e.Motor(
        ctrllimited="true",
        ctrlrange="-1.0 1.0",
        joint="ankle_3",
        gear="150",
    )
    actuator.add_children([
        motor,
        motor_1,
        motor_2,
        motor_3,
        motor_4,
        motor_5,
        motor_6,
        motor_7,
    ])
    track = e.Camera(
        name="track",
        mode="trackcom",
        pos="0 -3 0.3",
        xyaxes="1 0 0 0 0 1",
    )
    torso_geom = e.Geom(
        name="torso_geom",
        pos="0 0 0",
        size="0.25",
        type="sphere",
    )
    root = e.Joint(
        armature="0",
        damping="0",
        limited="false",
        margin="0.01",
        name="root",
        pos="0 0 0",
        type="free",
    )
    front_left_leg = e.Body(
        name="front_left_leg",
        pos="0 0 0",
    )
    front_right_leg = e.Body(
        name="front_right_leg",
        pos="0 0 0",
    )
    back_leg = e.Body(
        name="back_leg",
        pos="0 0 0",
    )
    right_back_leg = e.Body(
        name="right_back_leg",
        pos="0 0 0",
    )
    torso.add_children([
        track,
        torso_geom,
        root,
        front_left_leg,
        front_right_leg,
        back_leg,
        right_back_leg,
    ])
    aux_1_geom = e.Geom(
        fromto="0.0 0.0 0.0 0.2 0.2 0.0",
        name="aux_1_geom",
        size="0.08",
        type="capsule",
    )
    aux_1 = e.Body(
        name="aux_1",
        pos="0.2 0.2 0",
    )
    front_left_leg.add_children([
        aux_1_geom,
        aux_1,
    ])
    aux_2_geom = e.Geom(
        fromto="0.0 0.0 0.0 -0.2 0.2 0.0",
        name="aux_2_geom",
        size="0.08",
        type="capsule",
    )
    aux_2 = e.Body(
        name="aux_2",
        pos="-0.2 0.2 0",
    )
    front_right_leg.add_children([
        aux_2_geom,
        aux_2,
    ])
    aux_3_geom = e.Geom(
        fromto="0.0 0.0 0.0 -0.2 -0.2 0.0",
        name="aux_3_geom",
        size="0.08",
        type="capsule",
    )
    aux_3 = e.Body(
        name="aux_3",
        pos="-0.2 -0.2 0",
    )
    back_leg.add_children([
        aux_3_geom,
        aux_3,
    ])
    aux_4_geom = e.Geom(
        fromto="0.0 0.0 0.0 0.2 -0.2 0.0",
        name="aux_4_geom",
        size="0.08",
        type="capsule",
    )
    aux_4 = e.Body(
        name="aux_4",
        pos="0.2 -0.2 0",
    )
    right_back_leg.add_children([
        aux_4_geom,
        aux_4,
    ])
    hip_1 = e.Joint(
        axis="0 0 1",
        name="hip_1",
        pos="0.0 0.0 0.0",
        range="-30 30",
        type="hinge",
    )
    left_leg_geom = e.Geom(
        fromto="0.0 0.0 0.0 0.2 0.2 0.0",
        name="left_leg_geom",
        size="0.08",
        type="capsule",
    )
    body = e.Body(
        pos="0.2 0.2 0",
    )
    aux_1.add_children([
        hip_1,
        left_leg_geom,
        body,
    ])
    hip_2 = e.Joint(
        axis="0 0 1",
        name="hip_2",
        pos="0.0 0.0 0.0",
        range="-30 30",
        type="hinge",
    )
    right_leg_geom = e.Geom(
        fromto="0.0 0.0 0.0 -0.2 0.2 0.0",
        name="right_leg_geom",
        size="0.08",
        type="capsule",
    )
    body_1 = e.Body(
        pos="-0.2 0.2 0",
    )
    aux_2.add_children([
        hip_2,
        right_leg_geom,
        body_1,
    ])
    hip_3 = e.Joint(
        axis="0 0 1",
        name="hip_3",
        pos="0.0 0.0 0.0",
        range="-30 30",
        type="hinge",
    )
    back_leg_geom = e.Geom(
        fromto="0.0 0.0 0.0 -0.2 -0.2 0.0",
        name="back_leg_geom",
        size="0.08",
        type="capsule",
    )
    body_2 = e.Body(
        pos="-0.2 -0.2 0",
    )
    aux_3.add_children([
        hip_3,
        back_leg_geom,
        body_2,
    ])
    hip_4 = e.Joint(
        axis="0 0 1",
        name="hip_4",
        pos="0.0 0.0 0.0",
        range="-30 30",
        type="hinge",
    )
    rightback_leg_geom = e.Geom(
        fromto="0.0 0.0 0.0 0.2 -0.2 0.0",
        name="rightback_leg_geom",
        size="0.08",
        type="capsule",
    )
    body_3 = e.Body(
        pos="0.2 -0.2 0",
    )
    aux_4.add_children([
        hip_4,
        rightback_leg_geom,
        body_3,
    ])
    ankle_1 = e.Joint(
        axis="-1 1 0",
        name="ankle_1",
        pos="0.0 0.0 0.0",
        range="30 70",
        type="hinge",
    )
    left_ankle_geom = e.Geom(
        fromto="0.0 0.0 0.0 0.4 0.4 0.0",
        name="left_ankle_geom",
        size="0.08",
        type="capsule",
    )
    body.add_children([
        ankle_1,
        left_ankle_geom,
    ])
    ankle_2 = e.Joint(
        axis="1 1 0",
        name="ankle_2",
        pos="0.0 0.0 0.0",
        range="-70 -30",
        type="hinge",
    )
    right_ankle_geom = e.Geom(
        fromto="0.0 0.0 0.0 -0.4 0.4 0.0",
        name="right_ankle_geom",
        size="0.08",
        type="capsule",
    )
    body_1.add_children([
        ankle_2,
        right_ankle_geom,
    ])
    ankle_3 = e.Joint(
        axis="-1 1 0",
        name="ankle_3",
        pos="0.0 0.0 0.0",
        range="-70 -30",
        type="hinge",
    )
    third_ankle_geom = e.Geom(
        fromto="0.0 0.0 0.0 -0.4 -0.4 0.0",
        name="third_ankle_geom",
        size="0.08",
        type="capsule",
    )
    body_2.add_children([
        ankle_3,
        third_ankle_geom,
    ])
    ankle_4 = e.Joint(
        axis="1 1 0",
        name="ankle_4",
        pos="0.0 0.0 0.0",
        range="30 70",
        type="hinge",
    )
    fourth_ankle_geom = e.Geom(
        fromto="0.0 0.0 0.0 0.4 -0.4 0.0",
        name="fourth_ankle_geom",
        size="0.08",
        type="capsule",
    )
    body_3.add_children([
        ankle_4,
        fourth_ankle_geom,
    ])

    model_xml = mujoco.xml()

    # Output
    with open('ant_gen.xml', 'w') as fh:
        fh.write(model_xml)