Skip to content
Snippets Groups Projects
Commit 5afe7507 authored by Christian Darsow-Fromm's avatar Christian Darsow-Fromm
Browse files

Merge branch...

Merge branch '193-make-the-basic-usage-example-as-jupyter-notebook-to-be-able-to-test-it' into 'develop'

Resolve "Make the basic usage example as Jupyter notebook to be able to test it"

Closes #193

See merge request las-nq/adwin-control!101
parents 6835279c 8d5c25f9
No related branches found
No related tags found
No related merge requests found
Showing
with 275 additions and 114 deletions
......@@ -58,7 +58,7 @@ $(AUTODOCDIR): $(MODULEDIR)
# $(AUTODOCBUILD) -f -o $@ $^
doc-requirements: $(AUTODOCDIR)
jupyter nbconvert documentation.ipynb --to rst
@cd jupyter; sh jupyter2markdown.sh; cd ..
html: doc-requirements
......
File moved
#!/usr/bin/env bash
jupyter nbconvert *.ipynb --to rst --output-dir=..
This diff is collapsed.
# Basic Usage
This page assumes a successful [installation](install.html) of NQontrol and all dependencies.
## Hello Servo Example
Here is a minimalistic, `hello world`-like example to show, how to control a servo using the python terminal or a little script.
```python
# Importing a ServoDevice is enough
from nqontrol import ServoDevice
# Create a new servo device object, connecting to adwin with the device number 1.
sd = ServoDevice(1)
# Print the timestamp
print(sd.timeStamp)
# Create the first servo on channel 1 from 8.
sd.addServo(1)
# Get the new servo object to control it.
s = sd.servo(1)
# enable in and output
s.inputSw = True
s.outputSw = True
```
Using a signal generator for the input you will now get the same signal on the output.
(That is true for signals below about 15 kHz.)
## Apply a ServoDesign
To use a servo for a real control loop we want to have some filters.
The full documentation is in the [OpenQlab docs](https://las-nq-serv.physnet.uni-hamburg.de/python/openqlab/servodesign.html).
Input:
```python
from OpenQlab.analysis import ServoDesign
# Create a ServoDesign object
design = ServoDesign()
# Add an integrator and a lowpass
design.integrator(1e2)
design.lowpass(5e3)
# Plot how it looks analytically
import matplotlib.pyplot as plt
design.plot()
plt.show()
```
Output:
![transfer function](_static/servoDesign_transfer_function.png)
Input:
```python
# Apply it to our servo
s.applyServoDesign(design)
# Control, what happens with the servo
print(s.filters)
```
Output:
```bash
[[1.00313, -0.999993, 0.0, -0.99373, 0.0],
[0.01975, -1.56097, 0.64130, 2.0, 1.0],
[1.0, 0, 0, 0, 0],
[1.0, 0, 0, 0, 0],
[1.0, 0, 0, 0, 0]]
```
Input:
```python
print(s.filterStates)
print(s.gain)
```
Output:
```bash
[True, True, False, False, False]
1.0
```
## Control Filters
```python
# Disable all filters
s.filterStates = [False] * 5
# Enable the second (index = 1) filter
s.filterState(1, True)
```
## Enable a Ramp
```python
# Choose a slow ramp with a frequency of 1 Hz.
# Amplitude = 4
s.setRamp(1, 4)
```
## Start Realtime Plotting
```python
# Start plotting in a background process
s.realtimePlot()
# disable plotting the output
s.realtime['ydata'] = ['input', 'aux']
# set constant y limit from -3 to 5
s.realtime['ylim'] = (-3, 5)
# stop realtime plotting
s.stopRealtimePlot()
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment