use std::time::Duration;
use deke_types::SRobotQ;
#[derive(Clone, Debug)]
pub struct JointLimits<const N: usize> {
pub v_max: SRobotQ<N, f64>,
pub a_max: SRobotQ<N, f64>,
pub j_max: SRobotQ<N, f64>,
}
impl<const N: usize> JointLimits<N> {
pub fn symmetric(v: f64, a: f64, j: f64) -> Self {
Self {
v_max: SRobotQ::splat(v),
a_max: SRobotQ::splat(a),
j_max: SRobotQ::splat(j),
}
}
}
#[derive(Clone, Debug)]
pub struct PathConditioning {
pub sharp_corner_angle: f64,
}
impl Default for PathConditioning {
fn default() -> Self {
Self {
sharp_corner_angle: 30.0_f64.to_radians(),
}
}
}
#[derive(Clone, Debug)]
pub struct PlannerOptions<const N: usize> {
pub sample_ds: f64,
pub manip_weight: f64,
pub max_branch_jump: f64,
pub max_velocity: f64,
pub joint_v_max: SRobotQ<N, f64>,
pub reconfig_vel_fraction: f64,
}
impl<const N: usize> Default for PlannerOptions<N> {
fn default() -> Self {
Self {
sample_ds: 2e-3,
manip_weight: 1.0,
max_branch_jump: 0.6,
max_velocity: 0.0,
joint_v_max: SRobotQ::splat(f64::INFINITY),
reconfig_vel_fraction: 0.9,
}
}
}
#[derive(Clone, Debug)]
pub struct LinearConstraints<const N: usize> {
pub joint: JointLimits<N>,
pub tcp_speed: f64,
pub output_dt: Duration,
pub forbid_interior_dips: bool,
}
#[derive(Clone, Debug)]
pub struct FollowConfig<const N: usize> {
pub conditioning: PathConditioning,
pub planner: PlannerOptions<N>,
pub redundant: Option<crate::redundant::RedundantOptions>,
pub constraints: LinearConstraints<N>,
}
impl<const N: usize> FollowConfig<N> {
pub fn weld(ipm: f64, joint: JointLimits<N>, output_dt: Duration) -> Self {
let tcp_speed = ipm * 0.0254 / 60.0;
let planner = PlannerOptions {
sample_ds: 5e-4,
manip_weight: 1.0,
max_branch_jump: 0.6,
max_velocity: tcp_speed,
joint_v_max: joint.v_max,
reconfig_vel_fraction: 0.9,
};
Self {
conditioning: PathConditioning {
sharp_corner_angle: 30.0_f64.to_radians(),
},
planner,
redundant: None,
constraints: LinearConstraints {
joint,
tcp_speed,
output_dt,
forbid_interior_dips: false,
},
}
}
pub fn with_redundancy(mut self, options: crate::redundant::RedundantOptions) -> Self {
self.redundant = Some(options);
self
}
}