physic

package
v3.0.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2018 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package physic declares types for physical input, outputs and measurement units.

This includes temperature, humidity, pressure, tension, current, etc.

Index

Examples

Constants

View Source
const (
	NanoMetre  Distance = 1
	MicroMetre          = 1000 * NanoMetre
	MilliMetre          = 1000 * MicroMetre
	Metre               = 1000 * MilliMetre
	KiloMetre           = 1000 * Metre
	MegaMetre           = 1000 * KiloMetre

	// Conversion between Metre and imperial units.
	Thou = 25400 * NanoMetre
	Inch = 1000 * Thou
	Foot = 12 * Inch
	Yard = 3 * Foot
	Mile = 1760 * Yard
)

Distance constants.

View Source
const (
	NanoAmpere  ElectricCurrent = 1
	MicroAmpere                 = 1000 * NanoAmpere
	MilliAmpere                 = 1000 * MicroAmpere
	Ampere                      = 1000 * MilliAmpere
)

ElectricCurrent constants.

View Source
const (
	// Volt is W/A, kg⋅m²/s³/A.
	NanoVolt  ElectricPotential = 1
	MicroVolt                   = 1000 * NanoVolt
	MilliVolt                   = 1000 * MicroVolt
	Volt                        = 1000 * MilliVolt
	KiloVolt                    = 1000 * Volt
)

ElectricPotential constants.

View Source
const (
	// Ohm is V/A, kg⋅m²/s³/A².
	NanoOhm  ElectricResistance = 1
	MicroOhm                    = 1000 * NanoOhm
	MilliOhm                    = 1000 * MicroOhm
	Ohm                         = 1000 * MilliOhm
	KiloOhm                     = 1000 * Ohm
	MegaOhm                     = 1000 * KiloOhm
)

ElectricResistance constants.

View Source
const (
	// Newton is kg⋅m/s².
	NanoNewton  Force = 1
	MicroNewton       = 1000 * NanoNewton
	MilliNewton       = 1000 * MicroNewton
	Newton            = 1000 * MilliNewton
	KiloNewton        = 1000 * Newton
	MegaNewton        = 1000 * KiloNewton

	EarthGravity = 9806650 * MicroNewton

	// Conversion between Newton and imperial units.
	// Pound is both a unit of mass and weight (force). The suffix Mass is added
	// to disambiguate the measurement it represents.
	PoundForce = 4448221615261 * NanoNewton
)

Force constants.

View Source
const (
	// Hertz is 1/s.
	MicroHertz Frequency = 1
	MilliHertz           = 1000 * MicroHertz
	Hertz                = 1000 * MilliHertz
	KiloHertz            = 1000 * Hertz
	MegaHertz            = 1000 * KiloHertz
	GigaHertz            = 1000 * MegaHertz
)

Frequency constants.

View Source
const (
	NanoGram  Mass = 1
	MicroGram      = 1000 * NanoGram
	MilliGram      = 1000 * MicroGram
	Gram           = 1000 * MilliGram
	KiloGram       = 1000 * Gram
	MegaGram       = 1000 * KiloGram
	Tonne          = MegaGram

	// Conversion between Gram and imperial units.
	// Ounce is both a unit of mass, weight (force) or volume depending on
	// context. The suffix Mass is added to disambiguate the measurement it
	// represents.
	OunceMass = 28349523125 * NanoGram
	// Pound is both a unit of mass and weight (force). The suffix Mass is added
	// to disambiguate the measurement it represents.
	PoundMass = 16 * OunceMass
	Slug      = 14593903 * MilliGram
)

Mass constants.

View Source
const (
	// Pascal is N/m², kg/m/s².
	NanoPascal  Pressure = 1
	MicroPascal          = 1000 * NanoPascal
	MilliPascal          = 1000 * MicroPascal
	Pascal               = 1000 * MilliPascal
	KiloPascal           = 1000 * Pascal
)

Pressure constants.

View Source
const (
	TenthMicroRH RelativeHumidity = 1                 // 0.00001%rH
	MicroRH                       = 10 * TenthMicroRH // 0.0001%rH
	MilliRH                       = 1000 * MicroRH    // 0.1%rH
	PercentRH                     = 10 * MilliRH      // 1%rH
)

RelativeHumidity constants.

View Source
const (
	// MetrePerSecond is m/s.
	NanoMetrePerSecond  Speed = 1
	MicroMetrePerSecond       = 1000 * NanoMetrePerSecond
	MilliMetrePerSecond       = 1000 * MicroMetrePerSecond
	MetrePerSecond            = 1000 * MilliMetrePerSecond
	KiloMetrePerSecond        = 1000 * MetrePerSecond
	MegaMetrePerSecond        = 1000 * KiloMetrePerSecond

	LightSpeed = 299792458 * MetrePerSecond

	KilometrePerHour = 3600 * MilliMetrePerSecond
	MilePerHour      = 447040 * MicroMetrePerSecond
	FootPerSecond    = 304800 * MicroMetrePerSecond
)

Speed constants.

View Source
const (
	NanoKelvin  Temperature = 1
	MicroKelvin             = 1000 * NanoKelvin
	MilliKelvin             = 1000 * MicroKelvin
	Kelvin                  = 1000 * MilliKelvin

	// Conversion between Kelvin and Celsius.
	ZeroCelsius  = 273150 * MilliKelvin
	MilliCelsius = MilliKelvin
	Celsius      = Kelvin

	// Conversion between Kelvin and Fahrenheit.
	ZeroFahrenheit  = 255372 * MilliKelvin
	MilliFahrenheit = 555555 * NanoKelvin
	Fahrenheit      = 555555555 * NanoKelvin
)

Temperature constants.

Variables

This section is empty.

Functions

This section is empty.

Types

type Distance

type Distance int64

Distance is a measurement of length stored as an int64 nano metre.

This is one of the base unit in the International System of Units.

The highest representable value is 9.2Gm.

Example
package main

import (
	"fmt"

	"periph.io/x/periph/conn/physic"
)

func main() {
	fmt.Printf("%s\n", physic.Inch)
	fmt.Printf("%s\n", physic.Foot)
	fmt.Printf("%s\n", physic.Mile)
}
Output:

25.400mm
304.800mm
1.609km

func (Distance) String

func (d Distance) String() string

String returns the distance formatted as a string in metre.

type ElectricCurrent

type ElectricCurrent int64

ElectricCurrent is a measurement of a flow of electric charge stored as an int64 nano Ampere.

This is one of the base unit in the International System of Units.

The highest representable value is 9.2GA.

Example
package main

import (
	"fmt"

	"periph.io/x/periph/conn/physic"
)

func main() {
	fmt.Printf("%s\n", 10010*physic.MilliAmpere)
	fmt.Printf("%s\n", 10*physic.Ampere)
	fmt.Printf("%s\n", -10*physic.MilliAmpere)
}
Output:

10.010A
10A
-10mA

func (ElectricCurrent) String

func (e ElectricCurrent) String() string

String returns the current formatted as a string in Ampere.

type ElectricPotential

type ElectricPotential int64

ElectricPotential is a measurement of electric potential stored as an int64 nano Volt.

The highest representable value is 9.2GV.

Example
package main

import (
	"fmt"

	"periph.io/x/periph/conn/physic"
)

func main() {
	fmt.Printf("%s\n", 10010*physic.MilliVolt)
	fmt.Printf("%s\n", 10*physic.Volt)
	fmt.Printf("%s\n", -10*physic.MilliVolt)
}
Output:

10.010V
10V
-10mV

func (ElectricPotential) String

func (e ElectricPotential) String() string

String returns the tension formatted as a string in Volt.

type ElectricResistance

type ElectricResistance int64

ElectricResistance is a measurement of the difficulty to pass an electric current through a conductor stored as an int64 nano Ohm.

The highest representable value is 9.2GΩ.

Example
package main

import (
	"fmt"

	"periph.io/x/periph/conn/physic"
)

func main() {
	fmt.Printf("%s\n", 10010*physic.MilliOhm)
	fmt.Printf("%s\n", 10*physic.Ohm)
	fmt.Printf("%s\n", 24*physic.MegaOhm)
}
Output:

10.010Ω
10Ω
24MΩ

func (ElectricResistance) String

func (e ElectricResistance) String() string

String returns the resistance formatted as a string in Ohm.

type Env

type Env struct {
	Temperature Temperature
	Pressure    Pressure
	Humidity    RelativeHumidity
}

Env represents measurements from an environmental sensor.

type Force

type Force int64

Force is a measurement of interaction that will change the motion of an object stored as an int64 nano Newton.

A measurement of Force is a vector and has a direction but this unit only represents the magnitude. The orientation needs to be stored as a Quaternion independently.

The highest representable value is 9.2TN.

Example
package main

import (
	"fmt"

	"periph.io/x/periph/conn/physic"
)

func main() {
	fmt.Printf("%s\n", 10*physic.MilliNewton)
	fmt.Printf("%s\n", 101010*physic.EarthGravity)
	fmt.Printf("%s\n", physic.PoundForce)
}
Output:

10mN
990.569kN
4.448kN

func (Force) String

func (f Force) String() string

String returns the force formatted as a string in Newton.

type Frequency

type Frequency int64

Frequency is a measurement of cycle per second, stored as an int32 micro Hertz.

The highest representable value is 9.2THz.

Example
package main

import (
	"fmt"

	"periph.io/x/periph/conn/physic"
)

func main() {
	fmt.Printf("%s\n", 10*physic.MilliHertz)
	fmt.Printf("%s\n", 101010*physic.MilliHertz)
	fmt.Printf("%s\n", 10*physic.MegaHertz)
}
Output:

10mHz
101.010Hz
10MHz

func PeriodToFrequency

func PeriodToFrequency(t time.Duration) Frequency

PeriodToFrequency returns the frequency for a period of this interval.

Example
package main

import (
	"fmt"
	"time"

	"periph.io/x/periph/conn/physic"
)

func main() {
	fmt.Printf("%s\n", physic.PeriodToFrequency(time.Microsecond))
	fmt.Printf("%s\n", physic.PeriodToFrequency(time.Minute))
}
Output:

1MHz
16.666mHz

func (Frequency) Duration

func (f Frequency) Duration() time.Duration

Duration returns the duration of one cycle at this frequency.

Example
package main

import (
	"fmt"

	"periph.io/x/periph/conn/physic"
)

func main() {
	fmt.Printf("%s\n", physic.MilliHertz.Duration())
	fmt.Printf("%s\n", physic.MegaHertz.Duration())
}
Output:

16m40s
1µs

func (Frequency) String

func (f Frequency) String() string

String returns the frequency formatted as a string in Hertz.

type Mass

type Mass int64

Mass is a measurement of mass stored as an int64 nano gram.

This is one of the base unit in the International System of Units.

The highest representable value is 9.2Gg.

Example
package main

import (
	"fmt"

	"periph.io/x/periph/conn/physic"
)

func main() {
	fmt.Printf("%s\n", 10*physic.MilliGram)
	fmt.Printf("%s\n", physic.OunceMass)
	fmt.Printf("%s\n", physic.PoundMass)
	fmt.Printf("%s\n", physic.Slug)
}
Output:

10mg
28.349g
453.592g
14.593kg

func (Mass) String

func (m Mass) String() string

String returns the mass formatted as a string in gram.

type Pressure

type Pressure int64

Pressure is a measurement of force applied to a surface per unit area (stress) stored as an int64 nano Pascal.

The highest representable value is 9.2GPa.

Example
package main

import (
	"fmt"

	"periph.io/x/periph/conn/physic"
)

func main() {
	fmt.Printf("%s\n", 101010*physic.Pascal)
	fmt.Printf("%s\n", 101*physic.KiloPascal)
}
Output:

101.010kPa
101kPa

func (Pressure) String

func (p Pressure) String() string

String returns the pressure formatted as a string in Pascal.

type RelativeHumidity

type RelativeHumidity int32

RelativeHumidity is a humidity level measurement stored as an int32 fixed point integer at a precision of 0.00001%rH.

Valid values are between 0 and 10000000.

Example
package main

import (
	"fmt"

	"periph.io/x/periph/conn/physic"
)

func main() {
	fmt.Printf("%s\n", 506*physic.MilliRH)
	fmt.Printf("%s\n", 20*physic.PercentRH)
}
Output:

50.6%rH
20%rH

func (RelativeHumidity) String

func (r RelativeHumidity) String() string

String returns the humidity formatted as a string.

type SenseEnv

type SenseEnv interface {
	conn.Resource

	// Sense returns the value read from the sensor. Unsupported metrics are not
	// modified.
	Sense(env *Env) error
	// SenseContinuous initiates a continuous sensing at the specified interval.
	//
	// It is important to call Halt() once done with the sensing, which will turn
	// the device off and will close the channel.
	SenseContinuous(interval time.Duration) (<-chan Env, error)
	// Precision returns this sensor's precision.
	//
	// The env values are set to the number of bits that are significant for each
	// items that this sensor can measure.
	//
	// Precision is not accuracy. The sensor may have absolute and relative
	// errors in its measurement, that are likely well above the reported
	// precision. Accuracy may be improved on some sensor by using oversampling,
	// or doing oversampling in software. Refer to its datasheet if available.
	Precision(env *Env)
}

SenseEnv represents an environmental sensor.

type Speed

type Speed int64

Speed is a measurement of magnitude of velocity stored as an int64 nano Metre per Second.

The highest representable value is 9.2Gm/s.

Example
package main

import (
	"fmt"

	"periph.io/x/periph/conn/physic"
)

func main() {
	fmt.Printf("%s\n", 10*physic.MilliMetrePerSecond)
	fmt.Printf("%s\n", physic.LightSpeed)
	fmt.Printf("%s\n", physic.KilometrePerHour)
	fmt.Printf("%s\n", physic.MilePerHour)
	fmt.Printf("%s\n", physic.FootPerSecond)
}
Output:

10mm/s
299.792Mm/s
3.600m/s
447.040mm/s
304.800mm/s

func (Speed) String

func (s Speed) String() string

String returns the speed formatted as a string in m/s.

type Temperature

type Temperature int64

Temperature is a measurement of hotness stored as a nano kelvin.

Negative values are invalid.

The highest representable value is 9.2GK.

Example
package main

import (
	"fmt"

	"periph.io/x/periph/conn/physic"
)

func main() {
	fmt.Printf("%s\n", 0*physic.Kelvin)
	fmt.Printf("%s\n", 23010*physic.MilliCelsius+physic.ZeroCelsius)
	fmt.Printf("%s\n", 80*physic.Fahrenheit+physic.ZeroFahrenheit)
}
Output:

-273.150°C
23.010°C
26.666°C

func (Temperature) String

func (t Temperature) String() string

String returns the temperature formatted as a string in °Celsius.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL