Perceptual Control Theory with Python
Project description
Perceptual Control Theory
A python library for creating perceptual control hierarchies.
With this library you can create and run simple or complex hierarchies of perceptual control systems as well as make use of the power of the Python platform and its rich set of packages.
In the context of this library a single control system comprising a perceptual, reference, comparator and output function is called a Node. The functions therein can be configured by the user.
A hierarchy is defined by a collection of nodes.
Install
pip install pct
Import
Examples of importing the library functionality.
import pct as p
from pct.hierarchy import Hierarchy
from pct import *
How to use
Import modules from the PCT library.
from pct.nodes import PCTNode
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-68c4aba7710d> in <module>
----> 1 from pct.nodes import PCTNode
ModuleNotFoundError: No module named 'pct.nodes'
For the purposes of this example define a world model. This would not be required if the real world is used, or a simulation such as OpenAI Gym.
def velocity_model(velocity, force , mass):
velocity = velocity + force / mass
return velocity
# World value
mass = 50
Create a PCTNode, a control system unit comprising a reference, perception, comparator and output function. The default value for the reference is 1. With the history flag set, the data for each iteration is recorded for later plotting.
pctnode = PCTNode(history=True)
Call the node repeatedly to control the perception of velocity. With the verbose flag set, the control values are printed. In this case the printed values are the iteration number, the (velocity) reference, the perception, the error and the (force) output.
for i in range(40):
print(i, end=" ")
force = pctnode(verbose=True)
velocity = velocity_model(pctnode.get_perception_value(), force, mass)
pctnode.set_perception_value(velocity)
Using the plotly library plot the data. The graph shows the perception being controlled to match the reference value.
import plotly.graph_objects as go
fig = go.Figure(layout_title_text="Velocity Goal")
fig.add_trace(go.Scatter(y=pctnode.history.data['refcoll']['constant'], name="ref"))
fig.add_trace(go.Scatter(y=pctnode.history.data['percoll']['variable'], name="perc"))
This following code is only for the purposes of displaying image of the graph generated by the above code.
from IPython.display import Image
Image(url='http://www.perceptualrobots.com/wp-content/uploads/2020/08/pct_node_plot.png')
This shows a very basic example of the use of the PCT library. For more advanced functionality see the API documentation at https://perceptualrobots.github.io/pct/.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pct-0.0.9.tar.gz
.
File metadata
- Download URL: pct-0.0.9.tar.gz
- Upload date:
- Size: 18.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.0.post20201006 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22b52ee2e9e2e3cbfc83addbc0140834bb286279eda47603a64176bc2ab426ff |
|
MD5 | fca83511ee1df871d19b1d6174202e51 |
|
BLAKE2b-256 | 15059898f8df9a082ca4ee1749a6b523592f567cbaf423046ca9c806d529d457 |
File details
Details for the file pct-0.0.9-py3-none-any.whl
.
File metadata
- Download URL: pct-0.0.9-py3-none-any.whl
- Upload date:
- Size: 18.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.0.post20201006 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1b68d7349079bab6f6a008236d033884130cca56f068b221100d1224d969398 |
|
MD5 | 80e4399b3acaa26a1fd6a6999ea0a328 |
|
BLAKE2b-256 | d45a44b270ef83c172f6480755457efe7936459fabc3f5b9a4e5dbb97a84f8d2 |