-
Notifications
You must be signed in to change notification settings - Fork 2
Units
This crate provides typed physical quantities for the rest of qitech_lib. It is a custom
uom unit system: the seven SI base quantities, a hand-picked set of derived
quantities, and only the units QiTech machines actually use. The storage type is always f64.
Other crates use it wherever a value has a physical meaning. For example, ethercat_hal analog I/O
returns ElectricCurrent / ElectricPotential, and xtrem returns weights as Mass.
use units::f64::{Length, Time, Velocity, ElectricCurrent};
use units::length::millimeter;
use units::time::second;
use units::velocity::meter_per_minute;
use units::electric_current::milliampere;
let d = Length::new::<millimeter>(1500.0);
let t = Time::new::<second>(3.0);
let v: Velocity = d / t; // dimensions are checked at compile time
println!("{:.1} m/min", v.get::<meter_per_minute>()); // 30.0
let i = ElectricCurrent::new::<milliampere>(12.0);-
Quantity types live in
units::f64::*, which is also re-exported at the crate root, sounits::Massworks. -
Unit markers live in the module named after the quantity (
units::mass::gram). -
Construct and read values with
Q::new::<unit>(x)andq.get::<unit>(). - Arithmetic between quantities gives the correctly-dimensioned result type.
-
units::ConstZerois re-exported fromuom, so you can writeLength::ZERO.
Only the units listed here exist. This crate does not include all of uom's units, so, for
example, there is no minute for Time and no millisecond.
Quantity (units::f64::…) |
Module | Units |
|---|---|---|
Length |
length |
millimeter, centimeter, meter
|
Mass |
mass |
gram, kilogram, pound, ounce
|
Time |
time |
second |
ElectricCurrent |
electric_current |
milliampere, centiampere, ampere
|
ThermodynamicTemperature |
thermodynamic_temperature |
kelvin, degree_celsius
|
AmountOfSubstance |
amount_of_substance |
mole |
LuminousIntensity |
luminous_intensity |
candela |
Velocity |
velocity |
millimeter_per_second, meter_per_second, meter_per_minute
|
Acceleration |
acceleration |
meter_per_second_squared, meter_per_minute_per_second
|
Jerk |
jerk |
meter_per_second_cubed, meter_per_minute_per_second_squared
|
Angle ¹ |
angle |
radian, degree, revolution
|
AngularVelocity ¹ |
angular_velocity |
radian_per_second, degree_per_second, revolution_per_second, revolution_per_minute
|
AngularAcceleration ¹ |
angular_acceleration |
radian_per_second_squared, degree_per_second_squared, revolution_per_minute_per_second
|
AngularJerk ¹ |
angular_jerk |
radian_per_second_cubed, degree_per_second_cubed, revolution_per_minute_per_second_squared
|
ElectricPotential |
electric_potential |
millivolt, centivolt, volt
|
Power |
power |
milliwatt, watt, kilowatt
|
Energy |
energy |
joule, watt_hour, kilowatt_hour
|
Frequency |
frequency |
millihertz, centihertz, hertz, cycle_per_minute
|
Pressure |
pressure |
pascal, bar
|
VolumeRate |
volume_rate |
cubic_meter_per_second, liter_per_second, liter_per_minute
|
Ratio |
ratio |
ratio |
¹ The angular quantities have the kind dyn AngleKind. They are dimensionless like Ratio, but the
kind keeps them from being mixed with plain ratios or frequencies by accident.
-
New unit for an existing quantity: add an
@unit_name: factor; "symbol", "singular", "plural";line to theunits { … }block in that quantity's file, for examplesrc/volume_rate.rs.factorconverts to the base SI unit. -
New quantity:
- Create
src/<quantity>.rswith aquantity! { … }block that gives its ISQ dimension exponents. Copy an existing file. - Register it in the
units: U { … }list ofsystem!insrc/lib.rs.
- Create
EtherCAT HAL
EtherCAT Devices
XTREM
Other crates