diff --git a/.cargo/config.toml b/.cargo/config.toml index 7728f21..00dc200 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,9 +1,7 @@ -[build] -target = "./armv7a-vex-v5.json" - -[target.wasm32-unknown-unknown] -rustflags = ["-Clink-arg=--export-memory", "-Clink-arg=--import-table"] +[target.'cfg(target_os = "vexos")'] +runner = "cargo v5 run --file" +rustflags = ["-Clink-arg=-Tvexide.ld"] [unstable] -build-std = ["core", "compiler_builtins", "alloc"] +build-std = ["std", "panic_abort"] build-std-features = ["compiler-builtins-mem"] diff --git a/.vscode/settings.json b/.vscode/settings.json index c56ae3a..830a4bd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,6 @@ { "rust-analyzer.check.targets": [ - "${workspaceFolder}/armv7a-vex-v5.json", - "wasm32-unknown-unknown" + "armv7a-vex-v5" ], "rust-analyzer.check.allTargets": false, "rust-analyzer.cargo.features": "all", diff --git a/Cargo.lock b/Cargo.lock index 814fcf6..e110594 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,17 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "async-lock" +version = "3.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fd03604047cee9b6ce9de9f70c6cd540a0520c813cbd49bae61f33ab80ed1dc" +dependencies = [ + "event-listener", + "event-listener-strategy", + "pin-project-lite", +] + [[package]] name = "async-task" version = "4.7.1" @@ -40,6 +51,21 @@ dependencies = [ "time", ] +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + [[package]] name = "deranged" version = "0.4.0" @@ -49,6 +75,27 @@ dependencies = [ "powerfmt", ] +[[package]] +name = "event-listener" +version = "5.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13b66accf52311f30a0db42147dadea9850cb48cd070028831ae5f5d4b856ab" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + +[[package]] +name = "event-listener-strategy" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8be9f3dfaaffdae2972880079a491a1a8bb7cbed0b8dd7a347f668b4150a3b93" +dependencies = [ + "event-listener", + "pin-project-lite", +] + [[package]] name = "evian" version = "0.3.0-rc.1" @@ -81,6 +128,7 @@ dependencies = [ name = "evian-math" version = "0.0.1-rc.1" dependencies = [ + "num-traits", "vexide", ] @@ -108,6 +156,7 @@ name = "examples" version = "0.0.1" dependencies = [ "evian", + "num-traits", "vexide", ] @@ -131,9 +180,9 @@ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" [[package]] name = "libm" -version = "0.2.11" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" +checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" [[package]] name = "lock_api" @@ -145,39 +194,39 @@ dependencies = [ "scopeguard", ] -[[package]] -name = "memchr" -version = "2.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" - [[package]] name = "mint" version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e53debba6bda7a793e5f99b8dacf19e626084f525f7829104ba9898f367d85ff" -[[package]] -name = "no_std_io" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fa5f306a6f2c01b4fd172f29bb46195b1764061bf926c75e96ff55df3178208" -dependencies = [ - "memchr", -] - [[package]] name = "num-conv" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + [[package]] name = "once_cell" version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +[[package]] +name = "parking" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" + [[package]] name = "pin-project" version = "1.1.6" @@ -198,6 +247,12 @@ dependencies = [ "syn", ] +[[package]] +name = "pin-project-lite" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" + [[package]] name = "powerfmt" version = "0.2.0" @@ -222,12 +277,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "replace_with" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3a8614ee435691de62bcffcf4a66d91b3594bf1428a5722e79103249a095690" - [[package]] name = "rgb" version = "0.8.50" @@ -278,6 +327,15 @@ dependencies = [ "syn", ] +[[package]] +name = "smart-leds-trait" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edeb89c73244414bb0568611690dd095b2358b3fda5bae65ad784806cca00157" +dependencies = [ + "rgb", +] + [[package]] name = "snafu" version = "0.8.5" @@ -359,8 +417,7 @@ checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "vex-libunwind" version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a93b1794031a6ec542ca31c3c19ee54a1c7ad78bad188577d75452d2f344780" +source = "git+https://github.com/vexide/vex-libunwind.git?tag=v0.1.0#6289c9d696fdff3f47e8ea093bcb035fb10f8a18" dependencies = [ "snafu", "vex-libunwind-sys", @@ -369,57 +426,64 @@ dependencies = [ [[package]] name = "vex-libunwind-sys" version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1eddc26a00312b0b53ee4df6574e4c09488c89361d3beb6f4cbe75267af32f50" +source = "git+https://github.com/vexide/vex-libunwind.git?tag=v0.1.0#6289c9d696fdff3f47e8ea093bcb035fb10f8a18" [[package]] name = "vex-sdk" -version = "0.26.0" +version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be1b586dd8546706564cf20c94bae51c8f9e4891d70360d3fb63d563350df3d1" +checksum = "79e5fe15afde1305478b35e2cb717fff59f485428534cf49cfdbfa4723379bf6" + +[[package]] +name = "vex-sdk-jumptable" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c7ce1c05cba9a1c5f6814ba05b6948cf5bdbbfbd855b36085af64b98c490dcf" +dependencies = [ + "vex-sdk", +] + +[[package]] +name = "vex-sdk-mock" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d55283baa551435a728ee5dd0bd592f99ae163fa66c952219a9ae80978b8764c" +dependencies = [ + "vex-sdk", +] [[package]] name = "vexide" version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "537cb5a5a3fc8ff54b611fcbdcb9fb66f0d5e7d96746c5c91d212a09d48bda97" +source = "git+https://github.com/vexide/vexide.git?branch=refactor%2Fupstreamed-target%2Brust-std#52e5993410ac28ff3595a121f8b1b421efee0442" dependencies = [ "vex-sdk", "vexide-async", "vexide-core", "vexide-devices", "vexide-macro", - "vexide-panic", "vexide-startup", ] [[package]] name = "vexide-async" version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f18212c1cf2587633f8189e671875ee7cd4a6bff57aa15bfe43f722c6b78363" +source = "git+https://github.com/vexide/vexide.git?branch=refactor%2Fupstreamed-target%2Brust-std#52e5993410ac28ff3595a121f8b1b421efee0442" dependencies = [ + "async-lock", "async-task", "vex-sdk", - "vexide-core", "waker-fn", ] [[package]] name = "vexide-core" version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b286389834deb4db81e0775a352465f2d2a84d15c5a3d1991bb5cd03c2e6a482" +source = "git+https://github.com/vexide/vexide.git?branch=refactor%2Fupstreamed-target%2Brust-std#52e5993410ac28ff3595a121f8b1b421efee0442" dependencies = [ "bitflags", "futures-core", - "libm", - "lock_api", - "no_std_io", "pin-project", - "replace_with", - "snafu", - "talc", "vex-libunwind", "vex-sdk", ] @@ -427,13 +491,13 @@ dependencies = [ [[package]] name = "vexide-devices" version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1efe5b3781a08e3c598ba0072af1a780f3c1db8293e32793084c8ff8459506d9" +source = "git+https://github.com/vexide/vexide.git?branch=refactor%2Fupstreamed-target%2Brust-std#52e5993410ac28ff3595a121f8b1b421efee0442" dependencies = [ "bitflags", + "libm", "mint", - "no_std_io", "rgb", + "smart-leds-trait", "snafu", "vex-sdk", "vexide-core", @@ -442,36 +506,26 @@ dependencies = [ [[package]] name = "vexide-macro" version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e9ddc4a9da4ff280e16026a20180b760587df18edc4f90dd8616aca2b591da" +source = "git+https://github.com/vexide/vexide.git?branch=refactor%2Fupstreamed-target%2Brust-std#52e5993410ac28ff3595a121f8b1b421efee0442" dependencies = [ "proc-macro2", "quote", "syn", ] -[[package]] -name = "vexide-panic" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5af737b3258416d4c1da69f4977e70d00c15d6115af480614b87a22f3896664b" -dependencies = [ - "snafu", - "vex-sdk", - "vexide-core", - "vexide-devices", -] - [[package]] name = "vexide-startup" version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7092780a3eff1b3359bef8d1f4163e81df8d3614c8dc784809730a0e8ca42f3f" +source = "git+https://github.com/vexide/vexide.git?branch=refactor%2Fupstreamed-target%2Brust-std#52e5993410ac28ff3595a121f8b1b421efee0442" dependencies = [ "bitflags", "compile-time", + "talc", "vex-sdk", + "vex-sdk-jumptable", + "vex-sdk-mock", "vexide-core", + "vexide-devices", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index ca3d9b3..a8b31f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,11 @@ icon = "cool-x" compress = true [dev-dependencies] -vexide = "0.7.0" +vexide = { git = "https://github.com/vexide/vexide.git", branch = "refactor/upstreamed-target+rust-std", features = [ + "full", + "vex-sdk-jumptable", + "vex-sdk-mock", +] } evian = { path = "packages/evian" } [workspace] @@ -18,11 +22,7 @@ members = ["packages/*"] resolver = "2" [workspace.dependencies] -vexide = { version = "0.7.0", default-features = false, features = [ - "async", - "core", - "devices", -] } +vexide = { git = "https://github.com/vexide/vexide.git", branch = "refactor/upstreamed-target+rust-std" } evian = { version = "0.3.0-rc.1", path = "packages/evian", default-features = false } evian-control = { version = "0.0.1-rc.1", path = "packages/evian-control", default-features = false } evian-drivetrain = { version = "0.0.1-rc.1", path = "packages/evian-drivetrain", default-features = false } @@ -46,6 +46,9 @@ missing_panics_doc = "allow" cast_possible_wrap = "allow" match_bool = "allow" +[dependencies] +num-traits = "0.2.19" + [workspace.lints.rust] rust_2018_idioms = { level = "warn", priority = -1 } rust_2024_compatibility = { level = "warn", priority = -1 } @@ -55,4 +58,4 @@ missing_docs = "warn" unsafe_op_in_unsafe_fn = "deny" unexpected_cfgs = { level = "warn", check-cfg = [ 'cfg(target_vendor, values("vex"))', -] } \ No newline at end of file +] } diff --git a/armv7a-vex-v5.json b/armv7a-vex-v5.json deleted file mode 100644 index daf13f6..0000000 --- a/armv7a-vex-v5.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "cpu": "cortex-a9", - "arch": "arm", - "abi": "eabihf", - "os": "none", - "vendor": "vex", - "env": "v5", - "panic-strategy": "abort", - "relocation-model": "static", - "llvm-floatabi": "hard", - "llvm-target": "armv7a-none-eabihf", - "features": "+v7,+neon,+vfp3d16,+thumb2", - "linker": "rust-lld", - "linker-flavor": "ld.lld", - "data-layout": "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64", - "max-atomic-width": 64, - "c-enum-min-bits": 8, - "target-pointer-width": "32", - "executables": true, - "post-link-args": { - "ld.lld": ["-Tv5.ld"] - }, - "has-thumb-interworking": true, - "default-uwtable": true, - "disable-redzone": true, - "emit-debug-gdb-scripts": false -} diff --git a/examples/basic.rs b/examples/basic.rs index b3bef86..6ae9e2f 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -1,13 +1,9 @@ -#![no_main] -#![no_std] - -extern crate alloc; - use vexide::prelude::*; -use core::time::Duration; +use std::time::Duration; use evian::{ control::loops::{AngularPid, Pid}, + drivetrain::model::Differential, motion::{Basic, Seeking}, prelude::*, }; @@ -25,18 +21,18 @@ const ANGULAR_TOLERANCES: Tolerances = Tolerances::new() struct Robot { drivetrain: Drivetrain, + controller: Controller, } impl Compete for Robot { async fn autonomous(&mut self) { let dt = &mut self.drivetrain; let mut seeking = Seeking { - linear_controller: LINEAR_PID, - angular_controller: ANGULAR_PID, + linear_controller: Pid::new(0.0, 0.0, 0.0, None), + lateral_controller: Pid::new(0.0, 0.0, 0.0, None), tolerances: LINEAR_TOLERANCES, timeout: Some(Duration::from_secs(10)), }; - let mut basic = Basic { linear_controller: LINEAR_PID, angular_controller: ANGULAR_PID, @@ -66,43 +62,67 @@ impl Compete for Robot { .with_linear_error_tolerance(12.0) .await; } + + async fn driver(&mut self) { + loop { + let state = self.controller.state().unwrap_or_default(); + + _ = self + .drivetrain + .model + .drive_arcade(state.left_stick.y(), state.left_stick.x()); + println!("{}", self.drivetrain.tracking.position()); + + sleep(Duration::from_millis(50)).await; + } + } } #[vexide::main] async fn main(peripherals: Peripherals) { - let left_motors = shared_motors![ - Motor::new(peripherals.port_11, Gearset::Blue, Direction::Forward), - Motor::new(peripherals.port_12, Gearset::Blue, Direction::Reverse), - Motor::new(peripherals.port_13, Gearset::Blue, Direction::Forward), - ]; - let right_motors = shared_motors![ - Motor::new(peripherals.port_17, Gearset::Blue, Direction::Forward), - Motor::new(peripherals.port_18, Gearset::Blue, Direction::Reverse), - Motor::new(peripherals.port_19, Gearset::Blue, Direction::Forward), - ]; - - let mut basic = Basic { - linear_controller: LINEAR_PID, - angular_controller: ANGULAR_PID, - linear_tolerances: LINEAR_TOLERANCES, - angular_tolerances: ANGULAR_TOLERANCES, - timeout: Some(Duration::from_secs(10)), - }; + let forwards_enc = AdiOpticalEncoder::new(peripherals.adi_a, peripherals.adi_b); + let sideways_enc = AdiOpticalEncoder::new(peripherals.adi_c, peripherals.adi_d); + + let mut imu = InertialSensor::new(peripherals.port_15); + imu.calibrate().await.unwrap(); let mut drivetrain = Drivetrain::new( - Differential::from_shared(left_motors.clone(), right_motors.clone()), - WheeledTracking::forward_only( - Vec2::default(), - 90.0.deg(), + Differential::new( + [ + Motor::new(peripherals.port_7, Gearset::Blue, Direction::Forward), + Motor::new(peripherals.port_8, Gearset::Blue, Direction::Reverse), + Motor::new(peripherals.port_9, Gearset::Blue, Direction::Reverse), + Motor::new(peripherals.port_10, Gearset::Blue, Direction::Forward), + ], [ - TrackingWheel::new(left_motors, 2.75, -5.75, None), - TrackingWheel::new(right_motors, 2.75, 5.25, None), + Motor::new(peripherals.port_17, Gearset::Blue, Direction::Reverse), + Motor::new(peripherals.port_18, Gearset::Blue, Direction::Reverse), + Motor::new(peripherals.port_19, Gearset::Blue, Direction::Forward), + Motor::new(peripherals.port_20, Gearset::Blue, Direction::Forward), ], - None, + ), + WheeledTracking::new( + Vec2::default(), + 90.0.deg(), + [TrackingWheel::new(forwards_enc, 2.0, 0.0, None)], + [TrackingWheel::new(sideways_enc, 2.0, 0.0, None)], + Some(imu), ), ); - basic.turn_to_heading(&mut drivetrain, 0.0.deg()).await; + let mut seeking = Seeking { + linear_controller: Pid::new(0.08, 0.0, 0.0125, None), + lateral_controller: Pid::new(0.05, 0.0, 0.0, None), + tolerances: LINEAR_TOLERANCES, + timeout: Some(Duration::from_secs(10)), + }; - Robot { drivetrain }.compete().await; + seeking.move_to_point(&mut drivetrain, (-6.0, 6.0)).await; + + Robot { + drivetrain, + controller: peripherals.primary_controller, + } + .compete() + .await; } diff --git a/packages/evian-control/Cargo.toml b/packages/evian-control/Cargo.toml index 437a00e..d49372c 100644 --- a/packages/evian-control/Cargo.toml +++ b/packages/evian-control/Cargo.toml @@ -17,4 +17,8 @@ evian-math = { workspace = true } workspace = true [package.metadata.docs.rs] -targets = ["armv7a-none-eabi"] \ No newline at end of file +targets = ["armv7a-vex-v5"] +cargo-args = [ + "-Zbuild-std=std,panic_abort", + "-Zbuild-std-features=compiler-builtins-mem", +] \ No newline at end of file diff --git a/packages/evian-control/src/lib.rs b/packages/evian-control/src/lib.rs index 6136d91..b1dc531 100644 --- a/packages/evian-control/src/lib.rs +++ b/packages/evian-control/src/lib.rs @@ -4,8 +4,6 @@ //! systems. These "systems" could be drivetrains, an arm or lift, or any other //! mechanism that requires precise motion control. -#![no_std] - pub mod loops; mod tolerances; diff --git a/packages/evian-control/src/loops/bang_bang.rs b/packages/evian-control/src/loops/bang_bang.rs index 64b248a..8a879b4 100644 --- a/packages/evian-control/src/loops/bang_bang.rs +++ b/packages/evian-control/src/loops/bang_bang.rs @@ -1,4 +1,4 @@ -use core::time::Duration; +use std::time::Duration; use crate::loops::ControlLoop; diff --git a/packages/evian-control/src/loops/cascade.rs b/packages/evian-control/src/loops/cascade.rs index 016a4d3..b40fcdd 100644 --- a/packages/evian-control/src/loops/cascade.rs +++ b/packages/evian-control/src/loops/cascade.rs @@ -1,4 +1,4 @@ -use core::time::Duration; +use std::time::Duration; use evian_math::Angle; diff --git a/packages/evian-control/src/loops/mod.rs b/packages/evian-control/src/loops/mod.rs index 9323350..4c539bd 100644 --- a/packages/evian-control/src/loops/mod.rs +++ b/packages/evian-control/src/loops/mod.rs @@ -6,7 +6,7 @@ pub mod feedforward; mod pid; mod tbh; -use core::time::Duration; +use std::time::Duration; pub use bang_bang::BangBang; pub use cascade::Cascade; diff --git a/packages/evian-control/src/loops/pid.rs b/packages/evian-control/src/loops/pid.rs index b7c01f8..40b6f5b 100644 --- a/packages/evian-control/src/loops/pid.rs +++ b/packages/evian-control/src/loops/pid.rs @@ -1,4 +1,4 @@ -use core::time::Duration; +use std::time::Duration; use evian_math::Angle; diff --git a/packages/evian-control/src/loops/tbh.rs b/packages/evian-control/src/loops/tbh.rs index e683e1d..a61280d 100644 --- a/packages/evian-control/src/loops/tbh.rs +++ b/packages/evian-control/src/loops/tbh.rs @@ -1,4 +1,4 @@ -use core::time::Duration; +use std::time::Duration; use crate::loops::{ControlLoop, Feedback}; diff --git a/packages/evian-control/src/tolerances.rs b/packages/evian-control/src/tolerances.rs index b4dabd3..b253f97 100644 --- a/packages/evian-control/src/tolerances.rs +++ b/packages/evian-control/src/tolerances.rs @@ -13,8 +13,7 @@ //! "settled" when it meets specified error and velocity tolerances for a given duration, after when a timeout is //! reached. -use core::time::Duration; -use vexide::time::Instant; +use std::time::{Duration, Instant}; /// Describes when a control system has stabilized reasonably near its setpoint. /// diff --git a/packages/evian-drivetrain/src/lib.rs b/packages/evian-drivetrain/src/lib.rs index ad05ff9..f9a4bfd 100644 --- a/packages/evian-drivetrain/src/lib.rs +++ b/packages/evian-drivetrain/src/lib.rs @@ -8,10 +8,6 @@ //! tracking system. The [`Drivetrain`] type can enacapsulate many different types of robot //! drivetrains depending on how its model and tracking logic is implemented. -#![no_std] - -extern crate alloc; - pub mod model; use evian_tracking::Tracking; diff --git a/packages/evian-drivetrain/src/model/differential.rs b/packages/evian-drivetrain/src/model/differential.rs index 1e628a4..a0a891e 100644 --- a/packages/evian-drivetrain/src/model/differential.rs +++ b/packages/evian-drivetrain/src/model/differential.rs @@ -1,6 +1,5 @@ -use core::cell::RefCell; +use std::{cell::RefCell, rc::Rc}; -use alloc::rc::Rc; use vexide::{devices::smart::motor::MotorError, prelude::Motor}; use super::{DrivetrainModel, Tank}; diff --git a/packages/evian-drivetrain/src/model/mecanum.rs b/packages/evian-drivetrain/src/model/mecanum.rs index e6f287e..90c3aa7 100644 --- a/packages/evian-drivetrain/src/model/mecanum.rs +++ b/packages/evian-drivetrain/src/model/mecanum.rs @@ -1,12 +1,9 @@ -use core::cell::RefCell; +use std::{cell::RefCell, rc::Rc}; -use alloc::rc::Rc; use evian_math::{Vec2, desaturate}; use vexide::{devices::smart::motor::MotorError, prelude::Motor}; -use crate::model::Tank; - -use super::{Arcade, DrivetrainModel, Holonomic}; +use super::{DrivetrainModel, Holonomic, Tank}; pub struct Mecanum { pub front_left_motors: Rc>>, diff --git a/packages/evian-drivetrain/src/model/mod.rs b/packages/evian-drivetrain/src/model/mod.rs index e26cad6..bdfdaba 100644 --- a/packages/evian-drivetrain/src/model/mod.rs +++ b/packages/evian-drivetrain/src/model/mod.rs @@ -11,8 +11,9 @@ mod mecanum; pub use differential::Differential; pub use mecanum::Mecanum; -/// A collection of motors driving a mobile robot. +/// A collection of motors driving a wheeled mobile robot. pub trait DrivetrainModel { + /// Error type returned when the robot fails to move. type Error; } diff --git a/packages/evian-math/Cargo.toml b/packages/evian-math/Cargo.toml index 02c8ba5..061de77 100644 --- a/packages/evian-math/Cargo.toml +++ b/packages/evian-math/Cargo.toml @@ -11,9 +11,14 @@ edition = "2024" [dependencies] vexide = { workspace = true } +num-traits = "0.2" [lints] workspace = true [package.metadata.docs.rs] -targets = ["armv7a-none-eabi"] \ No newline at end of file +targets = ["armv7a-vex-v5"] +cargo-args = [ + "-Zbuild-std=std,panic_abort", + "-Zbuild-std-features=compiler-builtins-mem", +] \ No newline at end of file diff --git a/packages/evian-math/src/angle.rs b/packages/evian-math/src/angle.rs index 112a9a4..6d0a418 100644 --- a/packages/evian-math/src/angle.rs +++ b/packages/evian-math/src/angle.rs @@ -1,11 +1,11 @@ -use core::{ +use std::{ f64::{ self, consts::{FRAC_PI_2, PI, TAU}, }, ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign}, }; -use vexide::{devices::position::Position, float::Float}; +use vexide::devices::position::Position; /// Angular position. #[derive(Default, Debug, Clone, Copy, PartialEq)] diff --git a/packages/evian-math/src/lib.rs b/packages/evian-math/src/lib.rs index 7fc8f47..5ea529a 100644 --- a/packages/evian-math/src/lib.rs +++ b/packages/evian-math/src/lib.rs @@ -1,7 +1,5 @@ //! Math utilities & types. -#![no_std] - mod angle; mod vec2; @@ -10,6 +8,25 @@ pub mod curve; pub use angle::{Angle, IntoAngle}; pub use vec2::Vec2; +/// Scales down the values in an array so that none exceed a given maximum magnitude. +/// +/// This function checks the element with the largest absolute value in the input array. +/// If that magnitude is greater than `max`, all elements are uniformly scaled down so +/// that the largest magnitude equals `max`. If all elements are already within the limit, +/// the array is unchanged. +/// +/// # Examples +/// +/// ``` +/// let values = [3.0, -4.0, 1.0]; +/// let result = desaturate(values, 2.0); +/// assert_eq!(result, [1.5, -2.0, 0.5]); +/// +/// // Already within bounds, so unchanged: +/// let values = [0.5, -1.2, 0.8]; +/// let result = desaturate(values, 2.0); +/// assert_eq!(result, values); +/// ``` pub fn desaturate(values: [f64; N], max: f64) -> [f64; N] { let largest_magnitude = values.iter().map(|v| v.abs()).fold(0.0, f64::max); diff --git a/packages/evian-math/src/vec2.rs b/packages/evian-math/src/vec2.rs index ad906c1..5a525d7 100644 --- a/packages/evian-math/src/vec2.rs +++ b/packages/evian-math/src/vec2.rs @@ -1,8 +1,9 @@ -use core::{ +use std::{ fmt, ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign}, }; -use vexide::{devices::math::Point2, float::Float}; +use num_traits::real::Real; +use vexide::devices::math::Point2; /// A vector in 2D cartesian space. /// @@ -47,7 +48,7 @@ impl Vec2 { } } -impl> Vec2 { +impl> Vec2 { /// Construct a `Vec2` from polar coordinates. pub fn from_polar(r: T, theta: T) -> Self { let (sin, cos) = theta.sin_cos(); @@ -61,7 +62,7 @@ impl> Vec2 { // MARK: Math -impl Vec2 { +impl Vec2 { /// Returns this vector's angle in radians relative to the origin (0, 0). pub fn angle(&self) -> T { self.y.atan2(self.x) @@ -73,7 +74,7 @@ impl Vec2 { } } -impl> Vec2 { +impl> Vec2 { /// Returns the cartesian distance between one vector and another. /// /// This operation is equivalent to `(self - other).length()`. @@ -82,7 +83,7 @@ impl> Vec2 { } } -impl> Vec2 { +impl> Vec2 { /// Returns the unit (normalized) vector. /// /// This function creates a `Vec2` with a length of 1.0 while retaining the @@ -93,13 +94,7 @@ impl> Vec2 { } } -impl + Sub + Mul> Vec2 { - /// Linearly interpolates between two vectors. - #[must_use] - pub fn lerp(self, other: Vec2, t: T) -> Vec2 { - self + ((other - self) * t) - } - +impl + Sub + Mul> Vec2 { /// Creates a new vector with its coordinates rotated by a given angle /// in radians. #[must_use] @@ -113,14 +108,22 @@ impl + Sub + Mul> Vec2 } } -impl + Sub> Vec2 { +impl + Sub + Mul> Vec2 { + /// Linearly interpolates between two vectors. + #[must_use] + pub fn lerp(self, other: Vec2, t: T) -> Vec2 { + self + ((other - self) * t) + } +} + +impl + Sub> Vec2 { /// Computes the cross product between this vector and another `Vec2`. pub fn cross(&self, other: Vec2) -> T { self.x * other.y - self.y * other.x } } -impl + Add> Vec2 { +impl + Add> Vec2 { /// Computes the dot product between this vector and another `Vec2`. /// /// The dot product is the sum of the products of each vector's components, @@ -131,7 +134,7 @@ impl + Add> Vec2 { } } -impl + Add + Div> Vec2 { +impl + Add + Div> Vec2 { /// Projects one `Vec2` onto onto another. #[must_use] pub fn projected(&self, onto: Vec2) -> Self { diff --git a/packages/evian-motion/Cargo.toml b/packages/evian-motion/Cargo.toml index ab35c68..a5a11e8 100644 --- a/packages/evian-motion/Cargo.toml +++ b/packages/evian-motion/Cargo.toml @@ -20,4 +20,8 @@ evian-tracking = { workspace = true } workspace = true [package.metadata.docs.rs] -targets = ["armv7a-none-eabi"] \ No newline at end of file +targets = ["armv7a-vex-v5"] +cargo-args = [ + "-Zbuild-std=std,panic_abort", + "-Zbuild-std-features=compiler-builtins-mem", +] \ No newline at end of file diff --git a/packages/evian-motion/src/basic/distance_at_heading.rs b/packages/evian-motion/src/basic/distance_at_heading.rs index dd97a7d..3cd2fcc 100644 --- a/packages/evian-motion/src/basic/distance_at_heading.rs +++ b/packages/evian-motion/src/basic/distance_at_heading.rs @@ -1,11 +1,11 @@ -use core::{ +use std::{ future::Future, pin::Pin, task::{Context, Poll}, - time::Duration, + time::{Duration, Instant}, }; -use vexide::time::{Instant, Sleep, sleep}; +use vexide::time::{Sleep, sleep}; use evian_control::{ Tolerances, diff --git a/packages/evian-motion/src/basic/mod.rs b/packages/evian-motion/src/basic/mod.rs index bac18dc..e4fb959 100644 --- a/packages/evian-motion/src/basic/mod.rs +++ b/packages/evian-motion/src/basic/mod.rs @@ -1,6 +1,6 @@ //! Feedback-driven driving and turning. -use core::time::Duration; +use std::time::Duration; use evian_control::{Tolerances, loops::Feedback}; use evian_drivetrain::{Drivetrain, model::Arcade}; diff --git a/packages/evian-motion/src/basic/turn_to_point.rs b/packages/evian-motion/src/basic/turn_to_point.rs index 2053ae3..7f157f9 100644 --- a/packages/evian-motion/src/basic/turn_to_point.rs +++ b/packages/evian-motion/src/basic/turn_to_point.rs @@ -1,11 +1,11 @@ -use core::{ +use std::{ future::Future, pin::Pin, task::{Context, Poll}, - time::Duration, + time::{Duration, Instant}, }; -use vexide::time::{Instant, Sleep, sleep}; +use vexide::time::{Sleep, sleep}; use evian_control::{ Tolerances, diff --git a/packages/evian-motion/src/curvature.rs b/packages/evian-motion/src/curvature.rs index a6d5bab..18e35ce 100644 --- a/packages/evian-motion/src/curvature.rs +++ b/packages/evian-motion/src/curvature.rs @@ -1,6 +1,5 @@ -use core::f64::consts::FRAC_PI_2; +use std::f64::consts::FRAC_PI_2; use evian_tracking::Tracking; -use vexide::float::Float; use evian_drivetrain::{Drivetrain, model::Arcade}; diff --git a/packages/evian-motion/src/lib.rs b/packages/evian-motion/src/lib.rs index 538c8ec..3ee3ad6 100644 --- a/packages/evian-motion/src/lib.rs +++ b/packages/evian-motion/src/lib.rs @@ -1,7 +1,5 @@ //! Motion control algorithms. -#![no_std] - mod curvature; pub mod basic; diff --git a/packages/evian-motion/src/pursuit/follow.rs b/packages/evian-motion/src/pursuit/follow.rs index 8f87bed..a4a15f0 100644 --- a/packages/evian-motion/src/pursuit/follow.rs +++ b/packages/evian-motion/src/pursuit/follow.rs @@ -1,7 +1,7 @@ -use core::{ +use std::{ pin::Pin, task::{Context, Poll}, - time::Duration, + time::{Duration, Instant}, }; use evian_drivetrain::{Drivetrain, model::Tank}; @@ -9,8 +9,7 @@ use evian_math::{Angle, Vec2}; use evian_tracking::{TracksHeading, TracksPosition}; use vexide::{ - float::Float, - time::{Instant, Sleep, sleep}, + time::{Sleep, sleep}, }; use super::Waypoint; diff --git a/packages/evian-motion/src/pursuit/mod.rs b/packages/evian-motion/src/pursuit/mod.rs index 77bcf76..d8c2dc2 100644 --- a/packages/evian-motion/src/pursuit/mod.rs +++ b/packages/evian-motion/src/pursuit/mod.rs @@ -2,7 +2,7 @@ extern crate alloc; -use core::time::Duration; +use std::time::Duration; use alloc::vec::Vec; use evian_drivetrain::{Drivetrain, model::Tank}; diff --git a/packages/evian-motion/src/seeking/boomerang.rs b/packages/evian-motion/src/seeking/boomerang.rs index 8c918c8..eb2c796 100644 --- a/packages/evian-motion/src/seeking/boomerang.rs +++ b/packages/evian-motion/src/seeking/boomerang.rs @@ -1,6 +1,6 @@ -use core::{future::Future, pin::Pin, task::Poll, time::Duration}; +use std::{future::Future, pin::Pin, task::Poll, time::{Duration, Instant}}; -use vexide::time::{Instant, Sleep, sleep}; +use vexide::time::{Sleep, sleep}; use evian_control::{ Tolerances, @@ -166,7 +166,7 @@ where } /// Removes this motion's error tolerance. - pub const fn withear_error_tolerance(&mut self) -> &mut Self { + pub const fn without_error_tolerance(&mut self) -> &mut Self { self.tolerances.error_tolerance = None; self } @@ -178,7 +178,7 @@ where } /// Removes this motion's velocity tolerance. - pub const fn withear_velocity_tolerance(&mut self) -> &mut Self { + pub const fn without_velocity_tolerance(&mut self) -> &mut Self { self.tolerances.velocity_tolerance = None; self } @@ -190,7 +190,7 @@ where } /// Removes this motion's tolerance duration. - pub const fn withear_tolerance_duration(&mut self) -> &mut Self { + pub const fn without_tolerance_duration(&mut self) -> &mut Self { self.tolerances.duration = None; self } diff --git a/packages/evian-motion/src/seeking/mod.rs b/packages/evian-motion/src/seeking/mod.rs index 9d3f638..e60e388 100644 --- a/packages/evian-motion/src/seeking/mod.rs +++ b/packages/evian-motion/src/seeking/mod.rs @@ -1,13 +1,10 @@ //! Point-to-point feedback seeking. -use core::time::Duration; +use std::time::Duration; use evian_control::{Tolerances, loops::Feedback}; -use evian_drivetrain::{ - Drivetrain, - model::{Arcade, Differential}, -}; -use evian_math::{Angle, Vec2}; +use evian_drivetrain::{Drivetrain, model::Arcade}; +use evian_math::Vec2; use evian_tracking::{TracksHeading, TracksPosition, TracksVelocity}; mod boomerang; @@ -29,13 +26,13 @@ pub use move_to_point::MoveToPointFuture; pub struct Seeking where L: Feedback + Unpin + Clone, - A: Feedback + Unpin + Clone, + A: Feedback + Unpin + Clone, { - /// Linear (forward driving) feedback controller. + /// Linear (forward) feedback controller. pub linear_controller: L, - /// Angular (turning) feedback controller. - pub angular_controller: A, + /// Angular (cross-track) feedback controller. + pub lateral_controller: A, /// Linear settling conditions. /// @@ -50,7 +47,7 @@ where impl Seeking where L: Feedback + Unpin + Clone, - A: Feedback + Unpin + Clone, + A: Feedback + Unpin + Clone, { /// Moves the robot to a 2D point. /// @@ -68,35 +65,35 @@ where timeout: self.timeout, tolerances: self.tolerances, linear_controller: self.linear_controller.clone(), - angular_controller: self.angular_controller.clone(), + lateral_controller: self.lateral_controller.clone(), state: None, } } - /// Moves the robot to a desired pose (position and heading). - /// - /// This motion uses a boomerang controller, which is a motion algorithm - /// for moving differential drivetrains to a desired pose. Larger `lead` - /// values will result in wider arcs, while smaller `lead` values will - /// result in smaller arcs. You may need to tune the `lead` value in order - /// to properly reach the desired heading by the end of the motion. - pub fn boomerang<'a, M: Arcade, T: TracksPosition + TracksHeading + TracksVelocity>( - &mut self, - drivetrain: &'a mut Drivetrain, - point: impl Into>, - heading: Angle, - lead: f64, - ) -> BoomerangFuture<'a, M, L, A, T> { - BoomerangFuture { - drivetrain, - target_heading: heading, - lead, - target_point: point.into(), - timeout: self.timeout, - tolerances: self.tolerances, - linear_controller: self.linear_controller.clone(), - angular_controller: self.angular_controller.clone(), - state: None, - } - } + // /// Moves the robot to a desired pose (position and heading). + // /// + // /// This motion uses a boomerang controller, which is a motion algorithm + // /// for moving differential drivetrains to a desired pose. Larger `lead` + // /// values will result in wider arcs, while smaller `lead` values will + // /// result in smaller arcs. You may need to tune the `lead` value in order + // /// to properly reach the desired heading by the end of the motion. + // pub fn boomerang<'a, M: Arcade, T: TracksPosition + TracksHeading + TracksVelocity>( + // &mut self, + // drivetrain: &'a mut Drivetrain, + // point: impl Into>, + // heading: Angle, + // lead: f64, + // ) -> BoomerangFuture<'a, M, L, A, T> { + // BoomerangFuture { + // drivetrain, + // target_heading: heading, + // lead, + // target_point: point.into(), + // timeout: self.timeout, + // tolerances: self.tolerances, + // linear_controller: self.linear_controller.clone(), + // angular_controller: self.angular_controller.clone(), + // state: None, + // } + // } } diff --git a/packages/evian-motion/src/seeking/move_to_point.rs b/packages/evian-motion/src/seeking/move_to_point.rs index e85dcf2..8708e4f 100644 --- a/packages/evian-motion/src/seeking/move_to_point.rs +++ b/packages/evian-motion/src/seeking/move_to_point.rs @@ -1,18 +1,23 @@ -use core::{f64::consts::PI, future::Future, pin::Pin, task::Poll, time::Duration}; +use std::{ + f64::consts::FRAC_PI_2, + future::Future, + pin::Pin, + task::Poll, + time::{Duration, Instant}, +}; -use vexide::time::{Instant, Sleep, sleep}; +use vexide::time::{Sleep, sleep}; use evian_control::{ Tolerances, - loops::{AngularPid, Feedback, Pid}, + loops::{Feedback, Pid}, }; use evian_drivetrain::{Drivetrain, model::Arcade}; -use evian_math::{Angle, IntoAngle, Vec2}; +use evian_math::{IntoAngle, Vec2}; use evian_tracking::{TracksHeading, TracksPosition, TracksVelocity}; pub(crate) struct State { sleep: Sleep, - close: bool, prev_time: Instant, start_time: Instant, } @@ -23,7 +28,7 @@ pub struct MoveToPointFuture<'a, M, L, A, T> where M: Arcade, L: Feedback + Unpin, - A: Feedback + Unpin, + A: Feedback + Unpin, T: TracksPosition + TracksHeading + TracksVelocity, { pub(crate) target_point: Vec2, @@ -31,7 +36,7 @@ where pub(crate) timeout: Option, pub(crate) tolerances: Tolerances, pub(crate) linear_controller: L, - pub(crate) angular_controller: A, + pub(crate) lateral_controller: A, pub(crate) drivetrain: &'a mut Drivetrain, pub(crate) state: Option, } @@ -42,7 +47,7 @@ impl Future for MoveToPointFuture<'_, M, L, A, T> where M: Arcade, L: Feedback + Unpin, - A: Feedback + Unpin, + A: Feedback + Unpin, T: TracksPosition + TracksHeading + TracksVelocity, { type Output = (); @@ -59,7 +64,6 @@ where sleep: sleep(Duration::from_millis(5)), start_time: now, prev_time: now, - close: false, } }); @@ -73,20 +77,8 @@ where let heading = this.drivetrain.tracking.heading(); let local_target = this.target_point - position; - let mut distance_error = local_target.length(); - if distance_error.abs() < 7.5 && !state.close { - state.close = true; - } - - let mut angle_error = (heading - local_target.angle().rad()).wrapped(); - - if this.reverse { - distance_error *= -1.0; - angle_error = (PI.rad() - angle_error).wrapped(); - } - if this .tolerances .check(distance_error, this.drivetrain.tracking.linear_velocity()) @@ -94,23 +86,26 @@ where .timeout .is_some_and(|timeout| state.start_time.elapsed() > timeout) { - _ = this.drivetrain.model.drive_arcade(0.0, 0.0); + drop(this.drivetrain.model.drive_arcade(0.0, 0.0)); return Poll::Ready(()); } - let angular_output = if state.close { - 0.0 - } else { - this.angular_controller - .update(-angle_error, Angle::ZERO, dt) - }; - let linear_output = - this.linear_controller.update(-distance_error, 0.0, dt) * angle_error.cos(); + let angle_error = (heading - local_target.angle().rad()).wrapped(); + let mut projected_cte = distance_error * angle_error.sin(); + + if angle_error.as_radians().abs() > FRAC_PI_2 { + projected_cte *= -1.0; + distance_error *= -1.0; + } + + let angular_output = this.lateral_controller.update(projected_cte, 0.0, dt); + let linear_output = this.linear_controller.update(-distance_error, 0.0, dt); - _ = this - .drivetrain - .model - .drive_arcade(linear_output, angular_output); + drop( + this.drivetrain + .model + .drive_arcade(linear_output, angular_output), + ); state.sleep = sleep(Duration::from_millis(5)); state.prev_time = Instant::now(); @@ -126,7 +121,7 @@ impl MoveToPointFuture<'_, M, L, A, T> where M: Arcade, L: Feedback + Unpin, - A: Feedback + Unpin, + A: Feedback + Unpin, T: TracksPosition + TracksHeading + TracksVelocity, { /// Reverses this motion, moving to the point backwards rather than forwards. @@ -141,9 +136,9 @@ where self } - /// Modifies this motion's angular feedback controller. - pub fn with_angular_controller(&mut self, controller: A) -> &mut Self { - self.angular_controller = controller; + /// Modifies this motion's lateral feedback controller. + pub fn with_lateral_controller(&mut self, controller: A) -> &mut Self { + self.lateral_controller = controller; self } @@ -172,7 +167,7 @@ where } /// Removes this motion's error tolerance. - pub const fn withear_error_tolerance(&mut self) -> &mut Self { + pub const fn without_error_tolerance(&mut self) -> &mut Self { self.tolerances.error_tolerance = None; self } @@ -184,7 +179,7 @@ where } /// Removes this motion's velocity tolerance. - pub const fn withear_velocity_tolerance(&mut self) -> &mut Self { + pub const fn without_velocity_tolerance(&mut self) -> &mut Self { self.tolerances.velocity_tolerance = None; self } @@ -207,7 +202,7 @@ where impl MoveToPointFuture<'_, M, Pid, A, T> where M: Arcade, - A: Feedback + Unpin, + A: Feedback + Unpin, T: TracksPosition + TracksHeading + TracksVelocity, { /// Modifies this motion's linear PID gains. @@ -262,58 +257,58 @@ where // MARK: Angular PID Modifiers -impl MoveToPointFuture<'_, M, L, AngularPid, T> +impl MoveToPointFuture<'_, M, L, Pid, T> where M: Arcade, L: Feedback + Unpin, T: TracksPosition + TracksHeading + TracksVelocity, { - /// Modifies this motion's angular PID gains. - pub const fn with_angular_gains(&mut self, kp: f64, ki: f64, kd: f64) -> &mut Self { - self.angular_controller.set_gains(kp, ki, kd); + /// Modifies this motion's lateral PID gains. + pub const fn with_lateral_gains(&mut self, kp: f64, ki: f64, kd: f64) -> &mut Self { + self.lateral_controller.set_gains(kp, ki, kd); self } - /// Modifies this motion's angular proportional gain (`kp`). - pub const fn with_angular_kp(&mut self, kp: f64) -> &mut Self { - self.angular_controller.set_kp(kp); + /// Modifies this motion's lateral proportional gain (`kp`). + pub const fn with_lateral_kp(&mut self, kp: f64) -> &mut Self { + self.lateral_controller.set_kp(kp); self } - /// Modifies this motion's angular integral gain (`ki`). - pub const fn with_angular_ki(&mut self, ki: f64) -> &mut Self { - self.angular_controller.set_ki(ki); + /// Modifies this motion's lateral integral gain (`ki`). + pub const fn with_lateral_ki(&mut self, ki: f64) -> &mut Self { + self.lateral_controller.set_ki(ki); self } - /// Modifies this motion's angular derivative gain (`kd`). - pub const fn with_angular_kd(&mut self, kd: f64) -> &mut Self { - self.angular_controller.set_kd(kd); + /// Modifies this motion's lateral derivative gain (`kd`). + pub const fn with_lateral_kd(&mut self, kd: f64) -> &mut Self { + self.lateral_controller.set_kd(kd); self } - /// Modifies this motion's angular integration range. - pub const fn with_angular_integration_range(&mut self, integration_range: Angle) -> &mut Self { - self.angular_controller + /// Modifies this motion's lateral integration range. + pub const fn with_lateral_integration_range(&mut self, integration_range: f64) -> &mut Self { + self.lateral_controller .set_integration_range(Some(integration_range)); self } - /// Modifies this motion's angular output limit. - pub const fn with_angular_output_limit(&mut self, limit: f64) -> &mut Self { - self.angular_controller.set_output_limit(Some(limit)); + /// Modifies this motion's lateral output limit. + pub const fn with_lateral_output_limit(&mut self, limit: f64) -> &mut Self { + self.lateral_controller.set_output_limit(Some(limit)); self } - /// Removes this motion's angular integration range. - pub const fn without_angular_integration_range(&mut self) -> &mut Self { - self.angular_controller.set_integration_range(None); + /// Removes this motion's lateral integration range. + pub const fn without_lateral_integration_range(&mut self) -> &mut Self { + self.lateral_controller.set_integration_range(None); self } - /// Removes this motion's angular output limit. - pub const fn without_angular_output_limit(&mut self) -> &mut Self { - self.angular_controller.set_output_limit(None); + /// Removes this motion's lateral output limit. + pub const fn without_lateral_output_limit(&mut self) -> &mut Self { + self.lateral_controller.set_output_limit(None); self } } diff --git a/packages/evian-tracking/Cargo.toml b/packages/evian-tracking/Cargo.toml index 7e072c3..426242b 100644 --- a/packages/evian-tracking/Cargo.toml +++ b/packages/evian-tracking/Cargo.toml @@ -17,4 +17,8 @@ evian-math = { workspace = true } workspace = true [package.metadata.docs.rs] -targets = ["armv7a-none-eabi"] \ No newline at end of file +targets = ["armv7a-vex-v5"] +cargo-args = [ + "-Zbuild-std=std,panic_abort", + "-Zbuild-std-features=compiler-builtins-mem", +] \ No newline at end of file diff --git a/packages/evian-tracking/src/lib.rs b/packages/evian-tracking/src/lib.rs index c810620..65451db 100644 --- a/packages/evian-tracking/src/lib.rs +++ b/packages/evian-tracking/src/lib.rs @@ -41,10 +41,6 @@ //! of what units to use and keeps everything generally stable while the Rust ecosystem tries to //! figure out what typed units library to go with. -#![no_std] - -extern crate alloc; - mod sensor; pub mod wheeled; diff --git a/packages/evian-tracking/src/sensor.rs b/packages/evian-tracking/src/sensor.rs index 5d37877..5d9aa40 100644 --- a/packages/evian-tracking/src/sensor.rs +++ b/packages/evian-tracking/src/sensor.rs @@ -1,6 +1,5 @@ -use core::cell::RefCell; +use std::{cell::RefCell, rc::Rc, vec::Vec}; -use alloc::{rc::Rc, vec::Vec}; use evian_math::Angle; use vexide::{ devices::{ @@ -44,7 +43,14 @@ macro_rules! impl_rotary_sensor { impl_rotary_sensor!(Motor, position, MotorError); impl_rotary_sensor!(RotationSensor, position, PortError); -impl_rotary_sensor!(AdiEncoder, position, PortError); + +impl RotarySensor for AdiEncoder { + type Error = PortError; + + fn position(&self) -> Result { + self.position() + } +} impl RotarySensor for Vec { type Error = T::Error; diff --git a/packages/evian-tracking/src/wheeled.rs b/packages/evian-tracking/src/wheeled.rs index 3e52639..1420ec3 100644 --- a/packages/evian-tracking/src/wheeled.rs +++ b/packages/evian-tracking/src/wheeled.rs @@ -2,15 +2,15 @@ use evian_math::{Angle, IntoAngle, Vec2}; -use alloc::rc::Rc; -use core::{ +use std::{ + rc::Rc, cell::RefCell, f64::consts::{PI, TAU}, + time::Instant, }; use vexide::{ devices::smart::Motor, prelude::{Task, sleep, spawn}, - time::Instant, }; use crate::{ diff --git a/packages/evian/src/lib.rs b/packages/evian/src/lib.rs index e0da89a..e1a00db 100644 --- a/packages/evian/src/lib.rs +++ b/packages/evian/src/lib.rs @@ -123,7 +123,6 @@ //! } //! ``` -#![no_std] #![cfg_attr(docsrs, feature(doc_cfg))] #[doc(inline)]