<?xml version="1.0" ?>
<sdf version='1.10'>
  <world name='pong-world'>
    <physics name='1ms' type='ignored'>
      <max_step_size>0.001</max_step_size>
      <real_time_factor>1</real_time_factor>
      <real_time_update_rate>1000</real_time_update_rate>
    </physics>
    <plugin name='gz::sim::systems::Physics' filename='gz-sim-physics-system'/>
    <plugin name='gz::sim::systems::UserCommands' filename='gz-sim-user-commands-system'/>
    <plugin name='gz::sim::systems::SceneBroadcaster' filename='gz-sim-scene-broadcaster-system'/>
    <plugin name='gz::sim::systems::Contact' filename='gz-sim-contact-system'/>

    
    <gravity>0 0 -9.8</gravity>
    <magnetic_field>6e-06 2.3e-05 -4.2e-05</magnetic_field>
    <atmosphere type='adiabatic'/>
    <scene>
      <ambient>0.4 0.4 0.4 1</ambient>
      <background>0.7 0.7 0.7 1</background>
      <shadows>true</shadows>
    </scene>
    <model name='ground_plane'>
      <static>true</static>
      <link name='link'>
        <collision name='collision'>
          <geometry>
            <plane>
              <normal>0 0 1</normal>
              <size>100 100</size>
            </plane>
          </geometry>
          <surface>
            <friction>
              <ode/>
            </friction>
            <bounce/>
            <contact/>
          </surface>
        </collision>
        <visual name='visual'>
          <geometry>
            <plane>
              <normal>0 0 1</normal>
              <size>100 100</size>
            </plane>
          </geometry>
          <material>
            <ambient>0.8 0.8 0.8 1</ambient>
            <diffuse>0.8 0.8 0.8 1</diffuse>
            <specular>0.8 0.8 0.8 1</specular>
          </material>
        </visual>
        <pose>0 0 0 0 -0 0</pose>
        <inertial>
          <pose>0 0 0 0 -0 0</pose>
          <mass>1</mass>
          <inertia>
            <ixx>1</ixx>
            <ixy>0</ixy>
            <ixz>0</ixz>
            <iyy>1</iyy>
            <iyz>0</iyz>
            <izz>1</izz>
          </inertia>
        </inertial>
        <enable_wind>false</enable_wind>
      </link>
      <pose>0 0 0 0 -0 0</pose>
      <self_collide>false</self_collide>
    </model>   
      
      <model name='pong-bot' canonical_link='chassis'>
        <pose relative_to='world'>0 0 0 0 0 0</pose>
        <link name='chassis'>
          <pose relative_to='__model__'>0.5 0 0.4 0 0 0</pose>
          <inertial> <!--inertial properties of the link mass, inertia matix-->
            <mass>1.14395</mass>
              <inertia>
                <ixx>0.095329</ixx>
                <ixy>0</ixy>
                <ixz>0</ixz>
                <iyy>0.381317</iyy>
                <iyz>0</iyz>
                <izz>0.476646</izz>
              </inertia>
            </inertial>
            <visual name='visual'>
              <geometry>
                <box>
                  <size>2.0 1.0 0.5</size>
                </box>
              </geometry>
              <!--let's add color to our link-->
              <material>
                <ambient>0.35 0.5 0.9 1</ambient>
                <diffuse>0.35 0.5 0.9 1</diffuse>
                <specular>1.0 1.0 0.9 1</specular>
              </material>
            </visual>
            <collision name='collision'>
              <geometry>
                <box>
                    <size>2.0 1.0 0.5</size>
                </box>
              </geometry>
            </collision>
        </link>
        
        <link name='left_wheel'>
          <pose relative_to="chassis">-0.5 0.6 0 -1.5707 0 0</pose>
          <inertial>
            <mass>1</mass>
            <inertia>
              <ixx>0.043333</ixx>
              <ixy>0</ixy>
              <ixz>0</ixz>
              <iyy>0.043333</iyy>
              <iyz>0</iyz>
              <izz>0.08</izz>
            </inertia>
          </inertial>
          <visual name='visual'>
            <geometry>
              <cylinder>
                <radius>0.4</radius>
                <length>0.2</length>
              </cylinder>
            </geometry>
            <material>
              <ambient>0.0 0.0 0.0 1</ambient>
              <diffuse>0.0 0.0 0.0 1</diffuse>
              <specular>0.0 0.0 0.0 1</specular>
            </material>
          </visual>
          <collision name='collision'>
            <geometry>
              <cylinder>
                <radius>0.4</radius>
                <length>0.2</length>
              </cylinder>
            </geometry>
          </collision>
        </link>
        
        <link name='right_wheel'>
          <pose relative_to="chassis">-0.5 -0.6 0 -1.5707 0 0</pose>
          <inertial>
            <mass>1</mass>
            <inertia>
              <ixx>0.043333</ixx>
              <ixy>0</ixy>
              <ixz>0</ixz>
              <iyy>0.043333</iyy>
              <iyz>0</iyz>
              <izz>0.08</izz>
            </inertia>
          </inertial>
          <visual name='visual'>
            <geometry>
              <cylinder>
                <radius>0.4</radius>
                <length>0.2</length>
              </cylinder>
            </geometry>
            <material>
              <ambient>0.0 0.0 0.0 1</ambient>
              <diffuse>0.0 0.0 0.0 1</diffuse>
              <specular>0.0 0.0 0.0 1</specular>
            </material>
          </visual>
          <collision name='collision'>
            <geometry>
              <cylinder>
                <radius>0.4</radius>
                <length>0.2</length>
              </cylinder>
            </geometry>
          </collision>
        </link>
        
        <frame name="caster_frame" attached_to='chassis'>
          <pose>0.8 0 -0.2 0 0 0</pose>
        </frame>
        
        <!--caster wheel-->
        <link name='caster'>
          <pose relative_to='caster_frame'/>
          <inertial>
            <mass>1</mass>
              <inertia>
                <ixx>0.016</ixx>
                <ixy>0</ixy>
                <ixz>0</ixz>
                <iyy>0.016</iyy>
                <iyz>0</iyz>
                <izz>0.016</izz>
              </inertia>
            </inertial>
            <visual name='visual'>
              <geometry>
                <sphere>
                  <radius>0.2</radius>
                </sphere>
              </geometry>
              <material>
                <ambient>0.9 1 0.9 1</ambient>
                <diffuse>0.9 1 0.9 1</diffuse>
                <specular>0.9 1 0.9 1</specular>
              </material>
            </visual>
            <collision name='collision'>
              <geometry>
                <sphere>
                  <radius>0.2</radius>
                </sphere>
              </geometry>
            </collision>
          </link>
          
          <joint name='left_wheel_joint' type='revolute'>
            <pose relative_to='left_wheel'/>  
            <parent>chassis</parent>
            <child>left_wheel</child>
            <axis>
              <xyz expressed_in='__model__'>0 1 0</xyz> 
              <!--can be defined as any frame or even arbitrary frames-->
              <limit>
                  <lower>-1.79769e+308</lower>    <!--negative infinity-->
                  <upper>1.79769e+308</upper>     <!--positive infinity-->
              </limit>
            </axis>
         </joint>
           
          <joint name='right_wheel_joint' type='revolute'>
            <pose relative_to='right_wheel'/>  
            <parent>chassis</parent>
            <child>right_wheel</child>
            <axis>
              <xyz expressed_in='__model__'>0 1 0</xyz> 
              <!--can be defined as any frame or even arbitrary frames-->
              <limit>
                  <lower>-1.79769e+308</lower>    <!--negative infinity-->
                  <upper>1.79769e+308</upper>     <!--positive infinity-->
              </limit>
            </axis>
         </joint>        
            
         <joint name='caster_wheel' type='ball'>
           <parent>chassis</parent>
           <child>caster</child>
         </joint>
         
         <plugin
           filename="gz-sim-diff-drive-system"
           name="gz::sim::systems::DiffDrive">
           <left_joint>left_wheel_joint</left_joint>
           <right_joint>right_wheel_joint</right_joint>
           <wheel_separation>1.2</wheel_separation>
           <wheel_radius>0.4</wheel_radius>
           <odom_publish_frequency>1</odom_publish_frequency>
           <topic>cmd_vel</topic>
         </plugin>
         
             
         <!-- Moving Forward-->
             <plugin filename="gz-sim-triggered-publisher-system"
                  name="gz::sim::systems::TriggeredPublisher">
                <input type="gz.msgs.Int32" topic="/keyboard/keypress">
                   <match field="data">16777235</match>
                </input>
                <output type="gz.msgs.Twist" topic="/cmd_vel">
                     linear: {x: 0.5}, angular: {z: 0.0}
                </output>
             </plugin>
      </model>
      
      
      
    <light name='sun' type='directional'>
      <pose>0 0 10 0 -0 0</pose>
      <cast_shadows>true</cast_shadows>
      <intensity>1</intensity>
      <direction>-0.5 0.1 -0.9</direction>
      <diffuse>0.8 0.8 0.8 1</diffuse>
      <specular>0.2 0.2 0.2 1</specular>
      <attenuation>
        <range>1000</range>
        <linear>0.01</linear>
        <constant>0.90000000000000002</constant>
        <quadratic>0.001</quadratic>
      </attenuation>
      <spot>
        <inner_angle>0</inner_angle>
        <outer_angle>0</outer_angle>
        <falloff>0</falloff>
      </spot>
    </light>
  </world>
</sdf>
