### 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"""
   TestDriver_Constant(; name, max_accel, drag_coeff)

## Parameters: 

| Name         | Description                         | Units  |   Default value |
| ------------ | ----------------------------------- | ------ | --------------- |
| `max_accel`         |                          | --  |   5 |
| `drag_coeff`         |                          | --  |   0.2 |

## Variables

| Name         | Description                         | Units  | 
| ------------ | ----------------------------------- | ------ | 
| `vehicle_speed`         |                          | --  | 
"""
@component function TestDriver_Constant(; name = nothing, max_accel=Float64(5), drag_coeff=0.2, kwargs...)
  isnothing(name) && throw(ArgumentError("""
        The `name` keyword must be provided. Please consider using the `@named` macro,
        like so:

        @named model = TestDriver_Constant()
        """))
  __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__max_accel = max_accel
  append!(__params, @parameters (max_accel::Real))
  __initial_conditions[max_accel] = __local__max_accel
  __local__drag_coeff = drag_coeff
  append!(__params, @parameters (drag_coeff::Real))
  __initial_conditions[drag_coeff] = __local__drag_coeff

  ### Final Path Parameters

  ### Variables (declarations)
  append!(__vars, @variables (vehicle_speed(t)::Real))

  ### Variables (assignments)
  __ovr_vehicle_speed = pop!(__overrides, "vehicle_speed", nothing); isnothing(__ovr_vehicle_speed) || push!(__eqs, vehicle_speed ~ __ovr_vehicle_speed)
  __ovr_vehicle_speed__initial = pop!(__overrides, "vehicle_speed__initial", nothing); isnothing(__ovr_vehicle_speed__initial) || (__initial_conditions[vehicle_speed] = __ovr_vehicle_speed__initial)

  ### Constants
  __constants = Any[]

  ### Components
  # Subcomponent speed_ref_source of type BlockComponents.Sources.Step
  speed_ref_source_overrides = Dict(Symbol(replace(string(k), r"^speed_ref_source__" => "")) => v for (k, v) in __overrides if startswith(string(k), "speed_ref_source__"))
  filter!(p -> !startswith(string(first(p)), "speed_ref_source__"), __overrides)
  push!(__systems, @named speed_ref_source = BlockComponents.Sources.Step(height=20, offset=0, start_time=1, speed_ref_source_overrides...))
  # Subcomponent driver of type FrictionBrakeDemo.Driver
  driver_overrides = Dict(Symbol(replace(string(k), r"^driver__" => "")) => v for (k, v) in __overrides if startswith(string(k), "driver__"))
  filter!(p -> !startswith(string(first(p)), "driver__"), __overrides)
  push!(__systems, @named driver = FrictionBrakeDemo.Driver(driver_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_speed ~ 0)

  ### Assertions
  __assertions = []

  ### Equations
  push!(__eqs, ModelingToolkit.D_nounits(vehicle_speed) ~ (driver.throttle - driver.brake) * max_accel - drag_coeff * vehicle_speed)
  push!(__eqs, driver.speed_act ~ vehicle_speed)
  push!(__eqs, connect(speed_ref_source.y, driver.speed_ref))

  # 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 TestDriver_Constant
