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
27#[derive(Debug, Clone, thiserror::Error)]
28pub enum DekeError {
29    #[error("Expected {expected} joints, but found {found}")]
30    ShapeMismatch { expected: usize, found: usize },
31    #[error("Path has {0} waypoints, needs at least 2")]
32    PathTooShort(usize),
33    #[error("Joints contain non-finite values")]
34    JointsNonFinite,
35    #[error("Self-collision detected between joints {0} and {1}")]
36    SelfCollision(i16, i16),
37    #[error("Environment collision detected between joint {0} and object {1}")]
38    EnvironmentCollision(i16, i16),
39    #[error("Joints exceed their limits")]
40    ExceedJointLimits,
41    #[error("Out of iterations")]
42    OutOfIterations,
43    #[error("Locked-prefix constraint violated at waypoint {waypoint} joint {joint}")]
44    LockedPrefixViolation { waypoint: u32, joint: u8 },
45    #[error("Boundary conditions not parallel to path tangent (residual {0})")]
46    BoundaryInfeasible(f32),
47    #[error("Path has consecutive zero-length segments")]
48    DuplicateWaypoints,
49    #[error("Retimer failed: {0}")]
50    RetimerFailed(String),
51    #[error("Super error")]
52    SuperError,
53}
54
55impl From<Infallible> for DekeError {
56    fn from(_: Infallible) -> Self {
57        unreachable!()
58    }
59}
60
61pub type DekeResult<T> = Result<T, DekeError>;
62
63pub trait Planner<const N: usize>: Sized + Clone + Debug + Send + Sync + 'static {
64    type Diagnostic: Display + Send + Sync;
65    type Config;
66
67    fn plan<
68        E: Into<DekeError>,
69        A: SRobotQLike<N, E>,
70        B: SRobotQLike<N, E>,
71        V: Validator<N>,
72    >(
73        &self,
74        config: &Self::Config,
75        start: A,
76        goal: B,
77        validator: &mut V,
78        ctx: &V::Context<'_>,
79    ) -> (DekeResult<SRobotPath<N>>, Self::Diagnostic);
80}
81
82pub trait Retimer<const N: usize>: Sized + Clone + Debug + Send + Sync + 'static {
83    type Diagnostic: Display + Send + Sync;
84    type Constraints;
85
86    fn retime<V: Validator<N>>(
87        &self,
88        constraints: &Self::Constraints,
89        path: &SRobotPath<N>,
90        fk: &impl FKChain<N>,
91        validator: &mut V,
92        ctx: &V::Context<'_>,
93    ) -> (DekeResult<SRobotTraj<N>>, Self::Diagnostic);
94}