1use std::{
2 convert::Infallible,
3 fmt::{Debug, Display},
4};
5
6pub use glam;
7pub use wide;
8
9mod fk;
10mod path;
11mod q;
12mod traj;
13mod validator;
14mod validator_dynamic;
15
16pub use fk::{
17 BoxFK, DHChain, DHJoint, DynamicDHChain, DynamicHPChain, DynamicURDFChain, FKChain, FKScalar,
18 FPDispatch, HPChain, HPJoint, PrismaticFK, TransformedFK, URDFBuildError, URDFChain,
19 URDFJoint, URDFJointType, compose_fixed_joints, compose_fixed_joints_f64,
20};
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(
54 "URDF joint at index {index} has an unexpected type: expected {expected}, found {found}"
55 )]
56 URDFJointTypeMismatch {
57 index: usize,
58 expected: &'static str,
59 found: &'static str,
60 },
61 #[error("URDFChain<{expected}> requires {expected} revolute joints, found {found}")]
62 URDFRevoluteCountMismatch { expected: usize, found: usize },
63 #[error("Super error")]
64 SuperError,
65}
66
67impl From<Infallible> for DekeError {
68 fn from(_: Infallible) -> Self {
69 unreachable!()
70 }
71}
72
73pub type DekeResult<T> = Result<T, DekeError>;
74
75pub trait Planner<const N: usize, F: fk::FKScalar = f32, R: ValidatorRet = ()>: Sized + Clone + Debug + Send + Sync + 'static {
76 type Diagnostic: Display + Send + Sync;
77 type Config;
78
79 fn plan<
80 E: Into<DekeError>,
81 A: SRobotQLike<N, E, F>,
82 B: SRobotQLike<N, E, F>,
83 V: Validator<N, R, F>,
84 >(
85 &self,
86 config: &Self::Config,
87 start: A,
88 goal: B,
89 validator: &V,
90 ctx: &V::Context<'_>,
91 ) -> (DekeResult<SRobotPath<N, F>>, Self::Diagnostic);
92}
93
94pub trait Retimer<const N: usize, F: fk::FKScalar = f32, R: ValidatorRet = ()>: Sized + Clone + Debug + Send + Sync + 'static {
95 type Diagnostic: Display + Send + Sync;
96 type Constraints;
97
98 fn retime<V: Validator<N, R, F>>(
99 &self,
100 constraints: &Self::Constraints,
101 path: &SRobotPath<N, F>,
102 fk: &impl FKChain<N, F>,
103 validator: &V,
104 ctx: &V::Context<'_>,
105 ) -> (DekeResult<SRobotTraj<N, F>>, Self::Diagnostic);
106}