<?xml version="1.0" encoding="utf-8"?>
<mujoco model="qube">

    <!-- Basic options -->
    <compiler angle="radian" meshdir="../meshes/"/>
    <option timestep="0.004" />
    <size njmax="500" nconmax="100" />
    <visual>
        <quality shadowsize="4096" />
    </visual>

    <!-- Materials & Assets -->
    <asset>
        <!-- Assets -->
        <include file="shared_assets.xml"/>

        <!-- Textures -->
        <texture type="2d" name="texbody" builtin="flat" rgb1="0 0 0" width="1024" height="1024" />
        <texture type="2d" name="texfloor" builtin="flat" rgb1="1 1 1" width="1024" height="1024" />
        <texture type="2d" name="texwall" builtin="flat" rgb1="1 1 1" width="1024" height="1024" />
        <texture type="2d" name="texred" builtin="flat" rgb1="0.721569 0.25098 0.235294" width="1024" height="1024" />
        <texture type="2d" name="texsilver" builtin="flat" rgb1="0.7529 0.7529 0.7529" width="512" height="512" />

        <!-- Materials -->
        <material name="floorMat" texture="texfloor" specular="1.0" shininess="0.1" />
        <material name="wallMat" texture="texwall" specular="1.0" shininess="0.1" />
        <material name="bodyMat" texture="texbody" specular="0.75" shininess="0.3" />
        <material name="redMat" texture="texred" specular="1.0" shininess="0.9" reflectance="1.0"/>
        <material name="silverMat" texture="texsilver" specular="0.75" shininess="0.6" reflectance="1.0"/>
    </asset>

    <worldbody>
        <!-- Top & side lights -->
        <light name="light_top" pos="0 -0.03 0.5" diffuse=".8 .8 .8" dir="0 0 -1" directional="false" specular="0.9 0.9 0.9" castshadow="false"/>
        <light name="light_right" pos="0.5 -0.03 0.5" diffuse=".6 .6 .6" dir="-1 0 -1" directional="false" specular="0.9 0.9 0.9" castshadow="false"/>
        <light name="light_left" pos="-0.5 -0.03 0.5" diffuse=".6 .6 .6" dir="1 0 -1" directional="false" specular="0.9 0.9 0.9" castshadow="false"/>
        
        <!-- Camera -->
        <camera name="blackfly" pos="0. -0.415 0.275" euler="1.167377293 0 0" fovy="35" />
        <!-- Main light -->
        <light name="light_main" pos="0 -0.465 0.38" diffuse=".8 .8 .8" dir="0 1 -0.65" directional="false" specular="0.9 0.9 0.9" castshadow="true" exponent="100"/>

        <!-- Walls -->
        <geom name="ground" pos="0 0 0" size="0.5 0.5 1" type="plane" material="floorMat"/>
        <geom name="wall_back" pos="0 0.16 0.165" euler="1.570796327 0 0" size="0.3 0.165 0.01" type="box" material="floorMat"/>
        <geom name="wall_left" pos="-0.3 -0.09 0.165" euler="0 1.570796327 0" size="0.165 0.25 0.01" type="box" material="floorMat"/>
        <geom name="wall_right" pos="0.3 -0.09 0.165" euler="0 -1.570796327 0" size="0.165 0.25 0.01" type="box" material="floorMat"/>
        <geom name="platform" pos="0 0 0.005" euler="0 0 0" size="0.05 0.05 0.005" type="box" material="floorMat"/>
        
        <!-- Qube -->
        <body name="base" pos="0 0 0.005" quat="0 0 0 1">
            <inertial pos="0.000323 -0.00132 0.054992" mass="1.0" fullinertia="0.16666666667 0.16666666667 0.16666666667 0.000000000 0.000000000 0.000000000" />
            <geom name="qube0:base" pos="0.000323 -0.00132 0.054992" type="mesh" contype="0" conaffinity="0" condim="1" friction="0 0 0" material="bodyMat" mesh="qube0:base" />
            <geom name="qube0:base:screw:01" pos="0.009938 0.009932 0.10653" type="mesh" contype="0" conaffinity="0" condim="1" friction="0 0 0" material="silverMat" mesh="qube0:base:screw:01" />
            <geom name="qube0:base:screw:02" pos="0.009938 -0.009927 0.10653" type="mesh" contype="0" conaffinity="0" condim="1" friction="0 0 0" material="silverMat" mesh="qube0:base:screw:02" />
            <geom name="qube0:base:screw:03" pos="-0.009938 0.009932 0.10653" type="mesh" contype="0" conaffinity="0" condim="1" friction="0 0 0" material="silverMat" mesh="qube0:base:screw:03" />
            <geom name="qube0:base:screw:04" pos="-0.009938 -0.009931 0.10653" type="mesh" contype="0" conaffinity="0" condim="1" friction="0 0 0" material="silverMat" mesh="qube0:base:screw:04" />
            <geom name="qube0:base:aux:female" pos="0 -0.026394 0.1078" type="mesh" contype="0" conaffinity="0" condim="1" friction="0 0 0" material="silverMat" mesh="qube0:base:aux:female" />

            <!-- Cable -->
            <body name="cable" pos="0 -0.002359 0.1667">
                <!-- <geom name="qube:cable" type="mesh" contype="0" conaffinity="0" condim="1" friction="0 0 0" material="bodyMat" mesh="qube0:cable" /> -->
                <geom name="qube:cable:aux:male" pos="0 -0.023859 -0.0447" type="mesh" contype="0" conaffinity="0" condim="1" friction="0 0 0" material="bodyMat" mesh="qube0:cable:aux:male" />
            </body>

            <!-- Motor -->
            <body name="motor" pos="0 0 0.12672">
                <inertial pos="0 0.008561 0.00125" mass="0.088" fullinertia="0.00001955483012 0.00000622772374 0.00001955483012 0.000000000 0.000000000 0.000000000" />
                <geom name="qube:motor:main" pos="0 -0.000486 0.00135" type="mesh" contype="0" conaffinity="0" condim="1" friction="0 0 0" material="redMat" mesh="qube0:motor:main" />
                <geom name="qube:motor:drive" pos="0.000009 -0.000053 -0.01472" type="mesh" contype="0" conaffinity="0" condim="1" friction="0 0 0" material="silverMat" mesh="qube0:motor:drive" />
                <geom name="qube:motor:front" pos="0.000031 0.025329 0.00124" type="mesh" contype="0" conaffinity="0" condim="1" friction="0 0 0" material="bodyMat" mesh="qube0:motor:front" />
                <geom name="qube:motor:part" pos="0 0.015289 -0.01559" type="mesh" contype="0" conaffinity="0" condim="1" friction="0 0 0" material="silverMat" mesh="qube0:motor:part" />

                <joint axis="0 0 1" name="base_motor" range="-90 90" type="hinge" damping="0.0004975"/>

                <!-- Rotary Arm -->
                <body name="arm" pos="0 0.054882 0">
                    <inertial pos="0 0 0" mass="0.0069000000000000025" fullinertia="0.000002500 0.000000030 0.000002500 0.000000000 0.000000000 0.000000000" />
                    <geom name="qube:arm" pos="0 0 0" type="mesh" contype="0" conaffinity="0" condim="1" friction="0 0 0" material="silverMat" mesh="qube0:arm" />

                    <joint axis="0 1 0" name="arm_pole" range="-90 90" type="hinge" damping="9.985e-05"/>

                    <!-- Pole -->
                    <body name="pole" pos="0 0.030562 0">
                        <inertial pos="-0.000022 0 0.05851" mass="0.024" fullinertia="0.000031118 0.000031122 0.000000273 0.000000000 0.000000000 0.000000000" />
                        <geom name="qube:pole" pos="-0.000022 0 0.05851" type="mesh" contype="0" conaffinity="0" condim="1" friction="0 0 0" material="redMat" mesh="qube0:pole" />
                    </body> 
                </body> 

            </body>            
        </body>
    </worldbody>

    <actuator>
        <general joint="base_motor" name="motor_rotation" ctrllimited="true" ctrlrange="-18 18" gainprm="1.4 0 0 0 0 0 0 0 0 0"/>
    </actuator>
</mujoco>
