<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:element name="board" type="boardXml"/>
    <xs:element name="board_calibration" type="boardCalibrationXml"/>
    <xs:element name="controller" type="controllerXml"/>
    <xs:element name="controller_gains" type="focGainsXml"/>
    <xs:element name="encoder" type="encoderConfigXml"/>
    <xs:element name="encoders" type="encodersXml"/>
    <xs:element name="gear_train" type="gearTrainXml"/>
    <xs:element name="motor" type="motorXml"/>
    <xs:element name="motor_driver" type="motorDriverXml"/>
    <xs:element name="thermal_model" type="thermalModelXml"/>

    <xs:complexType name="motorDriverXml">
        <xs:all>
            <xs:element ref="motor" minOccurs="0"/>
            <xs:element ref="thermal_model" minOccurs="0"/>
            <xs:element ref="controller" minOccurs="0"/>
            <xs:element ref="encoders" minOccurs="0"/>
            <xs:element ref="board" minOccurs="0"/>
            <xs:element ref="board_calibration" minOccurs="0"/>
            <xs:element ref="gear_train" minOccurs="0"/>
        </xs:all>
    </xs:complexType>

    <xs:complexType name="motorXml">
        <xs:all/>
        <xs:attribute name="pole_pairs" type="xs:int"/>
        <xs:attribute name="speed_constant" type="xs:string"/>
        <xs:attribute name="torque_constant" type="xs:string"/>
        <xs:attribute name="max_motor_speed" type="xs:string"/>
        <xs:attribute name="winding_resistance" type="xs:string"/>
        <xs:attribute name="winding_inductance" type="xs:string"/>
        <xs:attribute name="max_winding_current" type="xs:string"/>
        <xs:attribute name="max_winding_temperature" type="xs:string"/>
        <xs:attribute name="torque_temp_constant" type="xs:string"/>
        <xs:attribute name="velocity_temp_constant" type="xs:string"/>
    </xs:complexType>

    <xs:complexType name="thermalModelXml">
        <xs:all/>
        <xs:attribute name="housing_thermal_resistance" type="xs:string"/>
        <xs:attribute name="winding_thermal_resistance" type="xs:string"/>
        <xs:attribute name="housing_thermal_time_const" type="xs:string"/>
        <xs:attribute name="winding_thermal_time_const" type="xs:string"/>
        <xs:attribute name="temperature_source" type="xs:string"/>
        <xs:attribute name="model_start_percentage" type="xs:string"/>
    </xs:complexType>

    <xs:complexType name="controllerXml">
        <xs:all>
            <xs:element name="foc_iq_gains" type="focGainsXml" minOccurs="0"/>
            <xs:element name="foc_id_gains" type="focGainsXml" minOccurs="0"/>
        </xs:all>
        <xs:attribute name="mode" type="xs:string"/>
        <xs:attribute name="overmodulation" type="xs:string"/>
    </xs:complexType>

    <xs:complexType name="focGainsXml">
        <xs:all/>
        <xs:attribute name="k" type="xs:string"/>
        <xs:attribute name="ki" type="xs:string"/>
        <xs:attribute name="i_clamp" type="xs:string"/>
    </xs:complexType>

    <xs:complexType name="encodersXml">
        <xs:all>
            <xs:element name="hall_switches" type="encoderConfigXml" minOccurs="0"/>
            <xs:element name="encoder_a1" type="encoderConfigXml" minOccurs="0"/>
            <xs:element name="encoder_a2" type="encoderConfigXml" minOccurs="0"/>
            <xs:element name="encoder_b1" type="encoderConfigXml" minOccurs="0"/>
            <xs:element name="encoder_b2" type="encoderConfigXml" minOccurs="0"/>
        </xs:all>
        <xs:attribute name="motor_encoder" type="xs:string"/>
        <xs:attribute name="output_encoder" type="xs:string"/>
        <xs:attribute name="deflection_encoder" type="xs:string"/>
        <xs:attribute name="torque_source" type="xs:string"/>
    </xs:complexType>

    <xs:complexType name="encoderConfigXml">
        <xs:all/>
        <xs:attribute name="type" type="xs:string"/>
        <xs:attribute name="calibration_type" type="xs:string"/>
        <xs:attribute name="direction" type="xs:string"/>
        <xs:attribute name="absolute" type="xs:boolean"/>
        <xs:attribute name="ticks_per_revolution" type="xs:string"/>
        <xs:attribute name="position_filter_size" type="xs:string"/>
        <xs:attribute name="velocity_filter_size" type="xs:string"/>
        <xs:attribute name="calibration_offset" type="xs:string"/>
    </xs:complexType>

    <xs:complexType name="boardXml">
        <xs:all/>
        <xs:attribute name="min_duty_cycle" type="xs:string"/>
        <xs:attribute name="max_duty_cycle" type="xs:string"/>
        <xs:attribute name="max_board_current" type="xs:string"/>
        <xs:attribute name="switching_frequency_hz" type="xs:string"/>
        <xs:attribute name="current_sense_threshold_vds" type="xs:string"/>
        <xs:attribute name="current_sense_threshold_winding" type="xs:string"/>
        <xs:attribute name="current_sense_gain" type="xs:string"/>
        <xs:attribute name="current_filter_size" type="xs:string"/>
        <xs:attribute name="control_divider" type="xs:int"/>
        <xs:attribute name="winding_order" type="xs:string"/>
        <xs:attribute name="hall_order" type="xs:string"/>
    </xs:complexType>

    <xs:complexType name="boardCalibrationXml">
        <xs:all/>
        <xs:attribute name="offset_i_a" type="xs:string"/>
        <xs:attribute name="offset_i_b" type="xs:string"/>
        <xs:attribute name="offset_i_c" type="xs:string"/>
        <xs:attribute name="offset_i_bus" type="xs:string"/>
        <xs:attribute name="offset_v_a" type="xs:string"/>
        <xs:attribute name="offset_v_b" type="xs:string"/>
        <xs:attribute name="offset_v_c" type="xs:string"/>
    </xs:complexType>

    <xs:complexType name="gearTrainXml">
        <xs:all/>
        <xs:attribute name="gear_ratio_numerator" type="xs:int"/>
        <xs:attribute name="gear_ratio_denominator" type="xs:int"/>
        <xs:attribute name="efficiency" type="xs:string"/>
        <xs:attribute name="max_output_torque" type="xs:string"/>
    </xs:complexType>

</xs:schema>