GithubHelp home page GithubHelp logo

Comments (3)

hgrecco avatar hgrecco commented on June 24, 2024

This is something that we need to resolve in a more general way. The following things need to be considered:

  1. Most of the times the unit is associated with a Feat and you do are not supposed to change it.
  2. 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.
  3. If you want/need to change it, you need two things
    1. inform the device that you are using a new unit (as in your example)
    2. 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.

vascotenner avatar vascotenner commented on June 24, 2024

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.

vascotenner avatar vascotenner commented on June 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.