Skip to main content

copp/
lib.rs

1//! `copp` crate public API.
2//!
3//! # What problem does this library solve?
4//! This library targets **OPP** (Optimal Path Parameterization) problems.
5//! Given a geometric path parameterization
6//! $q = q(s)$, the solver finds a time law $s = s(t)$ such that constraints are
7//! satisfied while an objective is optimized.
8//!
9//! In short, we convert geometry-space motion into time-space scheduling:
10//! $$
11//! q = q(s) \quad \Longrightarrow \quad s = s(t),
12//! $$
13//! and solve for globally optimal / KKT-satisfying / heuristic near-optimal
14//! trajectories under the selected backend and objective model.
15//!
16//! # Objective families: TOPP vs COPP
17//! - **TOPP**: Time-Optimal Path Parameterization (typical objective is minimum
18//!   traversal time).
19//! - **COPP**: Convex-Objective Path Parameterization (supports richer convex
20//!   objectives beyond pure time-optimality).
21//!
22//! For non-convex objectives, a practical approach is **SCP**:
23//! perform DC decomposition and iterative objective linearization. Constraint
24//! linearization (notably for third-order models) is already implemented in this
25//! crate. For objective modeling details, see COPP solver families and
26//! `CoppObjective`-related APIs.
27//!
28//! # Constraint-order families: 2nd vs 3rd order
29//! - **2nd-order** (TOPP2/COPP2): commonly covers velocity, acceleration,
30//!   and torque-related constraints.
31//! - **3rd-order** (TOPP3/COPP3): additionally models jerk-level effects.
32//!
33//! User-defined constraints are supported at different abstraction levels:
34//! - prefer [`robot::Robot`] for physically meaningful high-level ingestion;
35//! - use [`constraints::Constraints`] directly for maximum low-level flexibility.
36//!
37//! # Supported problem classes
38//! This crate provides solvers for four major classes:
39//! - TOPP2
40//! - COPP2
41//! - TOPP3
42//! - COPP3
43//!
44//! # Recommended onboarding path
45//! 1. Build constraints with [`robot::Robot`] (or directly with
46//!    [`constraints::Constraints`] for advanced customization).
47//! 2. Choose a solver family from [`solver`] based on objective/accuracy/runtime.
48//! 3. Start quickly with [`prelude`] for common imports.
49
50pub mod robot;
51
52pub(crate) mod copp;
53pub mod diag;
54pub(crate) mod math;
55pub mod path;
56
57pub use crate::copp::constraints;
58
59/// Solver entry namespace (TOPP2/TOPP3/COPP2/COPP3).
60///
61/// Each submodule exposes a solver family with stable public paths.
62/// Read the submodule summary first, then choose by objective and runtime budget.
63pub mod solver {
64    /// TOPP2 reachable-set construction.
65    ///
66    /// Input: TOPP2 problem + reach-set options.  
67    /// Output: feasible acceleration range representation along the path.  
68    /// Scenario: feasibility analysis or as a precursor for TOPP2/TOPP3 pipelines.
69    ///
70    /// # Example
71    /// ```rust, no_run
72    #[doc = include_str!("../examples/reach_set2.rs")]
73    /// ```
74    pub mod reach_set2 {
75        pub use crate::copp::copp2::stable::reach_set2::*;
76        pub use crate::topp2_basic::*;
77    }
78
79    /// TOPP2 reachability-analysis solver.
80    ///
81    /// Input: TOPP2 problem + RA options.  
82    /// Output: time-optimal feasible `a` profile under second-order constraints.  
83    /// Scenario: fast and reliable TOPP2 baseline for production pipelines.
84    ///
85    /// # Example
86    /// ```rust, no_run
87    #[doc = include_str!("../examples/topp2_ra.rs")]
88    /// ```
89    pub mod topp2_ra {
90        pub use crate::copp::copp2::stable::topp2_ra::*;
91        pub use crate::topp2_basic::*;
92    }
93
94    /// COPP2 SOCP backend (Clarabel).
95    ///
96    /// Input: COPP2 problem + convex objective + SOCP/Clarabel options.  
97    /// Output: conic-optimization based solution and conversion helpers.  
98    /// Scenario: when conic formulation is preferred over DP-style solvers.
99    ///
100    /// # Example
101    /// ```rust, no_run
102    #[doc = include_str!("../examples/copp2_socp.rs")]
103    /// ```
104    pub mod copp2_socp {
105        pub use crate::copp::clarabel_backend::{
106            ClarabelOptions, ClarabelOptionsBuilder, clarabel_to_copp2_solution,
107        };
108        pub use crate::copp::copp2::stable::copp2_socp::*;
109        pub use crate::copp2_basic::*;
110    }
111
112    /// COPP3 SOCP backend (Clarabel).
113    ///
114    /// Input: COPP3 problem + convex objective + SOCP/Clarabel options.  
115    /// Output: conic-program solution and conversion helpers.  
116    /// Scenario: third-order convex optimization via conic programming.
117    ///
118    /// # Example
119    /// ```rust, no_run
120    #[doc = include_str!("../examples/copp3_socp.rs")]
121    /// ```
122    pub mod copp3_socp {
123        pub use crate::copp::clarabel_backend::{
124            ClarabelOptions, ClarabelOptionsBuilder, clarabel_to_copp3_solution,
125        };
126        pub use crate::copp::copp3::stable::copp3_socp::*;
127        pub use crate::copp3_basic::*;
128    }
129
130    /// TOPP3 LP backend (Clarabel).
131    ///
132    /// Input: TOPP3 problem + LP/Clarabel options.  
133    /// Output: LP-based time-optimal solution in third-order setting.  
134    /// Scenario: linear-programming formulation for TOPP3.
135    ///
136    /// # Example
137    /// ```rust, no_run
138    #[doc = include_str!("../examples/topp3_lp.rs")]
139    /// ```
140    pub mod topp3_lp {
141        pub use crate::copp::clarabel_backend::{
142            ClarabelOptions, ClarabelOptionsBuilder, clarabel_to_copp3_solution,
143        };
144        pub use crate::copp::copp3::stable::topp3_lp::*;
145        pub use crate::topp3_basic::*;
146    }
147
148    /// TOPP3 SOCP backend (Clarabel).
149    ///
150    /// Input: TOPP3 problem + SOCP/Clarabel options.  
151    /// Output: SOCP-based time-optimal trajectory profile.  
152    /// Scenario: conic alternative to LP/RA for TOPP3.
153    ///
154    /// # Example
155    /// ```rust, no_run
156    #[doc = include_str!("../examples/topp3_socp.rs")]
157    /// ```
158    pub mod topp3_socp {
159        pub use crate::copp::clarabel_backend::{
160            ClarabelOptions, ClarabelOptionsBuilder, clarabel_to_copp3_solution,
161        };
162        pub use crate::copp::copp3::stable::topp3_socp::*;
163        pub use crate::topp3_basic::*;
164    }
165}
166
167/// Time-grid interpolation policy used when converting trajectory profiles to time-domain samples.
168///
169/// Import via `use copp::InterpolationMode;` — this is the single canonical path.
170/// All solver submodules (`solver::topp2_ra`, `solver::topp3_lp`, etc.) accept this type
171/// in their interpolation helpers (`t_to_s_topp2`, `t_to_s_topp3`, …).
172pub use crate::copp::general::InterpolationMode;
173
174mod topp2_basic {
175    pub use crate::copp::copp2::stable::basic::{
176        Topp2Problem, Topp2ProblemBuilder, a_to_b_topp2, s_to_t_topp2, t_to_s_topp2,
177    };
178}
179
180mod copp2_basic {
181    pub use crate::copp::copp2::stable::basic::{
182        Copp2Problem, Copp2ProblemBuilder, a_to_b_topp2, s_to_t_topp2, t_to_s_topp2,
183    };
184    pub use crate::copp::objectives::CoppObjective;
185}
186
187mod topp3_basic {
188    pub use crate::copp::copp3::stable::basic::{
189        Topp3Problem, Topp3ProblemBuilder, s_to_t_topp3, t_to_s_topp3,
190    };
191}
192
193mod copp3_basic {
194    pub use crate::copp::copp3::stable::basic::{
195        Copp3Problem, Copp3ProblemBuilder, s_to_t_topp3, t_to_s_topp3,
196    };
197    pub use crate::copp::objectives::CoppObjective;
198}
199
200/// Commonly used public imports for application code.
201///
202/// Input: none (import-only convenience module).  
203/// Output: unified symbols for robot, constraints, solvers, and utility types.
204/// Scenario: rapid prototyping and application-layer code with minimal import boilerplate.  
205///
206/// Typical usage: `use copp::prelude::*;`
207///
208/// # Import ordering (mirrors recommended onboarding path)
209/// 1. **Robot & constraints** — [`robot::Robot`], [`robot::RobotBasic`], [`robot::RobotTorque`], [`constraints::Constraints`].
210/// 2. **Solver builders** — Problem/options builders for each solver family.
211/// 3. **Utility types** — [`InterpolationMode`], [`copp::objectives::CoppObjective`], [`diag::CoppError`], [`diag::Verbosity`].
212/// 4. **Path & AD** — [`path::Path`], [`path::Jet3`], math helpers.
213/// 5. **Solver submodules** — for calling solver entry functions directly.
214pub mod prelude {
215    // 1. Robot model traits and constraint container
216    pub use crate::constraints::Constraints;
217    pub use crate::robot::*;
218
219    // 2. Solver builders (Problem builders and options builders)
220    pub use crate::solver::copp2_socp::{ClarabelOptions, ClarabelOptionsBuilder};
221    pub use crate::solver::copp2_socp::{Copp2Problem, Copp2ProblemBuilder};
222    pub use crate::solver::copp3_socp::{Copp3Problem, Copp3ProblemBuilder};
223    pub use crate::solver::topp2_ra::{ReachSet2OptionsBuilder, Topp2Problem, Topp2ProblemBuilder};
224    pub use crate::solver::topp3_lp::{Topp3Problem, Topp3ProblemBuilder};
225
226    // 3. Shared utility types
227    pub use crate::InterpolationMode;
228    pub use crate::copp::objectives::CoppObjective;
229    pub use crate::diag::{
230        CoppError, Verbosity, VerbosityOutput, set_verbosity_log_file, set_verbosity_output,
231        verbosity_output,
232    };
233
234    // 4. Path building and automatic differentiation
235    pub use crate::path::{
236        Jet3, Parametrization, Path, PathDerivatives, SplineConfig, cos, exp, ln, powi, sin, sqrt,
237    };
238
239    // 5. Solver submodule namespaces (for calling solver entry functions)
240    pub use crate::solver::{copp2_socp, copp3_socp, reach_set2, topp2_ra, topp3_lp, topp3_socp};
241}