Comments (3)
This is something that we need to resolve in a more general way. The following things need to be considered:
- Most of the times the unit is associated with a Feat and you do are not supposed to change it.
- With a device with enough significant digits when getting/setting a value, you can use in your program the unit that you want and it is transparently converted to the units the device needs.
- If you want/need to change it, you need two things
- inform the device that you are using a new unit (as in your example)
- change the unit of the feats in question. You can use a (still provisional) API shown here
In this context, consider an hypothetical instrument that can change the position with the command POS
followed by a number which is the value in some predefine units. The following program would make sense:
# Position has cm units by default
>>> print(inst.position)
0 centimeter
>>> inst.position = Q_(1, 'cm')
# Transmitted to the instrument as POS 1 (meaning 1 centimeter)
>>> inst.units = 'mm'
>>> inst.position = Q_(1, 'cm')
# Transmitted to the instrument as POS 10 (meaning 10 millimeter)
But your case is a different one which only applies to 'dimensionless' feats. I say dimensionless (in quotes) because even if you are changing a physical magnitude the API will be dimensionless because the units might:
- not be of the same dimensionality and therefore are not interconvertible (in your example, how do you convert from 1 inch to radian)
- not be defined in the registry and not definable because they are not really universal (in your example, how much is 1 encodercount depends on the encoder)
So the program would look like:
>>> print(inst.position)
0
>>> inst.position = 1
# Transmitted to the instrument as POS 1 (meaning 1 centimeter)
>>> inst.units = 'encodercount'
>>> inst.position = 1
# Transmitted to the instrument as POS 1 (meaning 1 encodercount)
There is no proper and easy way (that I can think of) to have units in this type of position
Feat because it can lead to problems like this:
# Position has cm units by default
>>> print(inst.position)
0 centimeter
>>> inst.position = Q_(1, 'cm')
# Transmitted to the instrument as POS 1 (meaning 1 centimeter)
>>> inst.units = 'encodercount'
>>> inst.position = Q_(1, 'cm')
# What should it do????
The only way will be to define a context attached to the Feat to teach non specific unit conversions.
The way I have used in the past to deal with something like this was defining only certain units for the Feat (millimeter, inch, etc). And if really need radians or encodercount I define other feats. It is not nice but it works.
Going back to your question. If you are NOT going to relate to a Feat, the best way is to use string instead of Quantities. (Additionally, quantities might not be a good idea as "2 meters" and "1 meter" will be different keys even though is the same unit.
from lantz.
This is a long standing open issue.
I came across it when using an newport motion controller, which can have several axis connected. Depending on the connected motion device, it can use different units (radian for rotational devices). It would be nice if Lantz could automatically determine the kind of motion device and set the relevant units.
from lantz.
I have implemented the ability to set the units of feats after creation of the object: https://github.com/vascotenner/lantz/tree/drivers_developv
from lantz.
Related Issues (20)
- VISA library path of simulated instrument
- Update links to documentation
- inst.finalize() leaves device in remote mode (using "with inst ...")
- Interface to adjust inst.query_delay in Lantz driver. HOT 2
- DictFeatWidget fails to initialize when keys are not explicitly set
- In case of a DictFeat, LabeledFeatWidget._widget doesn't have a value_to_feat method and communication fails
- In case of DictFeat, DriverTestWidget.update_on_change() has no effect
- DriverTestWidget.widgets_values_as_dict() broken
- Driver refresh() fails with DictFeats
- Not imported : from lantz.ui.qtwidgets import start_test_app
- Python2 HOT 4
- lantz import issues
- Remote Network Instrument HOT 1
- Foreign library with cdll instead of windll
- Qt5 support HOT 1
- Import lantz issue pyqt HOT 1
- USB to Serial devices
- ValueError: 'bytesize' is not a valid attribute for type SerialInstrument HOT 1
- Archive repository and link to lantzproject/lantz
- AttributeError: module 'PySide.QtSvg' has no attribute '__version__'
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lantz.