コード例 #1
0
def main():
    mujoco = e.Mujoco(model="empty-world")

    compiler = e.Compiler(angle="degree",
                          coordinate="local",
                          inertiafromgeom=True)
    option = e.Option(integrator="RK4", timestep=0.01)
    size = e.Size(
        njmax=1000,
        nconmax=500,
    )
    default = e.Default()
    asset = e.Asset()
    worldbody = e.Worldbody()

    mujoco.add_children([
        compiler,
        option,
        size,
        default,
        asset,
        worldbody,
    ])

    # Default
    d_joint = e.Joint(armature=1, damping=1, limited=True)
    d_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([d_joint, d_geom])

    # Standard assets
    utils.populated_ma_asset(asset)

    # Standard floor and lighting
    utils.populate_ma_worldbody(worldbody)

    model_xml = mujoco.xml()
    filename = "empty-world.xml"
    utils.save_model(model_xml, filename)
コード例 #2
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)
コード例 #3
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)
コード例 #4
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)
コード例 #5
0
ファイル: gen_inverted_pendulum.py プロジェクト: tarod13/mjcf
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)
コード例 #6
0
def base_setup():
    #########################
    # Level 1
    mujoco = e.Mujoco(model="empty")

    #########################
    # Level 2
    option = e.Option(integrator="RK4", timestep=0.01)
    asset = e.Asset()
    worldbody = e.Worldbody()

    size = e.Size(
        njmax=4000,
        nconmax=4000,
    )

    mujoco.add_children([option, size, asset, worldbody])

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

    # Asset
    tex1 = e.Texture(
        builtin="gradient",
        height=100,
        rgb1=[0.9, 0.9, 1.0],  # Bipedal Walker Sky Purple
        rgb2=[0.9, 0.9, 1.0],
        type="skybox",
        width=100)
    tex2 = 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)
    tex3 = e.Texture(builtin="checker",
                     height=[100],
                     name="texplane",
                     rgb1=[0, 0, 0],
                     rgb2=[0.8, 0.8, 0.8],
                     type="2d",
                     width=100)
    mat1 = e.Material(name="MatPlane",
                      reflectance=0.5,
                      shininess=1,
                      specular=1,
                      texrepeat=[60, 60],
                      texture="texplane")
    mat2 = e.Material(name="geom", texture="texgeom", texuniform=True)
    asset.add_children([
        tex1,
        tex2,
        tex3,
        mat1,
        mat2,
    ])

    # Worldbody
    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_geom = 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")

    worldbody.add_children([
        light,
        floor_geom,
    ])

    return mujoco, worldbody
コード例 #7
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
    )
    size = e.Size(
        njmax=1000,
        nconmax=500,
    )
    custom = e.Custom()
    default = e.Default()
    asset = e.Asset()
    worldbody = e.Worldbody()
    tendon = e.Tendon()
    actuator = e.Actuator()

    mujoco.add_children([
        compiler,
        option,
        size,
        custom,
        default,
        asset,
        worldbody,
        tendon,
        actuator
    ])

    # Custom
    numeric = e.Numeric(
        name="init_qpos",
        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",
    )
    custom.add_child(numeric)

    # Default
    d_joint = e.Joint(
        armature=1,
        damping=1,
        limited=True
    )
    d_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([d_joint, d_geom])

    # Standard assets
    utils.populated_ma_asset(asset)

    # Standard floor and lighting
    utils.populate_ma_worldbody(worldbody)

    # Add axes. Useful for debugging
    # utils.add_axes(worldbody)

    ant_bodies = []
    ant_tendons = []
    ant_actuators = []
    body, tendons, actuators = get_ant(name="")
    ant_bodies.append(body)
    ant_tendons.extend(tendons)
    ant_actuators.extend(actuators)

    worldbody.add_children(ant_bodies)

    # Tendon
    tendon.add_children(ant_tendons)

    # Actuator
    actuator.add_children(ant_actuators)

    model_xml = mujoco.xml()
    filename = "muscled-ant.xml"
    utils.save_model(model_xml, filename)
コード例 #8
0
ファイル: gen_ants.py プロジェクト: iandanforth/muscledagents
def main():
    #########################
    # Level 1
    mujoco = e.Mujoco(model="ant-army")

    #########################
    # Level 2
    compiler = e.Compiler(angle="degree",
                          coordinate="local",
                          inertiafromgeom=True)
    option = e.Option(integrator="RK4", timestep=0.01)
    size = e.Size(
        njmax=1000,
        nconmax=500,
    )
    custom = e.Custom()
    default = e.Default()
    asset = e.Asset()
    worldbody = e.Worldbody()
    tendon = e.Tendon()
    actuator = e.Actuator()

    mujoco.add_children([
        compiler, option, size, custom, default, asset, worldbody, tendon,
        actuator
    ])

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

    # Custom
    numeric = e.Numeric(
        name="init_qpos",
        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",
    )
    custom.add_child(numeric)

    # Default
    d_joint = e.Joint(armature=1, damping=1, limited=True)
    d_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([d_joint, d_geom])

    # Asset
    tex1 = e.Texture(builtin="gradient",
                     height=100,
                     rgb1=[1, 1, 1],
                     rgb2=[0, 0, 0],
                     type="skybox",
                     width=100)
    tex2 = 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)
    tex3 = e.Texture(builtin="checker",
                     height=[100],
                     name="texplane",
                     rgb1=[0, 0, 0],
                     rgb2=[0.8, 0.8, 0.8],
                     type="2d",
                     width=100)
    mat1 = e.Material(name="MatPlane",
                      reflectance=0.5,
                      shininess=1,
                      specular=1,
                      texrepeat=[60, 60],
                      texture="texplane")
    mat2 = e.Material(name="geom", texture="texgeom", texuniform=True)
    asset.add_children([
        tex1,
        tex2,
        tex3,
        mat1,
        mat2,
    ])

    # Worldbody
    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_geom = 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")

    worldbody.add_children([light, floor_geom])

    ant_bodies = []
    ant_tendons = []
    ant_actuators = []
    square_side = 3
    for i in range(square_side):
        for j in range(square_side):
            name = "ant_{}_{}".format(i, j)
            y_offset = 2.5 * i
            x_offset = 2.5 * j
            body, tendons, actuators = get_ant(
                name=name, location=[x_offset, y_offset, 0.75])
            ant_bodies.append(body)
            ant_tendons.extend(tendons)
            ant_actuators.extend(actuators)

    worldbody.add_children(ant_bodies)

    # Tendon
    tendon.add_children(ant_tendons)

    # Actuator
    actuator.add_children(ant_actuators)

    model_xml = mujoco.xml()

    # Output
    out_path = os.path.join("..", "muscledagents", "envs", "mujoco", "assets",
                            "muscled-ants.xml")
    with open(out_path, 'w') as fh:
        fh.write(model_xml)