<?xml version="1.0"?>
<hcdf version="1.0" name="test-minimal">

  <!-- Comp 1: board with switch, sensors, motor, surface, antenna, port -->
  <comp name="test-board" role="actuator">
    <description>Test component exercising all major child elements</description>

    <inertial>
      <mass>0.5</mass>
      <inertia_origin xyz="0 0 0.005"/>
      <inertia>1.2e-5 0 0 1.1e-5 0 2.0e-5</inertia>
    </inertial>

    <visual name="board">
      <pose xyz="0 0 0" rpy="0 0 0"/>
      <model uri="models/test-board.glb" sha="abc123def456"/>
    </visual>

    <collision name="board_col">
      <pose xyz="0 0 -0.005" rpy="0 0 0"/>
      <geometry>
        <box><size>0.048 0.044 0.012</size></box>
      </geometry>
      <surface>
        <friction static="0.6" dynamic="0.4"/>
        <restitution>0.2</restitution>
      </surface>
    </collision>

    <frame name="sensor_origin" relative-to="test-board">
      <description>Sensor reference frame</description>
      <pose xyz="0 0 0.01" rpy="0 0 0"/>
    </frame>

    <port name="eth0"><capabilities><purpose value="communication"/><carrier value="electrical"/><rate min="100000000" max="10000000000" nominal="100000000" unit="bit/s"/></capabilities></port>
    <port name="eth1"><capabilities><purpose value="communication"/><carrier value="electrical"/><rate min="1000000000" max="1000000000" nominal="1000000000" unit="bit/s"/></capabilities></port>
    <port name="can0"><capabilities><purpose value="communication"/><carrier value="electrical"/><profile id="hcdf:can"/><rate min="5000000" max="5000000" nominal="5000000" unit="bit/s"/></capabilities></port>
    <port name="sig_motor"><capabilities><purpose value="communication"/><carrier value="electrical"/></capabilities></port>
    <port name="phase_motor"><capabilities><purpose value="power-delivery"/><carrier value="electrical"/></capabilities></port>
    <port name="pwr_in"><capabilities><purpose value="power-delivery"/><carrier value="electrical"/><voltage min="20" max="29.2" nominal="24" unit="V"/><current min="0" max="6" nominal="3" unit="A"/><power min="0" max="144" nominal="72" unit="W"/></capabilities></port>
    <port name="gnss0"><capabilities><purpose value="communication"/><carrier value="radiated-rf"/><frequency min="1575420000" max="1575420000" nominal="1575420000" unit="Hz"/></capabilities></port>
    <connector name="eth0_connector" family="molex:micro-lock-plus-2.0-4c"/>
    <connector name="sig_motor_connector" family="molex:12-pin"/>
    <connector name="phase_motor_connector" family="hcdf:three-phase-power"/>
    <antenna name="gnss0"><radiated-port component="test-board" port="gnss0"/></antenna>
    <switch name="test-switch"><bidirectional><port-ref component="test-board" port="eth0"/></bidirectional><bidirectional><port-ref component="test-board" port="eth1"/></bidirectional></switch>

    <sensor name="imu0" update-rate="1000">
      <inertial type="accel_gyro">
        <pose xyz="0.016 -0.001 -0.008" rpy="0 0 0"/>
        <driver name="icm45686">
          <axis-align x="Y" y="-X" z="Z"/>
        </driver>
        <accel>
          <range unit="g">16</range>
          <resolution unit="mg">0.488</resolution>
          <noise type="gaussian">
            <mean>0</mean>
            <stddev>0.003</stddev>
            <bias-mean>0.01</bias-mean>
          </noise>
        </accel>
        <gyro>
          <range unit="dps">2000</range>
          <noise type="gaussian">
            <stddev>0.01</stddev>
          </noise>
        </gyro>
      </inertial>
    </sensor>

    <sensor name="tof0">
      <optical type="tof">
        <pose xyz="-0.008 0 0.003" rpy="0 0 0"/>
        <driver name="afbr_s50"/>
        <fov name="collector" color="#4488ff">
          <pose xyz="0 0 0" rpy="0 0.0471 0"/>
          <geometry>
            <frustum shape="pyramidal">
              <near>0.05</near>
              <far>50.0</far>
              <hfov>0.2164</hfov>
              <vfov>0.0942</vfov>
            </frustum>
          </geometry>
        </fov>
        <fov name="emitter" color="#ff4444">
          <pose xyz="-0.005 0 0" rpy="0 0 0"/>
          <geometry>
            <frustum shape="conical">
              <near>0.001</near>
              <far>50.0</far>
              <fov>0.035</fov>
            </frustum>
          </geometry>
        </fov>
      </optical>
    </sensor>

    <sensor name="motor_encoder">
      <encoder type="incremental" principle="magnetic">
        <resolution unit="counts">4096</resolution>
      </encoder>
    </sensor>

    <sensor name="motor_hall">
      <em type="mag">
        <range unit="mT">100</range>
      </em>
    </sensor>

    <sensor name="motor_temp">
      <temperature type="thermistor">
        <range unit="degC">150</range>
      </temperature>
    </sensor>

    <motor name="foc_motor" type="bldc" encoder="motor_encoder" hall="motor_hall" thermistor="motor_temp">
      <voltage unit="V" nominal="24" max="28"/>
      <current unit="A" continuous="6.5" peak="19"/>
      <resistance unit="ohm">0.5</resistance>
      <torque-constant unit="Nm/A">0.29</torque-constant>
      <velocity-constant unit="V/RPM">0.109</velocity-constant>
      <max-speed unit="rpm">260</max-speed>
      <stall-torque unit="Nm">19.76</stall-torque>
      <no-load-speed unit="rpm">257.9</no-load-speed>
      <no-load-current unit="A">0.974</no-load-current>
      <max-power-out unit="W">158.8</max-power-out>
      <max-efficiency unit="percent">68.4</max-efficiency>
      <control-modes>
        <mode>velocity</mode>
        <mode>position</mode>
        <mode>torque</mode>
      </control-modes>
    </motor>

    <dynamic-surface name="wheel">
      <wheel type="driven">
        <radius unit="m">0.085</radius>
        <width unit="m">0.041</width>
        <friction static="0.9" dynamic="0.7"/>
      </wheel>
    </dynamic-surface>

    <software name="firmware">
      <version>1.0.0</version>
      <hash>abc123def456</hash>
    </software>
  </comp>

  <!-- Comp 2: minimal parent for joint target -->
  <comp name="parent-body" role="parent">
    <inertial>
      <mass>5.0</mass>
      <inertia_origin xyz="0 0 0"/>
    </inertial>
    <collision name="parent_col">
      <geometry><cylinder><radius>0.05</radius><length>0.2</length></cylinder></geometry>
    </collision>
    <collision name="parent_cap">
      <geometry><capsule><radius>0.03</radius><length>0.1</length></capsule></geometry>
    </collision>
    <collision name="parent_sphere">
      <geometry><sphere><radius>0.04</radius></sphere></geometry>
    </collision>
    <collision name="parent_ellipsoid">
      <geometry><ellipsoid><radii>0.05 0.03 0.02</radii></ellipsoid></geometry>
    </collision>
    <collision name="parent_cone">
      <geometry><cone><radius>0.03</radius><length>0.08</length></cone></geometry>
    </collision>
    <port name="eth0"><capabilities><purpose value="communication"/><carrier value="electrical"/><rate min="100000000" max="10000000000" nominal="100000000" unit="bit/s"/></capabilities></port>
    <port name="can0"><capabilities><purpose value="communication"/><carrier value="electrical"/><profile id="hcdf:can"/><rate min="5000000" max="5000000" nominal="5000000" unit="bit/s"/></capabilities></port>
  </comp>

  <!-- Joints -->
  <joint name="shoulder_yaw" type="revolute">
    <parent comp="parent-body"/>
    <child comp="test-board"/>
    <origin xyz="0 0.15 0.3" rpy="0 0 0"/>
    <axis xyz="0 0 1"/>
    <limit lower="-3.14" upper="3.14" effort="50" velocity="3.14"/>
    <dynamics damping="0.5" friction="0.1" spring_stiffness="0" spring_reference="0"/>
  </joint>

  <joint name="fixed_mount" type="fixed">
    <parent comp="parent-body"/>
    <child comp="test-board"/>
  </joint>

  <!-- Group -->
  <group name="test_chain" type="kinematic-chain">
    <description>Test kinematic chain</description>
    <joint ref="shoulder_yaw"/>
  </group>

  <!-- State -->
  <state name="home" default="true">
    <description>Home position</description>
    <joint-position joint="shoulder_yaw" value="0"/>
  </state>

  <!-- Self-collision disable -->
  <self-collision-disable>
    <pair comp1="parent-body" comp2="test-board" reason="adjacent"/>
  </self-collision-disable>

  <!-- Physical presentation of the authored connector-bearing ports. -->
  <binding name="test_board_eth0_presented" fidelity="presented"><functional><port-ref component="test-board" port="eth0"/></functional><physical><connector-ref connector="eth0_connector"><component-ref component="test-board"/></connector-ref></physical></binding>
  <binding name="test_board_motor_signal_presented" fidelity="presented"><functional><port-ref component="test-board" port="sig_motor"/></functional><physical><connector-ref connector="sig_motor_connector"><component-ref component="test-board"/></connector-ref></physical></binding>
  <binding name="test_board_motor_phase_presented" fidelity="presented"><functional><port-ref component="test-board" port="phase_motor"/></functional><physical><connector-ref connector="phase_motor_connector"><component-ref component="test-board"/></connector-ref></physical></binding>

  <!-- Connectivity: point-to-point link, CAN bus, and switched chain with link-owned configuration. -->
  <link name="test_link">
    <description>Point-to-point electrical communication link between the parent and test board.</description>
    <selected purpose="communication" carrier="electrical"><rate><nominal value="100000000" unit="bit/s"/></rate></selected>
    <participant name="parent-body"><endpoint><port-ref component="parent-body" port="eth0"/></endpoint></participant>
    <participant name="test-board"><endpoint><port-ref component="test-board" port="eth0"/></endpoint></participant>
  </link>

  <bus name="test_can">
    <description>CAN communication bus between the parent controller and test board target.</description>
    <selected purpose="communication" carrier="electrical"><profile id="hcdf:can"/><rate><nominal value="5000000" unit="bit/s"/></rate></selected>
    <participant name="parent-body" role="hcdf:controller"><endpoint><port-ref component="parent-body" port="can0"/></endpoint></participant>
    <participant name="test-board" role="hcdf:target"><endpoint><port-ref component="test-board" port="can0"/></endpoint></participant>
  </bus>

  <chain name="test-chain">
    <description>Two-hop switched communication chain with timing, scheduling, MACsec, and EEE configuration.</description>
    <selected purpose="communication" carrier="electrical"><rate><nominal value="100000000" unit="bit/s"/></rate></selected>
    <configuration>
      <gptp-domain name="time" number="0">
        <clock name="parent-clock" kind="ordinary" gm-capable="true" priority1="128" priority2="128"><participant-ref network="test-chain" participant="parent-body"/></clock>
        <clock name="board-clock" kind="ordinary" gm-capable="false" priority1="255" priority2="255"><participant-ref network="test-chain" participant="test-board"/></clock>
        <port-defaults log-sync-interval="-3" neighbor-prop-delay-threshold-ns="800"/>
      </gptp-domain>
      <traffic-class name="ptp" number="7" preemption="express"><pcp value="7"/></traffic-class>
      <traffic-class name="safety" number="6" preemption="express"><pcp value="6"/></traffic-class>
      <traffic-class name="motion" number="5" preemption="express"><pcp value="5"/></traffic-class>
      <traffic-class name="bulk" number="0" preemption="preemptable"><pcp value="0"/></traffic-class>
      <gate-schedule name="1ms-control" cycle-time-ns="1000000">
        <gate duration-ns="50000"><open><traffic-class-ref network="test-chain" traffic-class="ptp"/></open></gate>
        <gate duration-ns="200000"><open><traffic-class-ref network="test-chain" traffic-class="safety"/><traffic-class-ref network="test-chain" traffic-class="motion"/></open></gate>
        <gate duration-ns="750000"><open><traffic-class-ref network="test-chain" traffic-class="bulk"/></open></gate>
      </gate-schedule>
      <schedule-assignment name="chain-participants"><schedule-ref network="test-chain" schedule="1ms-control"/><target><participant-ref network="test-chain" participant="parent-body"/></target><target><participant-ref network="test-chain" participant="test-board"/></target></schedule-assignment>
      <macsec><policy name="secure" enforcement="must-secure" cipher="ieee:gcm-aes-128" key-agreement="vendor:psk" credential-store-ref="se051"/><default-policy><macsec-policy-ref network="test-chain" policy="secure"/></default-policy></macsec>
      <eee default-mode="disabled"/>
    </configuration>
    <participant name="parent-body"><endpoint><port-ref component="parent-body" port="eth0"/></endpoint></participant>
    <participant name="test-board"><endpoint><port-ref component="test-board" port="eth0"/></endpoint></participant>
    <hop name="parent-body" role="root"><owner><component-ref component="parent-body"/></owner></hop>
    <hop name="test-board" role="tail"><owner><function-ref component="test-board" function="test-switch"/></owner></hop>
    <leg name="parent-to-board"><from><hop-ref network="test-chain" hop="parent-body"/><participant-ref network="test-chain" participant="parent-body"/></from><to><hop-ref network="test-chain" hop="test-board"/><participant-ref network="test-chain" participant="test-board"/></to></leg>
  </chain>

  <stream-profile uri="profiles/operational.streams.xml" selection-role="default"/>

  <!-- Transmission -->
  <transmission name="shoulder_transmission" type="planetary">
    <motor ref="foc_motor"/>
    <joint ref="shoulder_yaw"/>
    <reduction>50</reduction>
    <efficiency>0.85</efficiency>
  </transmission>

  <!-- Color palette -->
  <color name="rubber" rgba="0.1 0.1 0.1 1.0"/>

  <!-- Include -->
  <include uri="components/sensor-module.hcdf" sha="abc123" name="sensor-1" pose="0 0 0.1 0 0 0"/>

</hcdf>
