Skip to main content

deke_types/
lib.rs

1use std::{
2    convert::Infallible,
3    fmt::{Debug, Display},
4};
5
6pub use glam;
7pub use wide;
8
9mod fk;
10mod fk_dynamic;
11mod path;
12mod q;
13mod traj;
14mod validator;
15mod validator_dynamic;
16
17pub use fk::{
18    DHChain, DHJoint, FKChain, HPChain, HPJoint, PrismaticFK, TransformedFK, URDFChain, URDFJoint,
19};
20pub use fk_dynamic::{BoxFK, DynamicDHChain, DynamicHPChain, DynamicURDFChain};
21pub use path::{RobotPath, SRobotPath};
22pub use q::{RobotQ, SRobotQ, robotq, SRobotQLike};
23pub use traj::{RobotTraj, SRobotTraj};
24pub use validator::{JointValidator, Validator, ValidatorAnd, ValidatorNot, ValidatorOr, ValidatorContext, Leaf, FromFlattened};
25pub use validator_dynamic::DynamicJointValidator;
26
27use crate::validator::ValidatorRet;
28
29#[derive(Debug, Clone, thiserror::Error)]
30pub enum DekeError {
31    #[error("Expected {expected} joints, but found {found}")]
32    ShapeMismatch { expected: usize, found: usize },
33    #[error("Path has {0} waypoints, needs at least 2")]
34    PathTooShort(usize),
35    #[error("Joints contain non-finite values")]
36    JointsNonFinite,
37    #[error("Self-collision detected between joints {0} and {1}")]
38    SelfCollision(i16, i16),
39    #[error("Environment collision detected between joint {0} and object {1}")]
40    EnvironmentCollision(i16, i16),
41    #[error("Joints exceed their limits")]
42    ExceedJointLimits,
43    #[error("Out of iterations")]
44    OutOfIterations,
45    #[error("Locked-prefix constraint violated at waypoint {waypoint} joint {joint}")]
46    LockedPrefixViolation { waypoint: u32, joint: u8 },
47    #[error("Boundary conditions not parallel to path tangent (residual {0})")]
48    BoundaryInfeasible(f32),
49    #[error("Path has consecutive zero-length segments")]
50    DuplicateWaypoints,
51    #[error("Retimer failed: {0}")]
52    RetimerFailed(String),
53    #[error("Super error")]
54    SuperError,
55}
56
57impl From<Infallible> for DekeError {
58    fn from(_: Infallible) -> Self {
59        unreachable!()
60    }
61}
62
63pub type DekeResult<T> = Result<T, DekeError>;
64
65pub trait Planner<const N: usize, R: ValidatorRet = ()>: Sized + Clone + Debug + Send + Sync + 'static {
66    type Diagnostic: Display + Send + Sync;
67    type Config;
68
69    fn plan<
70        E: Into<DekeError>,
71        A: SRobotQLike<N, E>,
72        B: SRobotQLike<N, E>,
73        V: Validator<N, R>,
74    >(
75        &self,
76        config: &Self::Config,
77        start: A,
78        goal: B,
79        validator: &V,
80        ctx: &V::Context<'_>,
81    ) -> (DekeResult<SRobotPath<N>>, Self::Diagnostic);
82}
83
84pub trait Retimer<const N: usize, R: ValidatorRet = ()>: Sized + Clone + Debug + Send + Sync + 'static {
85    type Diagnostic: Display + Send + Sync;
86    type Constraints;
87
88    fn retime<V: Validator<N, R>>(
89        &self,
90        constraints: &Self::Constraints,
91        path: &SRobotPath<N>,
92        fk: &impl FKChain<N>,
93        validator: &V,
94        ctx: &V::Context<'_>,
95    ) -> (DekeResult<SRobotTraj<N>>, Self::Diagnostic);
96}