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