Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/dual iir config script #451

Merged
merged 16 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ jobs:
command: check
args: --verbose

- uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install Python Dependencies
run: |
python -m pip install --upgrade pip
pip install -r scripts/requirements.txt
pip install pylint
- name: Run Pylint
run: |
pylint scripts/

compile:
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.toolchain == 'nightly' }}
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/release-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ jobs:
command: install
args: mdbook-linkcheck

- name: Install ToC
uses: actions-rs/cargo@v1
with:
command: install
args: mdbook-toc

- uses: peaceiris/actions-mdbook@v1
with:
mdbook-version: '0.4.12'
Expand Down
6 changes: 2 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ branch = "feature/assume-init"
git = "https://github.com/quartiq/smoltcp-nal.git"
rev = "0634188"

[patch.crates-io.miniconf]
git = "https://github.com/quartiq/miniconf.git"
rev = "8da5961"

[features]
nightly = ["cortex-m/inline-asm", "dsp/nightly"]
pounder_v1_1 = [ ]
Expand Down
1 change: 1 addition & 0 deletions book/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This folder hosts the source used for generating Stabilizer's user manual.
The user manual is generated using `mdbook`, which can be installed via cargo:
```
cargo install mdbook
cargo install mdbook-toc
cargo install mdbook-linkcheck
```

Expand Down
5 changes: 5 additions & 0 deletions book/book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ title = "Stabilizer"
create-missing = false
build-dir = "stabilizer-manual"

[preprocessor.toc]
marker = "<-- TOC -->"
command = "mdbook-toc"
renderer = ["html"]

[output.html]
site-url = "/stabilizer"
git-repository-url = "https://github.com/quartiq/stabilizer"
Expand Down
24 changes: 24 additions & 0 deletions book/src/usage.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@


### Table of Contents

<-- TOC -->


# Miniconf Run-time Settings
Stabilizer supports run-time settings configuration using MQTT.

Expand Down Expand Up @@ -58,6 +65,23 @@ Refer to the documentation for [Miniconf](firmware/miniconf/enum.Error.html) for
description of the possible error codes that Miniconf may return if the settings update was
unsuccessful.

# IIR Configuration
For the `dual-iir` application, a Python utility has been written to easily configure the IIR
filters for a variety of filtering and control applications.

The script is located in `scripts/dual_iir_configuration.py`.

To use the script, install dependencies:
```bash
python -m pip install -r scripts/requirements.txt
ryan-summers marked this conversation as resolved.
Show resolved Hide resolved
```

Then, use the built-in help to learn how the utility can automatically configure your IIR filters
for you:
```bash
python scripts/dual_iir_configuration.py --help
```

# Telemetry

Stabilizer applications publish telemetry utilizes MQTT for managing run-time settings configurations as well as live telemetry
Expand Down
17 changes: 2 additions & 15 deletions hitl/loopback.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,12 @@

from gmqtt import Client as MqttClient
from miniconf import Miniconf
import stabilizer

# The minimum allowable loopback voltage error (difference between output set point and input
# measured value).
MINIMUM_VOLTAGE_ERROR = 0.010

def _voltage_to_machine_units(voltage):
""" Convert a voltage to IIR machine units.

Args:
voltage: The voltage to convert

Returns:
The IIR machine-units associated with the voltage.
"""
dac_range = 4.096 * 2.5
assert abs(voltage) <= dac_range, 'Voltage out-of-range'
return voltage / dac_range * 0x7FFF


def static_iir_output(output_voltage):
""" Generate IIR configuration for a static output voltage.

Expand All @@ -39,7 +26,7 @@ def static_iir_output(output_voltage):
Returns
The IIR configuration to send over Miniconf.
"""
machine_units = _voltage_to_machine_units(output_voltage)
machine_units = stabilizer.voltage_to_machine_units(output_voltage)
return {
'y_min': machine_units,
'y_max': machine_units,
Expand Down
3 changes: 2 additions & 1 deletion py/setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from setuptools import setup
from setuptools import setup, find_packages

setup(name='stabilizer',
packages=find_packages(),
version='0.1',
description='Stabilizer Utilities',
author='QUARTIQ GmbH',
Expand Down
21 changes: 21 additions & 0 deletions py/stabilizer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/python3
"""
Author: QUARTIQ GmbH

Description: General utilities for interfacing with Stabilizer using Python.
"""

# The maximum output scale of the Stabilizer DACs.
DAC_MAX_SCALE = 4.096 * 2.5

def voltage_to_machine_units(voltage):
""" Convert a voltage to IIR machine units.

Args:
voltage: The voltage to convert

Returns:
The IIR machine-units associated with the voltage.
"""
assert abs(voltage) <= DAC_MAX_SCALE, 'Voltage out-of-range'
return int(voltage / DAC_MAX_SCALE * 0x7FFF)
ryan-summers marked this conversation as resolved.
Show resolved Hide resolved
Loading