JSim 2026.06.01-p(1)
Loading...
Searching...
No Matches
joint_base.hpp
Go to the documentation of this file.
1// Copyright (c) JSim contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the LGPLv3 license file in the root directory of this project.
4
5#pragma once
6
8
9namespace frcsim {
10
11class RigidBody;
12
13enum class JointType {
14 kRevolute, // Hinge: rotation about an axis
15 kPrismatic, // Slider: translation along an axis
16 kFixed, // Rigid connection
17 kBall, // Ball joint: unconstrained rotation
18 kDistance, // Distance constraint between bodies
19};
20
34class JointBase {
35 public:
36 virtual ~JointBase() = default;
37
38 JointType type() const { return type_; }
39 RigidBody* bodyA() { return body_a_; }
40 RigidBody* bodyB() { return body_b_; }
41 const RigidBody* bodyA() const { return body_a_; }
42 const RigidBody* bodyB() const { return body_b_; }
43
44 // Anchor points in local coordinates of each body
45 const Vector3& anchorA() const { return anchor_a_; }
46 const Vector3& anchorB() const { return anchor_b_; }
47 void setAnchorA(const Vector3& anchor) { anchor_a_ = anchor; }
48 void setAnchorB(const Vector3& anchor) { anchor_b_ = anchor; }
49
50 bool isEnabled() const { return is_enabled_; }
51 void setEnabled(bool enabled) { is_enabled_ = enabled; }
52
54 void setBreakForceThreshold(double force_n) {
55 break_force_threshold_ = force_n;
56 }
57
58 bool isBroken() const { return is_broken_; }
59 void resetBroken() { is_broken_ = false; }
60
61 // Main constraint solving interface (to be overridden per joint type)
62 virtual void solveConstraint(double dt_s, int iterations) = 0;
63
64 // Warm-start cached impulses from previous frame
65 virtual void warmStart() {}
66
67 // Compute constraint error for diagnostics
68 virtual double constraintError() const = 0;
69
70 protected:
71 explicit JointBase(JointType type, RigidBody* body_a, RigidBody* body_b)
72 : type_(type), body_a_(body_a), body_b_(body_b) {}
73
75 RigidBody* body_a_{nullptr};
76 RigidBody* body_b_{nullptr};
79 bool is_enabled_{true};
80 bool is_broken_{false};
82};
83
84} // namespace frcsim
void setBreakForceThreshold(double force_n)
Definition joint_base.hpp:54
const Vector3 & anchorA() const
Definition joint_base.hpp:45
JointType type() const
Definition joint_base.hpp:38
Vector3 anchor_b_
Definition joint_base.hpp:78
JointBase(JointType type, RigidBody *body_a, RigidBody *body_b)
Definition joint_base.hpp:71
RigidBody * body_b_
Definition joint_base.hpp:76
virtual ~JointBase()=default
const Vector3 & anchorB() const
Definition joint_base.hpp:46
bool isEnabled() const
Definition joint_base.hpp:50
bool is_broken_
Definition joint_base.hpp:80
void setEnabled(bool enabled)
Definition joint_base.hpp:51
const RigidBody * bodyA() const
Definition joint_base.hpp:41
Vector3 anchor_a_
Definition joint_base.hpp:77
bool is_enabled_
Definition joint_base.hpp:79
const RigidBody * bodyB() const
Definition joint_base.hpp:42
RigidBody * body_a_
Definition joint_base.hpp:75
void setAnchorB(const Vector3 &anchor)
Definition joint_base.hpp:48
virtual double constraintError() const =0
RigidBody * bodyA()
Definition joint_base.hpp:39
virtual void warmStart()
Definition joint_base.hpp:65
void setAnchorA(const Vector3 &anchor)
Definition joint_base.hpp:47
RigidBody * bodyB()
Definition joint_base.hpp:40
JointType type_
Definition joint_base.hpp:74
virtual void solveConstraint(double dt_s, int iterations)=0
double breakForceThreshold() const
Definition joint_base.hpp:53
void resetBroken()
Definition joint_base.hpp:59
double break_force_threshold_
Definition joint_base.hpp:81
bool isBroken() const
Definition joint_base.hpp:58
Simulated rigid body with translational/angular dynamics and optional aero metadata.
Definition rigid_body.hpp:44
Definition vector.hpp:13
JointType
Definition joint_base.hpp:13
@ kDistance
Definition joint_base.hpp:18
@ kFixed
Definition joint_base.hpp:16
@ kPrismatic
Definition joint_base.hpp:15
@ kBall
Definition joint_base.hpp:17
@ kRevolute
Definition joint_base.hpp:14
3D vector utility used throughout JSim physics.
Definition vector.hpp:22