evian_drivetrain/lib.rs
1//! Robot drivetrain configurations.
2//!
3//! This crate provides types for describing and modeling different mobile robot drivetrain
4//! configurations. A *drivetrain* in evian is the combination of hardware components (e.g. motors,
5//! wheels, and sensors) that enables a robot to both *move* and *track its motion*. This importantly
6//! means that drivetrains are a collection of **both** motors and sensors.
7//!
8//! At the heart of this crate is the [`Drivetrain`] struct, which bundles together some motors and a
9//! *tracking system* — a system that measures something about the drivetrain as it moves around.
10//! The [`Drivetrain`] type could represent many different types of robot drivetrains depending on how
11//! the motor and tracking logic is implemented.
12//!
13//! # Supported Configurations
14//!
15//! At the moment, this crate currently provides built-in support for [differential drivetrains],
16//! however the [`Drivetrain`] struct could in theory be configured to accept any arrangement of motors
17//! with your own custom type if you require something else.
18//!
19//! [differential drivetrains]: crate::differential
20
21#![no_std]
22
23extern crate alloc;
24
25pub mod differential;
26
27/// A mobile robot drivetrain capable of measuring data about itself.
28#[derive(Default, Debug, Clone, Copy, Eq, PartialEq, Hash)]
29pub struct Drivetrain<M, T> {
30 /// Motor collection.
31 pub motors: M,
32
33 /// Tracking system.
34 pub tracking: T,
35}
36
37impl<M, T> Drivetrain<M, T> {
38 /// Creates a new drivetrain from a collection of motors and a tracking system.
39 pub const fn new(motors: M, tracking: T) -> Self {
40 Self { motors, tracking }
41 }
42}
43
44/// Creates a shared motor array.
45///
46/// This macro simplifies the creation of an `Rc<RefCell<[Motor; N]>>` array, which is a shareable
47/// wrapper around vexide's non-copyable [`Motor`](vexide::devices::smart::motor::Motor) struct.
48///
49/// # Examples
50///
51/// ```
52/// let motors = shared_motors![motor1, motor2, motor3];
53/// ```
54#[macro_export]
55macro_rules! shared_motors {
56 ( $( $item:expr ),* $(,)?) => {
57 {
58 use ::core::cell::RefCell;
59 use ::alloc::{rc::Rc, vec::Vec};
60
61 Rc::new(RefCell::new([$($item,)*]))
62 }
63 };
64}