optoforce
Project description
import optoforce
A package which simplifies connecting to and reading from optoforce sensors, using Python
This is mainly here to accompany my blog posts on communicating with embedded systems using python, where the optoforce sensor is an example. I hope this package is simple enough to serve as a template for others. I see that there are other packages on GitHub which help with this
I don't imagine it'll have many users, since the optoforce website redirects to another company which doesn't even mention them, and that company's optoforce page is pretty blank. BUT I use one, so perhaps there are others?
Installation
python -m pip install optoforce
Usage
From a python script:
# 16 byte frame/single-channel 3 axis force sensor (OMD-45-FH-2000N)
from optoforce import OptoForce16 as OptoForce
with OptoForce(speed_hz=100, filter_hz=15, zero=False) as force_sensor:
measurement = force_sensor.read(only_latest_data=False)
do_stuff_with_force_readings(measurement.Fx, measurement.Fy, measurement.Fz)
A call to OptoForce.read()
returns a measurement packet (a NamedTuple) containing force readings and other potentially useful data. For the specifics of each sensor model, see Reading16
, Reading34
and Reading22
in optoforce/reading.py
.
It's still a little verbose, so you may want to define shortcuts for your particular application. For example, if you don't care about anything except the vertical force:
with OptoForce() as force_sensor:
read_fz = lambda: force_sensor.read(only_latest_data=False).Fz
while True:
print(read_fz())
Or from the command line, to log to a file:
$ python -m optoforce --filename force-data.csv
If you want to detect and handle sensor errors as reported in the status word, look at the doc string in optoforce/status.py
. It was written for completeness after I finished my use for the OptoForce, so it hasn't been tested!
OptoForce models supported
Possibly,
- 16 byte frame/single-channel 3 axis force sensor (OMD-45-FH-2000N)
- 34 byte frame/multi-channel 3 axis force sensor (4 channels)
- 22 byte frame/single-channel 6 axis force/torque sensor
but I only have access to the 16 byte frame model, so I can't test the other two. The 34 byte model has been reported to work too. I imagine this means that the 22 byte model will be fine, but the torque readings aren't scaled as I don't have that datasheet :/
Sources
OptoForce General DAQ - USB,CAN,UART - v1.7.pdf
was used to implement this module
The force scale parameters are from SensitivityReport-PFH0A052.pdf
A friend mentioned that I might not be allowed to share those docs, since the company is quite secretive, and I unfortunately haven't seen them online
Common bugs
If you get permission errors when trying to open the serial port and you run linux, try running the code below (source)
$ sudo chmod 666 /dev/ttyACM0 # replace with your serial port
Permission errors can also happen on Windows -- you'll know that's the case when you get an error which includes Original message: PermissionError(...)
. That can happen when something else is using the device. In that case, making sure no other program is connected to the device should work. You could do that by unplugging the sensor, and plugging it back in again.
Publishing a new version
Install flit, which makes publishing packages ridiculously easy. Next, increase the __version__
number in optoforce/__init__.py
. Then, create a (local) tag for the commit and publish:
# make a local tag with message "release v0.0.1"
$ git tag -a v0.0.1 -m "release v0.0.1"
# push local tag to remote repo
$ git push origin v0.0.1
# generate files into dist/ and upload them to pypi
$ flit publish
Project details
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 optoforce-0.2.1.tar.gz
.
File metadata
- Download URL: optoforce-0.2.1.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.24.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 040e9f95b7805b221c8b5513513545c8d9ccb92e80d819cb6dafe638085ce76b |
|
MD5 | d0ac6832231521e6e8b690f5d64f2a38 |
|
BLAKE2b-256 | a5f69109396e00c47aa93cfbe8e449e607d2b229d85f15614a95c5a5fa81e7c6 |
File details
Details for the file optoforce-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: optoforce-0.2.1-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.24.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50977d35dfc984a33626ccc883293ebacd6adcb0d31b5a720a71b3b826306f52 |
|
MD5 | 0f3c0764ca0b719d427f0fe7a8d1e358 |
|
BLAKE2b-256 | 918ba543873a394e2e0efe2b012e43277810226e88f9a877e34f53c2c7aedea2 |