SuperDex Physics C++ API
Loading...
Searching...
No Matches
articulated_body_params.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19// PLEASE DO NOT ADD OTHER INCLUDES HERE. This header is included in the mochi_physics public API.
23
24#include <optional>
25
26namespace superdex {
27
28/**
29 * @brief Degree-of-freedom layout information for a single joint in an articulated body.
30 *
31 * @details Describes the offset and sizes of translation and rotation DoFs for a joint within
32 * the flattened DoF array of the articulated body.
33 */
35 /** @brief Offset of this joint's DoFs in the flattened DoF array. */
36 int offset = -1;
37 /** @brief Number of translational DoFs for this joint. */
38 int transSize = 0;
39 /** @brief Number of rotational DoFs for this joint. */
40 int rotSize = 0;
41
42 /**
43 * @brief Offset of this joint's translational DoFs in the flattened DoF array.
44 *
45 * @return The translational DoF offset (equal to @ref offset).
46 */
47 int GetTransOffset() const;
48
49 /**
50 * @brief Offset of this joint's rotational DoFs in the flattened DoF array.
51 *
52 * @return The rotational DoF offset (@ref offset + @ref transSize).
53 */
54 int GetRotOffset() const;
55
56 /**
57 * @brief Total number of DoFs for this joint.
58 *
59 * @return The total DoF count (@ref transSize + @ref rotSize).
60 */
61 int GetSize() const;
62
63#if MOCHI_LANGUAGE_CPP20
64 bool operator==(ArticulatedDofInfo const&) const = default;
65#endif
66
72};
73
74/**
75 * @brief Types of joints in an articulated body.
76 */
78 Free, ///< 6-DoF joint. Unconstrained relative motion between links.
79 Prismatic, ///< 1-DoF translational joint along a single axis.
80 Revolute, ///< 1-DoF rotational joint around a single axis.
81 Spherical, ///< 3-DoF rotational joint (ball-and-socket).
82 Hard, ///< 0-DoF rigid (weld) joint. No relative motion between links.
83 Cycle, ///< Cycle-closing joint in closed-loop topologies.
86};
87
88} // namespace superdex
89
92MOCHI_ENUM_ITEM(Prismatic)
93MOCHI_ENUM_ITEM(Revolute)
94MOCHI_ENUM_ITEM(Spherical)
96MOCHI_ENUM_ITEM(Cycle)
98MOCHI_ENUM_ITEM(Invalid)
100
101namespace superdex {
102
103/**
104 * @brief Defines a cycle-closing joint in an articulated body.
105 *
106 * @details Cycle joints create closed loops in the kinematic chain, allowing more complex
107 * topologies beyond simple tree structures.
108 */
110 /** @brief Child link index. */
111 int child = 0;
112
113 /** @brief Parent link index. */
114 int parent = 0;
115
116#if MOCHI_LANGUAGE_CPP20
117 bool operator==(ArticulatedCycleJoint const&) const = default;
118#endif
119
124};
125
126/**
127 * @brief Per-joint friction parameters for articulated bodies.
128 *
129 * @details Viscous and dry friction force/torque contributions are added together.
130 * - Viscous friction force/torque is proportional to velocity with coefficient @ref viscous.
131 * - Dry friction is elasto-plastic. Each joint keeps a friction anchor, and its dry friction
132 * force/torque grows with the (linear or angular) displacement of the joint from the anchor, up
133 * to the static peak @ref coulomb + @ref stictionExtra at @ref preslidingDisplacement. A load
134 * below the static peak is held at the displacement from the anchor that balances it. Beyond the
135 * presliding displacement, the joint slides, and its anchor follows it.
136 * - While the joint slides, dry friction force/torque (excluding additional viscous friction) has
137 * magnitude @ref coulomb + @ref stictionExtra * exp(-pow(|v| / @ref stribeckVel, 2)) when
138 * @ref stribeckVel > 0, with |v| the magnitude of the (linear or angular) sliding velocity. If
139 * @ref stribeckVel = 0, the Stribeck term is omitted and the magnitude is @ref coulomb. This
140 * causes friction to decrease smoothly from the peak static value to @ref coulomb at high
141 * velocities.
142 *
143 * @note The friction anchors are part of the actor history. Setting the joint positions resets
144 * them; other setters keep them.
145 * @note Units are [N] and [m] for translation DoFs (prismatic joints), and [N·m] and [rad] for
146 * rotation DoFs (revolute and spherical joints).
147 */
149 /**
150 * @brief Viscous friction coefficient [N·s/m or N·m·s/rad].
151 *
152 * @note Default is zero (no viscous friction).
153 */
155
156 /**
157 * @brief Coulomb friction coefficient [N or N·m].
158 *
159 * @note Default is zero (no Coulomb friction).
160 */
162
163 /**
164 * @brief Displacement of a joint from its friction anchor [m or rad] at which dry friction
165 * reaches its static peak.
166 *
167 * @details Below it, dry friction force/torque grows smoothly from zero with the displacement,
168 * which is elastic: the joint returns towards its anchor when the load drops. Beyond it, the
169 * joint slides.
170 *
171 * @note Must be positive. Smaller values hold loads more stiffly, but may degrade convergence.
172 * @note Below it, dry friction adds no damping. A held joint is damped only by @ref viscous (zero
173 * by default) and by the time integration.
174 */
176
177 /**
178 * @brief [Deprecated] Ignored. Dry friction no longer uses a velocity threshold: it is
179 * elasto-plastic, with @ref preslidingDisplacement.
180 *
181 * @warning Deprecated: will be removed in a future release. Setting it logs a warning.
182 */
183 std::optional<real> falloffVel = std::nullopt;
184
185 /**
186 * @brief [Experimental] Extra stiction force/torque [N or N·m] representing the difference
187 * between static and dynamic friction.
188 *
189 * @warning This is an experimental feature. It may be changed or removed in the future. Use at
190 * your own risk.
191 * @warning Nonzero values may harm convergence.
192 * @warning Nonzero extra stiction with zero Stribeck velocity results in a nonsmooth force.
193 *
194 * @note Must not be negative. The @ref coulomb represents dynamic friction in the high-velocity
195 * limit, and peak static friction is @ref coulomb + @ref stictionExtra.
196 * @note Defaults to zero (no difference between static and dynamic friction).
197 */
199
200 /**
201 * @brief [Experimental] Stribeck velocity [m/s or rad/s] governing how sharply friction
202 * transitions from static to dynamic coefficients as the sliding velocity increases.
203 *
204 * @warning This is an experimental feature. It may be changed or removed in the future. Use at
205 * your own risk.
206 * @warning Nonzero values may harm convergence.
207 * @warning Nonzero extra stiction with zero Stribeck velocity results in a nonsmooth force.
208 *
209 * @note Must not be negative. A smaller value means a sharper transition.
210 * @note Defaults to zero.
211 * @note This has no effect if @ref stictionExtra is zero.
212 * @note The sliding velocity is the slip since the start of the step divided by the time since
213 * then, so higher-order integrators may be only first-order accurate while the joint slides.
214 */
216
217#if MOCHI_LANGUAGE_CPP20
218 bool operator==(ArticulatedJointFrictionParams const&) const = default;
219#endif
220
221 // clang-format off
226 MOCHI_FIELD(falloffVel) MOCHI_ATTRIBUTE(NoSerializeDefaults)
230 // clang-format on
231};
232
233/**
234 * @brief Selects how a @ref RoutingElement contributes to a spatial tendon's routing.
235 */
237 /// A point fixed in a link's local frame (the same frame in which the link's mesh and
238 /// geometry are authored, i.e. the link's root-transform frame). Adjacent waypoints are joined
239 /// by a straight segment whose length contributes to the tendon length.
241 /// A constant moment arm contributing `coefficient * jointCoordinate`, as in a linear
242 /// transmission. Carries no geometry and breaks the polyline between waypoints.
244};
245
246} // namespace superdex
247
249MOCHI_ENUM_ITEM(Waypoint)
250MOCHI_ENUM_ITEM(LinearJoint)
252
253namespace superdex {
254
255/**
256 * @brief One ordered element in a spatial tendon's heterogeneous routing list.
257 *
258 * @details A @ref RoutingElementType::Waypoint uses @ref index (a link index) and @ref
259 * localPosition; a @ref RoutingElementType::LinearJoint uses @ref index (a joint index) and @ref
260 * coefficient. Order matters: a segment forms only between adjacent waypoints, so a linear-joint
261 * element between two waypoints leaves a gap.
262 */
264 /// Selects the interpretation of the remaining fields.
266
267 /// Waypoint: the link index the waypoint is attached to. LinearJoint: the joint index.
268 int index = 0;
269
270 /// Waypoint only: the waypoint position in the link's local frame (the same frame in which
271 /// the link's mesh and geometry are authored, i.e. the link's root-transform frame) [m].
273
274 /// LinearJoint only: the signed constant moment arm d(displacement)/d(joint DoF)
275 /// [m / joint DoF]; its sign sets whether the tendon lengthens or shortens with the joint DoF.
277
278#if MOCHI_LANGUAGE_CPP20
279 bool operator==(RoutingElement const&) const = default;
280#endif
281
288};
289
290} // namespace superdex
291
ArticulatedJointType
Types of joints in an articulated body.
@ Spherical
3-DoF rotational joint (ball-and-socket).
@ Revolute
1-DoF rotational joint around a single axis.
@ Prismatic
1-DoF translational joint along a single axis.
@ Hard
0-DoF rigid (weld) joint. No relative motion between links.
@ Cycle
Cycle-closing joint in closed-loop topologies.
@ Free
6-DoF joint. Unconstrained relative motion between links.
@ Invalid
Invalid constraint type.
RoutingElementType
Selects how a RoutingElement contributes to a spatial tendon's routing.
@ Waypoint
A point fixed in a link's local frame (the same frame in which the link's mesh and geometry are autho...
@ LinearJoint
A constant moment arm contributing coefficient * jointCoordinate, as in a linear transmission.
NdArray< real, 3 > Real3
Definition nd_array.h:115
@ Count
Number of actor type enum values.
Definition mochi_enums.h:38
#define MOCHI_ENUM_COUNT(name)
Definition reflection.h:329
#define MOCHI_ENUM_END()
Definition reflection.h:330
#define MOCHI_STRUCT_END()
Definition reflection.h:333
#define MOCHI_ENUM_BEGIN(name)
Definition reflection.h:327
#define MOCHI_FIELD(name)
Definition reflection.h:351
#define MOCHI_STRUCT_BEGIN(name)
Definition reflection.h:332
#define MOCHI_ATTRIBUTE(...)
Definition reflection.h:357
#define MOCHI_ENUM_ITEM(name)
Definition reflection.h:328
Defines a cycle-closing joint in an articulated body.
bool operator==(ArticulatedCycleJoint const &) const =default
Degree-of-freedom layout information for a single joint in an articulated body.
int transSize
Number of translational DoFs for this joint.
int GetTransOffset() const
Offset of this joint's translational DoFs in the flattened DoF array.
int GetSize() const
Total number of DoFs for this joint.
int offset
Offset of this joint's DoFs in the flattened DoF array.
int rotSize
Number of rotational DoFs for this joint.
bool operator==(ArticulatedDofInfo const &) const =default
int GetRotOffset() const
Offset of this joint's rotational DoFs in the flattened DoF array.
Per-joint friction parameters for articulated bodies.
real stictionExtra
[Experimental] Extra stiction force/torque [N or N·m] representing the difference between static and ...
real viscous
Viscous friction coefficient [N·s/m or N·m·s/rad].
real preslidingDisplacement
Displacement of a joint from its friction anchor [m or rad] at which dry friction reaches its static ...
real coulomb
Coulomb friction coefficient [N or N·m].
std::optional< real > falloffVel
[Deprecated] Ignored.
bool operator==(ArticulatedJointFrictionParams const &) const =default
real stribeckVel
[Experimental] Stribeck velocity [m/s or rad/s] governing how sharply friction transitions from stati...
One ordered element in a spatial tendon's heterogeneous routing list.
bool operator==(RoutingElement const &) const =default
Real3 localPosition
Waypoint only: the waypoint position in the link's local frame (the same frame in which the link's me...
RoutingElementType type
Selects the interpretation of the remaining fields.
int index
Waypoint: the link index the waypoint is attached to. LinearJoint: the joint index.
real coefficient
LinearJoint only: the signed constant moment arm d(displacement)/d(joint DoF) [m / joint DoF]; its si...