### DO NOT EDIT THIS FILE
### This file is auto-generated by the Dyad command-line compiler.
### If you edit this code it is likely to get overwritten.
### Instead, update the Dyad source code and regenerate this file


@doc Markdown.doc"""
   SimpleVehicle(; name, vehicle_mass_kg, inertia_moment, wheel_radius, damping_coeff, initial_position, initial_velocity)

## Parameters: 

| Name         | Description                         | Units  |   Default value |
| ------------ | ----------------------------------- | ------ | --------------- |
| `vehicle_mass_kg`         |                          | kg  |   2194 |
| `inertia_moment`         |                          | kg.m2  |   3.08 |
| `wheel_radius`         |                          | m  |   0.15 |
| `damping_coeff`         |                          | N.s/m  |   30 |
| `initial_position`         |                          | m  |   0 |
| `initial_velocity`         |                          | m/s  |   0 |

## Connectors

 * `shaft` - This connector represents a rotational spline with angle and torque as the potential and flow variables, respectively. ([`Spline`](@ref))
 * `vehicle_speed` - This connector represents a real signal as an output from a component ([`RealOutput`](@ref))
 * `wheel_speed` - This connector represents a real signal as an output from a component ([`RealOutput`](@ref))
"""
@component function SimpleVehicle(; name = nothing, vehicle_mass_kg=Float64(2194), inertia_moment=3.08, wheel_radius=0.15, damping_coeff=Float64(30), initial_position=Float64(0), initial_velocity=Float64(0), kwargs...)
  isnothing(name) && throw(ArgumentError("""
        The `name` keyword must be provided. Please consider using the `@named` macro,
        like so:

        @named model = SimpleVehicle()
        """))
  __overrides = Dict{String, Symbolics.SymbolicT}(string(k) => v for (k, v) in kwargs)
  __params = Symbolics.SymbolicT[]
  __vars = Symbolics.SymbolicT[]
  __systems = System[]
  __guesses = Dict{Symbolics.SymbolicT, Symbolics.SymbolicT}()
  __initial_conditions = Dict{Symbolics.SymbolicT, Symbolics.SymbolicT}()
  __initialization_eqs = Equation[]
  __eqs = Equation[]
  __bindings = Dict{Symbolics.SymbolicT, Symbolics.SymbolicT}()

  ### Structural Parameters (functions)

  ### Structural Parameters (Final)

  ### Path Parameters (functions)

  ### Path Parameters (non-final)

  ### Final Parameters (declarations)

  ### Final Parameters (assignments)

  ### Deferred assignment (default values that depend on final parameters)

  ### Symbolic Parameters
  __local__vehicle_mass_kg = vehicle_mass_kg
  append!(__params, @parameters (vehicle_mass_kg::Real), [bounds = (0, Inf)])
  __initial_conditions[vehicle_mass_kg] = __local__vehicle_mass_kg
  __local__inertia_moment = inertia_moment
  append!(__params, @parameters (inertia_moment::Real))
  __initial_conditions[inertia_moment] = __local__inertia_moment
  __local__wheel_radius = wheel_radius
  append!(__params, @parameters (wheel_radius::Real))
  __initial_conditions[wheel_radius] = __local__wheel_radius
  __local__damping_coeff = damping_coeff
  append!(__params, @parameters (damping_coeff::Real))
  __initial_conditions[damping_coeff] = __local__damping_coeff
  __local__initial_position = initial_position
  append!(__params, @parameters (initial_position::Real))
  __initial_conditions[initial_position] = __local__initial_position
  __local__initial_velocity = initial_velocity
  append!(__params, @parameters (initial_velocity::Real))
  __initial_conditions[initial_velocity] = __local__initial_velocity

  ### Final Path Parameters
  append!(__vars, @variables (vehicle_speed(t)::Real), [output = true])
  append!(__vars, @variables (wheel_speed(t)::Real), [output = true])

  ### Variables (declarations)

  ### Variables (assignments)

  ### Constants
  __constants = Any[]

  ### Components
  push!(__systems, @named shaft = __Dyad__Spline())
  # Subcomponent inertia of type RotationalComponents.Components.Inertia
  inertia_overrides = Dict(Symbol(replace(string(k), r"^inertia__" => "")) => v for (k, v) in __overrides if startswith(string(k), "inertia__"))
  filter!(p -> !startswith(string(first(p)), "inertia__"), __overrides)
  push!(__systems, @named inertia = RotationalComponents.Components.Inertia(J=inertia_moment, inertia_overrides...))
  # Subcomponent wheel of type RotationalComponents.Components.IdealRollingWheel
  wheel_overrides = Dict(Symbol(replace(string(k), r"^wheel__" => "")) => v for (k, v) in __overrides if startswith(string(k), "wheel__"))
  filter!(p -> !startswith(string(first(p)), "wheel__"), __overrides)
  push!(__systems, @named wheel = RotationalComponents.Components.IdealRollingWheel(radius=wheel_radius, wheel_overrides...))
  # Subcomponent vehicle_mass of type TranslationalComponents.Components.Mass
  vehicle_mass_overrides = Dict(Symbol(replace(string(k), r"^vehicle_mass__" => "")) => v for (k, v) in __overrides if startswith(string(k), "vehicle_mass__"))
  filter!(p -> !startswith(string(first(p)), "vehicle_mass__"), __overrides)
  push!(__systems, @named vehicle_mass = TranslationalComponents.Components.Mass(m=vehicle_mass_kg, vehicle_mass_overrides...))
  # Subcomponent load_damper of type TranslationalComponents.Components.Damper
  load_damper_overrides = Dict(Symbol(replace(string(k), r"^load_damper__" => "")) => v for (k, v) in __overrides if startswith(string(k), "load_damper__"))
  filter!(p -> !startswith(string(first(p)), "load_damper__"), __overrides)
  push!(__systems, @named load_damper = TranslationalComponents.Components.Damper(d=damping_coeff, load_damper_overrides...))
  # Subcomponent ground of type TranslationalComponents.Components.Fixed
  ground_overrides = Dict(Symbol(replace(string(k), r"^ground__" => "")) => v for (k, v) in __overrides if startswith(string(k), "ground__"))
  filter!(p -> !startswith(string(first(p)), "ground__"), __overrides)
  push!(__systems, @named ground = TranslationalComponents.Components.Fixed(s0=0, ground_overrides...))
  # Subcomponent housing of type RotationalComponents.Components.Fixed
  housing_overrides = Dict(Symbol(replace(string(k), r"^housing__" => "")) => v for (k, v) in __overrides if startswith(string(k), "housing__"))
  filter!(p -> !startswith(string(first(p)), "housing__"), __overrides)
  push!(__systems, @named housing = RotationalComponents.Components.Fixed(phi0=0, housing_overrides...))
  # Subcomponent load_anchor of type TranslationalComponents.Components.Fixed
  load_anchor_overrides = Dict(Symbol(replace(string(k), r"^load_anchor__" => "")) => v for (k, v) in __overrides if startswith(string(k), "load_anchor__"))
  filter!(p -> !startswith(string(first(p)), "load_anchor__"), __overrides)
  push!(__systems, @named load_anchor = TranslationalComponents.Components.Fixed(s0=0, load_anchor_overrides...))

  ### Check there are no unmatched overrides
  isempty(__overrides) || throw(ArgumentError("overides: [$(join(keys(__overrides), ", "))] don't match names found in model. These names may exist in the model but could have been conditionally excluded."))

  ### Guesses

  ### Initialization Equations
  push!(__initialization_eqs, vehicle_mass.s ~ initial_position)
  push!(__initialization_eqs, vehicle_mass.v ~ initial_velocity)

  ### Assertions
  __assertions = []

  ### Equations
  push!(__eqs, vehicle_speed ~ vehicle_mass.v)
  push!(__eqs, wheel_speed ~ inertia.w)
  push!(__eqs, connect(shaft, inertia.spline_a))
  push!(__eqs, connect(inertia.spline_b, wheel.spline))
  push!(__eqs, connect(wheel.flange, vehicle_mass.flange_a))
  push!(__eqs, connect(vehicle_mass.flange_b, load_damper.flange_a))
  push!(__eqs, connect(load_damper.flange_b, load_anchor.flange))
  push!(__eqs, connect(wheel.support_t, ground.flange))
  push!(__eqs, connect(wheel.support_r, housing.spline))

  # Return completely constructed System
  return System(__eqs, t, __vars, __params; systems=__systems, initial_conditions=__initial_conditions, guesses=__guesses, name, initialization_eqs=__initialization_eqs, bindings=__bindings, assertions=__assertions)
end
export SimpleVehicle
