# Sum (`sum`)

> Adds or subtracts two signals, as set by signs.

![sum](https://voltecx-web.nguyenvanqui291.workers.dev/docs/reference/img/sum.svg)

[Component reference](https://voltecx-web.nguyenvanqui291.workers.dev/docs/reference/) · [繁體中文](https://voltecx-web.nguyenvanqui291.workers.dev/zh/docs/reference/control/sum/)

**Group:** Control · **Kind:** `{"block":"sum","kind":"control"}`

## When to use it

Use it to form an error (reference minus feedback) or to add a feed-forward term. Use Gain with a negative k to flip one signal.

## Pins

| Pin | Domain | Meaning |
|---|---|---|
| `in1` | signal | First input, first sign of signs |
| `in2` | signal | Second input, second sign of signs |
| `out` | signal | Both inputs added with their signs |

## Common parameters

- `signs`: Plus or minus sign for each input (Default: ++)

## Parameters

| Key | Unit | Default | Typical range | Description |
|---|---|---|---|---|
| `signs` | — | ++ |  | Plus or minus sign for each input |

_Parameter descriptions are in English in both languages._

**Use for:** Error signals · Feed-forward terms · Offsets

**Not for:** Multiplying signals → [`product`](https://voltecx-web.nguyenvanqui291.workers.dev/docs/reference/control/product/) · Formulas of several signals → [`expr`](https://voltecx-web.nguyenvanqui291.workers.dev/docs/reference/control/expr/)

## Formulas

| Formula | Equation | Source |
|---|---|---|
| Signed sum | out = s1·in1 + s2·in2 | Ogata, Modern Control Engineering, 5th ed. (2010), ch. 2 (block diagrams, summing point) |
| Result relative to in1 | 100·out/in1 | Ogata, Modern Control Engineering, 5th ed. (2010), ch. 2 |

## Quick check

Inputs:

- `in1`: First input = 5 —
- `in2`: Second input = 4.8 —
- `s1`: Sign of in1 (+1 or -1) = 1 —
- `s2`: Sign of in2 (+1 or -1) = -1 —

Outputs:

- `out`: Output = `s1*in1 + s2*in2` —
- `errpct`: Output in percent of in1 = `100*out/in1` —

## Model logic

- The output is s1·in1 + s2·in2 at every step, with no state and direct feedthrough.
- A minus character in signs gives -1 and any other character +1; spaces are ignored, only the first two characters count, and a missing one gives +1.
- An unconnected input reads 0, so an open in2 makes the block pass s1·in1.

## Model

out = s1*in1 + s2*in2. A minus character in signs gives the weight -1, and any other character gives +1. Only the first two characters count and spaces are ignored. An unconnected input reads 0, and the block has direct feedthrough.

## Common mistakes

- The signs follow the pins, not the wiring order. With signs set to -+ the result is in2 minus in1, so put the reference on in2 and the feedback on in1, or the loop gets positive feedback.
- Sum has only two inputs, so chain two Sum blocks for three terms. An input left open reads 0.

Problems rules: `pin.unconnected`

## Datasheet and sources

No datasheet applies. The signs are a design choice, and reference minus feedback is the usual one.

## Example

Open the example with the command `file.openExample` and the name `demo:sum`.

---
Generated by `cargo xtask reference` from the usage texts and parameter specs. Do not edit by hand.
