symtropy_physics/joints/mod.rs
1// Copyright (C) 2024-2026 Tristan Stoltz / Luminous Dynamics
2// SPDX-License-Identifier: AGPL-3.0-or-later
3// Commercial licensing: see COMMERCIAL_LICENSE.md at repository root
4//! Joint types for articulated bodies.
5//!
6//! All joints implement the `Constraint<D>` trait, using the same iterative
7//! position + velocity solve pipeline as other constraints. Joints are
8//! dimension-agnostic (const-generic `<const D: usize>`).
9
10pub mod ball;
11pub mod fixed;
12pub mod hinge;
13pub mod prismatic;
14
15pub use ball::BallJoint;
16pub use fixed::FixedJoint;
17pub use hinge::HingeJoint;
18pub use prismatic::PrismaticJoint;
19
20/// Motor drive for actuated joints (hinge + prismatic).
21///
22/// Uses a PD controller to reach a target angle/position:
23/// `force = kp * (target - current) - kd * velocity`
24#[derive(Clone, Debug)]
25pub struct MotorDrive {
26 /// Target angle (radians, for hinge) or position (units, for prismatic).
27 pub target: f64,
28 /// Maximum force/torque the motor can apply.
29 pub max_force: f64,
30 /// Damping coefficient (velocity damping, prevents overshoot).
31 pub damping: f64,
32}
33
34impl MotorDrive {
35 /// Create a motor with the given target and max force.
36 pub fn new(target: f64, max_force: f64) -> Self {
37 Self {
38 target,
39 max_force,
40 damping: max_force * 0.1, // default 10% of max force
41 }
42 }
43}