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 builtinalloccrate.std- Enable items requiring the Rust standard library. Requiresallocfeature. 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. Requiresdim_check_debugfeature.libm- Uselibmfor float exponentiation whenstdis not available.micromath- Usemicromathfor float exponentiation whenstdandlibmare 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 calledQuantity, 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
Zerostruct. Positive integers are created by wrappingZerowith withOnePlusa given number of times, e.g., 2 is represented byOnePlus<OnePlus<Zero>>. Negative numbers are created similarly but withNegativeOnePlusinstead ofOnePlus: -2 isNegativeOnePlus<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 bothOnePlusandNegativeOnePlusin the same number is discouraged, e.g., usingNegativeOnePlus<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’sRefCells. 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
pidexample 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 userrtk::div!andrrtk::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 userrtk::mul!andrrtk::compile_time_dimensions::mul!interchangably.
Structs§
- Constant
Getter - Getter for returning a constant value.
- Datum
- A container for a time and something else, usually an
f32or aState. - Feeder
- Feeds the output of a
Getterinto aSettable. - Getter
From Chronology - 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. - Motion
Profile - A motion profile for getting from one state to another.
- None
Getter - Getter always returning
Ok(None). - PIDK
Values - Coefficients for a PID controller.
- Pointer
Dereferencer Updatable,Getter,Settable, andTimeGetterare passed throughBox,Rc<RefCell<T>>,Arc<RwLock<T>>, andArc<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 isunsafe fn, so this is considered sound.- Position
Derivative DependentPIDK Values - 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.
- Terminal
Data - Data that are sent between terminals: A timestamp, an optional command, and a state.
- Time
Getter From Getter - Because
Getters always return a timestamp (as long as they don’t returnErr(_)orOk(None)), we can use this to treat them likeTimeGetters.
Enums§
- Command
- A command for a motor to perform: go to a position, run at a velocity, or accelerate at a rate.
- Motion
Profile Piece - Where you are in following a motion profile.
- Position
Derivative - 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
getmethod. 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
Datumitself including types usingDatumas a type parameter or associated type. - Option
Datum Ext - Extension trait for
Option<Datum<T>>. - Settable
- Something with a
setmethod. Usually used for motors and other mechanical components and systems. This trait too is fairly broad. - Time
Getter - An object for getting the absolute time.
- Updatable
- Something with an
updatemethod. 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
disconnectmethod on either of them. - latest
- Get the newer of two
Datumobjects.
Type Aliases§
- Nothing
OrError - 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.
- Time
Output - Returned from
TimeGetterobjects, which may return either a time or an error.