<mujoco model="phonebot">
	<!-- enumeration of constant model parameters -->
	<!--
	phone z-offset from center : -0.00706
	phone size : 2X<0.075, 0.038175, 0.010806>
	leg (x,y)-offset : <0.041418, 0.0425>
	leg z-offset : -0.010148
	leg joint 1 x-offset : 0.0110
	leg link 1 length : 0.0175
	leg joint 2 x-offset : 0.0175
	leg link 2 length : 0.0285 (0.0110 + 0.0175)
	default capsule/sphere width : 0.004
	default margin : 0.001

	phone density : 557.55 (mass: 0.138kg / volume : refer to phone size above)
	3D print[PLA] density : 250.0 (1.25 g/cm^3 X (100cm/m)^3 X (kg/1000g) X 20%)
	Actuated Joint Range : 0.0 ~ 1.5707 (90')
	Motor Torque : 0.235 (~2.4kgf.cm X 9.8m/s^2 X m/100cm)
	-->

	<!-- everything at 1x scale -->
	<compiler angle="radian" coordinate="local" inertiafromgeom="true"/>
	<option integrator="RK4" timestep="0.001618" gravity="0 0 -9.81" iterations='100000'/>

	<visual>
		<map znear="0.01"/>
	</visual>

	<default>
		<!-- armature = rotor inertia ; damping = F(damp) = c_d.v -->
		<joint armature="0.01" damping="0.01" limited="true"/>
		<geom conaffinity="0" condim="3" density="250.0" friction="1 0.5 0.5" margin="0.001" rgba="0.3 0.6 0.8 1.0"/>
	</default>

	<asset>
		<texture builtin="gradient" height="100" rgb1="1 1 1" rgb2="0 0 0" type="skybox" width="100"/>
		<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"/>
		<texture builtin="checker" height="100" name="texplane" rgb1="0 0 0" rgb2="0.8 0.8 0.8" type="2d" width="100"/>
		<material name="MatPlane" reflectance="0.5" shininess="1" specular="1" texrepeat="60 60" texture="texplane"/>
		<material name="geom" texture="texgeom" texuniform="true"/>
	</asset>

	<worldbody>
		<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"/>
		<geom conaffinity="1" condim="3" material="MatPlane" name="floor" pos="0 0 0" rgba="0.8 0.9 0.8 1" size="10 10 10" type="plane"/>
		

		<body name="phone" pos="0 0 .1">
			<!-- root (dummy?) -->

			<!-- UNCOMMENT TO ADD GRAVITY -->
			<joint armature="0" damping="0" limited="false" margin="0.001" name="root" pos="0 0 0" type="free"/>


			<!-- main phone -->
			<geom name="phone_geom" pos="0 0 -0.00706" size="0.075 0.038175 0.010806" type="box" density="557.55" rgba="0.3 0.6 0.8 0.5"/>

			<!-- stoppers -->
			<geom name="fl_stop" pos="0.041418 0.0425 -0.010148" size="0.004" type="sphere"/>
			<geom name="fr_stop" pos="0.041418 -0.0425 -0.010148" size="0.004" type="sphere"/>
			<geom name="bl_stop" pos="-0.041418 0.0425 -0.010148" size="0.004" type="sphere"/>
			<geom name="br_stop" pos="-0.041418 -0.0425 -0.010148" size="0.004" type="sphere"/>

			<!-- legs -->
			<body name="fl_leg" pos="0.041418 0.0425 -0.010148">
				<body pos="-0.0110 0 0">
					<joint axis="0 -1 0" name="fl_ma" pos="0.0 0.0 0.0" range="-1.5707 1.5707" type="hinge"/>
					<geom fromto="0.0 0.0 0.0 -0.0175 0.0 0.0" name="fl_1a_geom" size="0.004" type="capsule"/>
					<body name="fl_sa" pos="-0.0175 0.0 0">
						<joint axis="0 -1 0" name="fl_ja" pos="0.0 0.0 0.0" limited="false" type="hinge"/>
						<geom fromto="0.0 0.0 0.0 0.0285 0.0 0.0" name="fl_2a_geom" size="0.004" type="capsule"/>
					</body>
				</body>
				<body pos="0.0110 0 0">
					<joint axis="0 1 0" name="fl_mb" pos="0.0 0.0 0.0" range="-1.5707 1.5707" type="hinge"/>
					<geom fromto="0.0 0.0 0.0 0.0175 0.0 0.0" name="fl_1b_geom" size="0.004" type="capsule"/>
					<body name="fl_sb" pos="0.0175 0.0 0">
						<joint axis="0 1 0" name="fl_jb" pos="0.0 0.0 0.0" limited="false" type="hinge"/>
						<geom fromto="0.0 0.0 0.0 -0.0285 0.0 0.0" name="fl_2b_geom" size="0.004" type="capsule"/>
					</body>
				</body>
			</body>

			<body name="fr_leg" pos="0.041418 -0.0425 -0.010148">
				<body pos="-0.0110 0 0">
					<joint axis="0 -1 0" name="fr_ma" pos="0.0 0.0 0.0" range="-1.5707 1.5707" type="hinge"/>
					<geom fromto="0.0 0.0 0.0 -0.0175 0.0 0.0" name="fr_1a_geom" size="0.004" type="capsule"/>
					<body name="fr_sa" pos="-0.0175 0.0 0">
						<joint axis="0 -1 0" name="fr_ja" pos="0.0 0.0 0.0" limited="false" type="hinge"/>
						<geom fromto="0.0 0.0 0.0 0.0285 0.0 0.0" name="fr_2a_geom" size="0.004" type="capsule"/>
					</body>
				</body>
				<body pos="0.0110 0 0">
					<joint axis="0 1 0" name="fr_mb" pos="0.0 0.0 0.0" range="-1.5707 1.5707" type="hinge"/>
					<geom fromto="0.0 0.0 0.0 0.0175 0.0 0.0" name="fr_1b_geom" size="0.004" type="capsule"/>
					<body name="fr_sb" pos="0.0175 0.0 0">
						<joint axis="0 1 0" name="fr_jb" pos="0.0 0.0 0.0" limited="false" type="hinge"/>
						<geom fromto="0.0 0.0 0.0 -0.0285 0.0 0.0" name="fr_2b_geom" size="0.004" type="capsule"/>
					</body>
				</body>
			</body>

			<body name="bl_leg" pos="-0.041418 0.0425 -0.010148">
				<body pos="-0.0110 0 0">
					<joint axis="0 -1 0" name="bl_ma" pos="0.0 0.0 0.0" range="-1.5707 1.5707" type="hinge"/>
					<geom fromto="0.0 0.0 0.0 -0.0175 0.0 0.0" name="bl_1a_geom" size="0.004" type="capsule"/>
					<body name="bl_sa" pos="-0.0175 0.0 0">
						<joint axis="0 -1 0" name="bl_ja" pos="0.0 0.0 0.0" limited="false" type="hinge"/>
						<geom fromto="0.0 0.0 0.0 0.0285 0.0 0.0" name="bl_2a_geom" size="0.004" type="capsule"/>
					</body>
				</body>
				<body pos="0.0110 0 0">
					<joint axis="0 1 0" name="bl_mb" pos="0.0 0.0 0.0" range="-1.5707 1.5707" type="hinge"/>
					<geom fromto="0.0 0.0 0.0 0.0175 0.0 0.0" name="bl_1b_geom" size="0.004" type="capsule"/>
					<body name="bl_sb" pos="0.0175 0.0 0">
						<joint axis="0 1 0" name="bl_jb" pos="0.0 0.0 0.0" limited="false" type="hinge"/>
						<geom fromto="0.0 0.0 0.0 -0.0285 0.0 0.0" name="bl_2b_geom" size="0.004" type="capsule"/>
					</body>
				</body>
			</body>

			<body name="br_leg" pos="-0.041418 -0.0425 -0.010148">
				<body pos="-0.0110 0 0">
					<joint axis="0 -1 0" name="br_ma" pos="0.0 0.0 0.0" range="-1.5707 1.5707" type="hinge"/>
					<geom fromto="0.0 0.0 0.0 -0.0175 0.0 0.0" name="br_1a_geom" size="0.004" type="capsule"/>
					<body name="br_sa" pos="-0.0175 0.0 0">
						<joint axis="0 -1 0" name="br_ja" pos="0.0 0.0 0.0" limited="false" type="hinge"/>
						<geom fromto="0.0 0.0 0.0 0.0285 0.0 0.0" name="br_2a_geom" size="0.004" type="capsule"/>
					</body>
				</body>
				<body pos="0.0110 0 0">
					<joint axis="0 1 0" name="br_mb" pos="0.0 0.0 0.0" range="-1.5707 1.5707" type="hinge"/>
					<geom fromto="0.0 0.0 0.0 0.0175 0.0 0.0" name="br_1b_geom" size="0.004" type="capsule"/>
					<body name="br_sb" pos="0.0175 0.0 0">
						<joint axis="0 1 0" name="br_jb" pos="0.0 0.0 0.0" limited="false" type="hinge"/>
						<geom fromto="0.0 0.0 0.0 -0.0285 0.0 0.0" name="br_2b_geom" size="0.004" type="capsule"/>
					</body>
				</body>
			</body>
		</body>
	</worldbody>

	<!-- define closed loop kinematic chain -->
    <equality>
    	<!-- <weld name="body_ep" body1="phone" active="true" solimp="0.9 0.95 0.001" solref="0.001 1" /> -->
		<connect name="fl_ep" body1="fl_sa" body2="fl_sb" anchor="0.0285 0 0" active="true" solimp="0.9 0.95 0.001" solref="0.001 1"/>
		<connect name="fr_ep" body1="fr_sa" body2="fr_sb" anchor="0.0285 0 0" active="true" solimp="0.9 0.95 0.001" solref="0.001 1"/>
		<connect name="bl_ep" body1="bl_sa" body2="bl_sb" anchor="0.0285 0 0" active="true" solimp="0.9 0.95 0.001" solref="0.001 1"/>
		<connect name="br_ep" body1="br_sa" body2="br_sb" anchor="0.0285 0 0" active="true" solimp="0.9 0.95 0.001" solref="0.001 1"/>
    </equality>

	<!-- define contacts -->
	<contact>
		<pair geom1="fl_stop" geom2="fl_2a_geom" margin="0.001"/>
		<pair geom1="fl_stop" geom2="fl_2b_geom" margin="0.001"/>
		<pair geom1="fr_stop" geom2="fr_2a_geom" margin="0.001"/>
		<pair geom1="fr_stop" geom2="fr_2b_geom" margin="0.001"/>
		<pair geom1="bl_stop" geom2="bl_2a_geom" margin="0.001"/>
		<pair geom1="bl_stop" geom2="bl_2b_geom" margin="0.001"/>
		<pair geom1="br_stop" geom2="br_2a_geom" margin="0.001"/>
		<pair geom1="br_stop" geom2="br_2b_geom" margin="0.001"/>
	</contact>
	<actuator>
		<motor ctrllimited="true" ctrlrange="-1.0 1.0" joint="fl_ma" gear="0.235"/> <!-- 2.4 kgf.cm == 0.235 N.m -->
		<motor ctrllimited="true" ctrlrange="-1.0 1.0" joint="fl_mb" gear="0.235"/>
		<motor ctrllimited="true" ctrlrange="-1.0 1.0" joint="fr_ma" gear="0.235"/>
		<motor ctrllimited="true" ctrlrange="-1.0 1.0" joint="fr_mb" gear="0.235"/>
		<motor ctrllimited="true" ctrlrange="-1.0 1.0" joint="bl_ma" gear="0.235"/>
		<motor ctrllimited="true" ctrlrange="-1.0 1.0" joint="bl_mb" gear="0.235"/>
		<motor ctrllimited="true" ctrlrange="-1.0 1.0" joint="br_ma" gear="0.235"/>
		<motor ctrllimited="true" ctrlrange="-1.0 1.0" joint="br_mb" gear="0.235"/>

		<!--
		<position ctrllimited="false" ctrlrange="-1.57 0" joint="fl_ma"/>
		<position ctrllimited="false" ctrlrange="-1.57 0" joint="fl_mb"/>
		<position ctrllimited="false" ctrlrange="-1.57 0" joint="fr_ma"/>
		<position ctrllimited="false" ctrlrange="-1.57 0" joint="fr_mb"/>
		<position ctrllimited="false" ctrlrange="-1.57 0" joint="bl_ma"/>
		<position ctrllimited="false" ctrlrange="-1.57 0" joint="bl_mb"/>
		<position ctrllimited="false" ctrlrange="-1.57 0" joint="br_ma"/>
		<position ctrllimited="false" ctrlrange="-1.57 0" joint="br_mb"/>
		-->
	</actuator>
</mujoco>
