Crate rrtk

Source
Expand description

§Rust Robotics ToolKit

A set of algorithms and other tools for robotics in Rust.

It is almost entirely no_std and most things work without alloc. It does not currently integrate with any API directly. This may be added in the future, probably through another crate.

§Feature Flags

  • alloc - Enable items requiring dynamic allocation through Rust’s builtin alloc crate.
  • std - Enable items requiring the Rust standard library. Requires alloc feature. Enabled by default.
  • devices - Enable RRTK’s graph-based device system.
  • dim_check_debug - Enable dimension checking in debug mode. Enabled by default.
  • dim_check_release - Enable dimension checking in both debug mode and release mode. Requires dim_check_debug feature.
  • libm - Use libm for float exponentiation when std is not available.
  • micromath - Use micromath for float exponentiation when std and libm are unavailable.
  • internal_enhanced_float - Do not enable this yourself.

RRTK prefers std over libm and libm over micromath when multiple are available.

Re-exports§

pub use dimensions::*;

Modules§

compile_time_dimensions
RRTK’s compile-time dimensional analysis system. This system is simpler than ones like uom, but it serves a similar purpose: to protect users from dimension mismatch errors at compile time without runtime overhead. This is done through a semi-hack representing integers as types and adding type parameters to a special struct called Quantity, which is a transparent struct holding only a value at runtime.
compile_time_integer
RRTK’s compile-time integer system. This is basically a simpler version of Typenum. It is used for compile-time dimensional analysis. 0 is represented by the Zero struct. Positive integers are created by wrapping Zero with with OnePlus a given number of times, e.g., 2 is represented by OnePlus<OnePlus<Zero>>. Negative numbers are created similarly but with NegativeOnePlus instead of OnePlus: -2 is NegativeOnePlus<NegativeOnePlus<Zero>>. You should be able to read a number’s type left-to-right and get a mathematical expression that will evaluate to the number. Using both OnePlus and NegativeOnePlus in the same number is discouraged, e.g., using NegativeOnePlus<OnePlus<Zero>> for 0.
devices
RRTK’s device system works through a graph-like structure where each device holds objects called terminals in RefCells. Terminals represent anywhere that a device can connect to another. Connected terminals hold references to eachother’s RefCells. This module holds builtin devices.
dimensions
This module contains types related to RRTK’s dimensional analysis system. RRTK uses nanoseconds for time because they typically work nicely with computer clocks and are still precise when stored in an integer, which is important because exponentially losing precision for time is bad, and float time does that. However, floats are used for other quantities, including quantities derived from time. These use seconds instead because numbers of the magnitude of nanoseconds cause floats to lose precision. RRTK should handle the conversion mostly seamlessly for you, but keep it in mind when thinking about how time-related types should work. The reasoning behind this unorthodox system using both nanoseconds and seconds becomes more apparent when you know how floating point numbers work. Everything in this module is reexported at the crate level.
error
Error types used for various things in RRTK. Currently they are only zero-sized types, but this may change.
streams
Getters that do data processing and have other getters as inputs are called streams. These are some helpful builtin streams for controlling your robot. See the pid example to learn more about how to use the stream system.

Macros§

div
Gets the resulting type from dividing quantities of two types. Basically an alias for <$a as Div<$b>>::Output. This is an important thing to be able to do when writing code that is generic over units as, since quantities of different units are technically different types, the fully qualified syntax gets unwieldy quickly when performing multiplication and division. Rust’s scoping rules for macros is a bit odd, but you should be able to use rrtk::div! and rrtk::compile_time_dimensions::div! interchangably.
mul
Gets the resulting type from multiplying quantities of two types. Basically an alias for <$a as Mul<$b>>::Output. This is an important thing to be able to do when writing code that is generic over units as, since quantities of different units are technically different types, the fully qualified syntax gets unwieldy quickly when performing multiplication and division. Rust’s scoping rules for macros is a bit odd, but you should be able to use rrtk::mul! and rrtk::compile_time_dimensions::mul! interchangably.

Structs§

ConstantGetter
Getter for returning a constant value.
Datum
A container for a time and something else, usually an f32 or a State.
Feeder
Feeds the output of a Getter into a Settable.
GetterFromChronology
As histories return values at times, we can ask them to return values at the time of now or now with a delta. This makes that much easier and is the recommended way of following MotionProfiles.
MotionProfile
A motion profile for getting from one state to another.
NoneGetter
Getter always returning Ok(None).
PIDKValues
Coefficients for a PID controller.
PointerDereferencer
Updatable, Getter, Settable, and TimeGetter are passed through Box, Rc<RefCell<T>>, Arc<RwLock<T>>, and Arc<Mutex<T>>, but this cannot be done safely for references involving raw pointer dereferencing. This is a wrapper struct that provides this functionality for *mut T, *const RwLock<T>, and *const Mutex<T>. It’s constructor is unsafe fn, so this is considered sound.
PositionDerivativeDependentPIDKValues
A set of PID k-values for controlling each position derivative.
State
A one-dimensional motion state with position, velocity, and acceleration.
Terminal
A place where a device can connect to another.
TerminalData
Data that are sent between terminals: A timestamp, an optional command, and a state.
TimeGetterFromGetter
Because Getters always return a timestamp (as long as they don’t return Err(_) or Ok(None)), we can use this to treat them like TimeGetters.

Enums§

Command
A command for a motor to perform: go to a position, run at a velocity, or accelerate at a rate.
MotionProfilePiece
Where you are in following a motion profile.
PositionDerivative
A derivative of position: position, velocity, or acceleration.

Traits§

Chronology
An object that can return a value, like a Getter, for a given time.
Device
A mechanical device.
Getter
Something with a get method. Structs implementing this will often be chained for easier data processing, with a struct having other implementors in fields which will have some operation performed on their output before it being passed on. Data processing Getters with other Getters as fields can be referred to as streams, though this is only in naming and trait-wise there is no distinction. The other common use for this trait is encoders. These should not be called streams.
NotDatum
Really hacky specialization workaround. Implement for any type that is not Datum itself including types using Datum as a type parameter or associated type.
OptionDatumExt
Extension trait for Option<Datum<T>>.
Settable
Something with a set method. Usually used for motors and other mechanical components and systems. This trait too is fairly broad.
TimeGetter
An object for getting the absolute time.
Updatable
Something with an update method. Mostly for subtraiting.

Functions§

connect
Connect two terminals. Connected terminals should represent a physical connection between mechanical devices. This function will automatically disconnect the specified terminals if they are connected. You can manually disconnect terminals by calling the disconnect method on either of them.
latest
Get the newer of two Datum objects.

Type Aliases§

NothingOrError
Returned when something may return either nothing or an error.
Output
A generic output type when something may return an error, nothing, or something with a timestamp.
TimeOutput
Returned from TimeGetter objects, which may return either a time or an error.