Unofficial Python Bindings for the Force Dimension SDK
Project description
forcedimension_core-python
Want to do more with the Force Dimension SDK with less code? Also check out the experimental high level wrappers.
Installation
v1.0.0 of the bindings bind Force Dimension SDK v3.16.0+. They are available through a PyPI package for Python 3.8+.
python3 -m pip install forcedimension-core
NumPy is an optional dependency which allows the usage of special NumPy style containers.
python3 -m pip install "forcedimension-core[numpy]"
You will also need to install the Force Dimension SDK and setup any drivers or udev rules. If you are unfamiliar with how to do this please refer to the detailed installation instructions.
About
This project aims to create unofficial Python bindings for the Force Dimension SDK's C/C++ API.
import sys
from forcedimension_core import dhd
from forcedimension_core.dhd.os_independent import kbHit, kbGet
b = 5 # damping coefficient in [N][s]/[m]
k = 150 # spring constant in [N]/[m]
# Storage buffers
pos = [0.0, 0.0, 0.0]
v = [0.0, 0.0, 0.0]
f = [0.0, 0.0, 0.0]
# Try to open the first available device
if (ID := dhd.open()) == -1:
print(f"Error: {dhd.errorGetLastStr()}")
sys.exit(1)
if (name := dhd.getSystemName()) is not None:
print(isinstance(name, str)) # prints "True"
print(name)
# Run until button 0 is pressed (typically the center or only button)
# or q is pressed on the keyboard
try:
while not (dhd.getButton(index=0) or (kbHit() and kbGet() == 'q')):
# Try to get the position
if (dhd.getPosition(out=pos) == -1):
raise dhd.errno_to_exception(dhd.errorGetLast())(
op=dhd.getPosition, ID=ID
)
# Try to get the velocity
if (dhd.getLinearVelocity(out=v) == -1):
raise dhd.errno_to_exception(dhd.errorGetLast())(
op=dhd.getLinearVelocity, ID=ID
)
# Set the dynamics to be a spring-mass damper
f[0] = -k * pos[0] - b * v[0]
f[1] = -k * pos[1] - b * v[1]
f[2] = -k * pos[2] - b * v[2]
# Try to set the force
if (dhd.setForce(f) == -1):
raise dhd.errno_to_exception(dhd.errorGetLast())(
op=dhd.setForce, ID=ID
)
except Exception as ex:
print(str(ex))
finally:
# On error, close the device and gracefully exit
dhd.close(ID)
sys.exit(1)
Licensing and Rights
This project is NOT directly associated with Force Dimension. It does NOT involve reverse-engineering or distribution of proprietary code. Docstrings are lifted from the Force Dimension SDK documentation and revised to fit the Python bindings with the express permission of Force Dimension.
The Python code itself is licensed under LGPLv3 for the benefit of public research.
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 forcedimension_core-1.0.0.tar.gz
.
File metadata
- Download URL: forcedimension_core-1.0.0.tar.gz
- Upload date:
- Size: 57.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.10.12 Linux/5.15.0-84-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f10b5c01ed1bd271a64635be71859e97572dfc2ce9d85a02b703e003e9323254 |
|
MD5 | 7d2707640fa8c3db9f940a269f7a9c60 |
|
BLAKE2b-256 | 970a0acb0260cf6c2407db6b3f02a5441de559dde43ca3a9cf12a7b8b9a3fdca |
File details
Details for the file forcedimension_core-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: forcedimension_core-1.0.0-py3-none-any.whl
- Upload date:
- Size: 64.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.10.12 Linux/5.15.0-84-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b6b8e271a24c03a0fbc70164119b1ddd7dd7d70e1870eaf3a77e3d99b2822c5 |
|
MD5 | 206f5818dd1565dd8de29821fbee6173 |
|
BLAKE2b-256 | 875aa381b6416eb351a88a074d6b0b49de73fa2e6f0db650f53965e29d77f5f0 |