use crate::body::BodyHandle;
use nalgebra::SVector;
#[derive(Clone, Debug)]
pub struct PdController {
pub kp: f64, pub kd: f64, pub max_effort: f64, }
impl Default for PdController {
fn default() -> Self {
Self {
kp: 100.0,
kd: 10.0,
max_effort: 1000.0,
}
}
}
impl PdController {
pub fn calculate(&self, error: f64, error_dot: f64) -> f64 {
let effort = self.kp * error + self.kd * error_dot;
effort.clamp(-self.max_effort, self.max_effort)
}
}
#[derive(Clone, Debug, Default)]
pub struct Motor {
pub target_pos: f64,
pub target_vel: f64,
pub current_effort: f64,
pub enabled: bool,
}
pub struct HingeJoint<const D: usize> {
pub body_a: BodyHandle,
pub body_b: BodyHandle,
pub anchor_a: SVector<f64, D>, pub anchor_b: SVector<f64, D>, pub axis: SVector<f64, D>, pub motor: Motor,
pub pd: PdController,
}
pub struct PrismaticJoint<const D: usize> {
pub body_a: BodyHandle,
pub body_b: BodyHandle,
pub anchor_a: SVector<f64, D>,
pub anchor_b: SVector<f64, D>,
pub axis: SVector<f64, D>, pub motor: Motor,
pub pd: PdController,
}