---
url: /dyad/dev/stdlib/DiscreteComponents/components/SuperTwistingSMC.md
description: >-
  Dyad SuperTwistingSMC docs.  Discrete-time super-twisting sliding mode
  controller.
---

# `SuperTwistingSMC` {#SuperTwistingSMC}

Discrete-time super-twisting sliding mode controller.

The super-twisting algorithm is a second-order sliding mode controller that achieves finite-time convergence to the sliding surface `s = 0` while reducing chattering compared to first-order sliding mode controllers.

The control law is:

$$u = -\sqrt{k |s|} \operatorname{sign}(s) + \xi$$

$$\dot{\xi} = -k_2 k \operatorname{sign}(s)$$

where `s` is the sliding variable (provided as input), `k` is the control gain, and `k2` is a tuning parameter for the integral term. The integrator `ξ` is discretized using forward Euler.

# Connectors: {#Connectors:}

* `s`: Sliding variable input (computed externally based on the system's switching function)

* `y`: Control signal output

# Parameters: {#Parameters:}

* `k`: Control gain

* `k2`: Tuning parameter for the integral term

## Usage {#Usage}

`DiscreteComponents.SuperTwistingSMC(k=1, k2=0.5)`

## Parameters: {#Parameters:-2}

|             Name |                        Description | Units |             Default value |
| ----------------:| ----------------------------------:| -----:| -------------------------:|
|             `Ts` |                                    |     – |              SampleTime() |
| `initialization` |                                    |     – | DiscreteCom...t(; y0=0.0) |
|              `k` |                       Control gain |     – |                         1 |
|             `k2` | Tuning parameter for integral term |     – |                       0.5 |

## Connectors {#Connectors}

* `s` - This connector represents a real signal as an input to a component ([`RealInput`](/stdlib/Dyad/connectors/RealInput#RealInput))

* `y` - This connector represents a real signal as an output from a component ([`RealOutput`](/stdlib/Dyad/connectors/RealOutput#RealOutput))

## Variables {#Variables}

| Name |                      Description | Units |
| ----:| --------------------------------:| -----:|
|  `p` | Super-twisting proportional term |     – |
| `xi` |                 Integrator state |     – |

## Behavior {#Behavior}

$$ \begin{align}
p\left( t \right) &=  - sign\left( s\left( t \right) \right) ~ \sqrt{\left|s\left( t \right)\right| ~ k} \\
\mathtt{xi}\left( t \right) &= Shift(t, -1)\left( \mathtt{xi}\left( t \right) \right) - SampleTime(ShiftIndex(InferredClock.Inferred(UUID("024eaf85-9fc1-44f7-8d36-972bd14b0ee5")), 0), nothing) ~ k ~ \mathtt{k2} ~ sign\left( s\left( t \right) \right) \\
y\left( t \right) &= p\left( t \right) + \mathtt{xi}\left( t \right)
\end{align}
$$

## Source {#Source}

````dyad
"""
Discrete-time super-twisting sliding mode controller.

The super-twisting algorithm is a second-order sliding mode controller that achieves finite-time convergence to the sliding surface `s = 0` while reducing chattering compared to first-order sliding mode controllers.

The control law is:
```math
u = -\sqrt{k |s|} \operatorname{sign}(s) + \xi
```
```math
\dot{\xi} = -k_2 k \operatorname{sign}(s)
```

where `s` is the sliding variable (provided as input), `k` is the control gain, and `k2` is a tuning parameter for the integral term. The integrator `ξ` is discretized using forward Euler.

# Connectors:
- `s`: Sliding variable input (computed externally based on the system's switching function)
- `y`: Control signal output

# Parameters:
- `k`: Control gain
- `k2`: Tuning parameter for the integral term
"""
component SuperTwistingSMC@[input clk extends Discrete]
  "Sliding variable input"
  s = RealInput@[clk]() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": -100, "y1": 450, "x2": 0, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "Control signal output"
  y = RealOutput@[clk]() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 1000, "y1": 450, "x2": 1100, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  structural parameter Ts::Real = SampleTime()
  "Control gain"
  parameter k::Real = 1
  "Tuning parameter for integral term"
  parameter k2::Real = 0.5
  structural parameter initialization::InitialCondition = DiscreteComponents.InitialCondition.InitialOutput(y0 = 0.0)
  "Super-twisting proportional term"
  variable p::Real
  "Integrator state"
  variable xi::Real
relations
  p = -sqrt(k * abs(s)) * sign(s)
  xi@clk = xi@(clk-1) + Ts * (-k2 * k * sign(s))
  y = p + xi
  switch initialization
    case InitialOutput
      initial xi@(clk-1) = initialization.y0 + sqrt(k * abs(s@clk)) * sign(s@clk) + Ts * k2 * k * sign(s@clk)
    case SteadyState
      initial xi@(clk-1) = error("SteadyState initial condition is not supported for SuperTwistingSMC; use InitialOutput or InitialState")
    case InitialState
      initial xi@(clk-1) = initialization.x0
  end
metadata {
  "Dyad": {"icons": {"default": "dyad://DiscreteComponents/SuperTwistingSMC.svg"}}
}
end
````

````dyad
"""
Discrete-time super-twisting sliding mode controller.

The super-twisting algorithm is a second-order sliding mode controller that achieves finite-time convergence to the sliding surface `s = 0` while reducing chattering compared to first-order sliding mode controllers.

The control law is:
```math
u = -\sqrt{k |s|} \operatorname{sign}(s) + \xi
```
```math
\dot{\xi} = -k_2 k \operatorname{sign}(s)
```

where `s` is the sliding variable (provided as input), `k` is the control gain, and `k2` is a tuning parameter for the integral term. The integrator `ξ` is discretized using forward Euler.

# Connectors:
- `s`: Sliding variable input (computed externally based on the system's switching function)
- `y`: Control signal output

# Parameters:
- `k`: Control gain
- `k2`: Tuning parameter for the integral term
"""
component SuperTwistingSMC
  "Sliding variable input"
  s = RealInput@[clk]() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": -100, "y1": 450, "x2": 0, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "Control signal output"
  y = RealOutput@[clk]() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 1000, "y1": 450, "x2": 1100, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  structural parameter Ts::Real = SampleTime()
  "Control gain"
  parameter k::Real = 1
  "Tuning parameter for integral term"
  parameter k2::Real = 0.5
  structural parameter initialization::InitialCondition = DiscreteComponents.InitialCondition.InitialOutput(y0 = 0.0)
  "Super-twisting proportional term"
  variable p::Real
  "Integrator state"
  variable xi::Real
relations
  p = -sqrt(k * abs(s)) * sign(s)
  xi@clk = xi@(clk-1) + Ts * (-k2 * k * sign(s))
  y = p + xi
  switch initialization
    case InitialOutput
      initial xi@(clk-1) = initialization.y0 + sqrt(k * abs(s@clk)) * sign(s@clk) + Ts * k2 * k * sign(s@clk)
    case SteadyState
      initial xi@(clk-1) = error("SteadyState initial condition is not supported for SuperTwistingSMC; use InitialOutput or InitialState")
    case InitialState
      initial xi@(clk-1) = initialization.x0
  end
metadata {
  "Dyad": {"icons": {"default": "dyad://DiscreteComponents/SuperTwistingSMC.svg"}}
}
end
````

## Test Cases {#Test-Cases}

No test cases defined.

## Related {#Related}

* Examples

* Experiments

* Analyses
