content: {-# LANGUAGE PostfixOperators #-}
  module Drasil.PDController.DataDefs where
  
  import Drasil.PDController.Concepts
  import Drasil.PDController.Assumptions
  import Drasil.PDController.Unitals
  import Drasil.PDController.References
  import Drasil.PDController.TModel
  import Data.Drasil.Concepts.Math (equation)
  import Language.Drasil
  import Theory.Drasil (DataDefinition, ddE)
  import Language.Drasil.Chunk.Concept.NamedCombinators
  import qualified Language.Drasil.Sentence.Combinators as S
  
  dataDefinitions :: [DataDefinition]
  dataDefinitions = [ddErrSig, ddPropCtrl, ddDerivCtrl, ddCtrlVar]
  
  ----------------------------------------------
  
  ddErrSig :: DataDefinition
  ddErrSig
    = ddE ddErrSigDefn [dRef johnson2008] Nothing "ddProcessError"
        [ddErrSigNote]
  
  ddErrSigDefn :: SimpleQDef
  ddErrSigDefn = mkQuantDef dqdProcessErrorFD ddErrSigEqn
  
  ddErrSigEqn :: Expr
  ddErrSigEqn = sy dqdSetPointFD $- sy dqdProcessVariableFD
  
  ddErrSigNote :: Sentence
  ddErrSigNote
    = foldlSent
        [atStartNP (the processError), S "is the difference between the Set-Point and" +:+.
           phrase processVariable,
         atStartNP (the equation), S "is converted" `S.toThe` phrase ccFrequencyDomain,
           S "by applying the", atStart ccLaplaceTransform +:+. fromSource tmLaplace,
         atStartNP (the setPoint), S "is assumed to be constant throughout the",
           phrase simulation +:+. fromSource aSP,
         S "The initial value" `S.ofThe` phrase processVariable, S "is assumed",
           S "to be zero", fromSource aInitialValue]
  
  ----------------------------------------------
  
  ddPropCtrl :: DataDefinition
  ddPropCtrl
    = ddE ddPropCtrlDefn [dRef johnson2008] Nothing "ddPropCtrl"
        [ddPropCtrlNote]
  
  ddPropCtrlDefn :: SimpleQDef
  ddPropCtrlDefn = mkQuantDef dqdPropControlFD ddPropCtrlEqn
  
  ddPropCtrlEqn :: Expr
  ddPropCtrlEqn = sy dqdPropGain $* sy dqdProcessErrorFD
  
  ddPropCtrlNote :: Sentence
  ddPropCtrlNote
    = foldlSent
        [S "The Proportional Controller" `S.is` S "the product" `S.ofThe` phraseNP (propGain `andThe`
           processError) +:+. fromSource ddErrSig,
           atStartNP (the equation), S "is converted" `S.toThe` phrase ccFrequencyDomain,
           S "by applying the", atStart ccLaplaceTransform, fromSource tmLaplace]
  
  ----------------------------------------------
  
  ddDerivCtrl :: DataDefinition
  ddDerivCtrl
    = ddE ddDerivCtrlDefn [dRef johnson2008] Nothing "ddDerivCtrl"
        [ddDerivCtrlNote]
  
  ddDerivCtrlDefn :: SimpleQDef
  ddDerivCtrlDefn = mkQuantDef dqdDerivativeControlFD ddDerivCtrlEqn
  
  ddDerivCtrlEqn :: Expr
  ddDerivCtrlEqn
    = sy dqdDerivGain $* sy dqdProcessErrorFD $* sy dqdFreqDomain
  
  ddDerivCtrlNote :: Sentence
  ddDerivCtrlNote
    = foldlSent
        [S "The Derivative Controller" `S.is` S "the product" `S.ofThe` phrase derGain
           `S.andThe` S "differential" `S.ofThe` phrase processError +:+. fromSource ddErrSig,
         atStartNP (the equation), S "is converted" `S.toThe` phrase ccFrequencyDomain,
           S "by applying the", atStart ccLaplaceTransform +:+. fromSource tmLaplace,
         S "A pure form" `S.ofThe` S "Derivative controller" `S.is` S "used in this",
           S "application", fromSource aUnfilteredDerivative]
  
  ----------------------------------------------
  
  ddCtrlVar :: DataDefinition
  ddCtrlVar
    = ddE ddCtrlVarDefn [dRef johnson2008] Nothing "ddCtrlVar" [ddCtrlNote]
  
  ddCtrlVarDefn :: SimpleQDef
  ddCtrlVarDefn = mkQuantDef dqdCtrlVarFD ddCtrlEqn
  
  ddCtrlEqn :: Expr
  ddCtrlEqn
    = sy dqdProcessErrorFD $* (sy dqdPropGain $+ 
          (sy dqdDerivGain $* sy dqdFreqDomain))
  
  ddCtrlNote :: Sentence
  ddCtrlNote
    = foldlSent
        [atStartNP (the controlVariable) +:+. (S "is the output" `S.ofThe` S "controller"),
         S "In this case" `sC` S "it is the sum" `S.ofThe` S "Proportional", fromSource ddPropCtrl,
           S "and Derivative", fromSource ddDerivCtrl +:+.
           S "controllers",
         S "The parallel", fromSource aParallelEq,
           S "and de-coupled", fromSource aDecoupled,
           S "form of the PD equation" `S.is` S "used in this document"]