RavEngine
Loading...
Searching...
No Matches
DyFeatherstoneArticulationJointData.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef DY_FEATHERSTONE_ARTICULATION_JOINT_DATA_H
30#define DY_FEATHERSTONE_ARTICULATION_JOINT_DATA_H
31
32#include "foundation/PxVec3.h"
33#include "foundation/PxQuat.h"
34#include "foundation/PxTransform.h"
35#include "foundation/PxVecMath.h"
36#include "CmUtils.h"
37#include "CmSpatialVector.h"
38#include "DyVArticulation.h"
39#include "DyFeatherstoneArticulationUtils.h"
40#include "DyArticulationJointCore.h"
41#include <stdio.h>
42
43namespace physx
44{
45 namespace Dy
46 {
47
48
50 {
51 public:
52
53 ArticulationJointCoreData() : jointOffset(0xffffffff), dofInternalConstraintMask(0)
54 {
55 }
56
57
58 PX_CUDA_CALLABLE PX_FORCE_INLINE void computeMotionMatrix(ArticulationJointCore* joint,
59 Cm::UnAlignedSpatialVector* motionMatrix, const Cm::UnAlignedSpatialVector* jointAxis)
60 {
61 const PxVec3 childOffset = -joint->childPose.p;
62
63 //transpose(Tc)*S = 0
64 //transpose(Ta)*S = 1
65 switch (joint->jointType)
66 {
68 {
69 const Cm::UnAlignedSpatialVector& jJointAxis = jointAxis[0];
70 const PxVec3 u = (joint->childPose.rotate(jJointAxis.bottom)).getNormalized();
71
72 motionMatrix[0] = Cm::UnAlignedSpatialVector(PxVec3(0.f), u);
73
74 PX_ASSERT(dof == 1);
75
76 break;
77 }
80 {
81 const Cm::UnAlignedSpatialVector& jJointAxis = jointAxis[0];
82 const PxVec3 u = (joint->childPose.rotate(jJointAxis.top)).getNormalized();
83 const PxVec3 uXd = u.cross(childOffset);
84
85 motionMatrix[0] = Cm::UnAlignedSpatialVector(u, uXd);
86
87 break;
88 }
90 {
91
92 for (PxU32 ind = 0; ind <dof; ++ind)
93 {
94 const Cm::UnAlignedSpatialVector& jJointAxis = jointAxis[ind];
95 const PxVec3 u = (joint->childPose.rotate(jJointAxis.top)).getNormalized();
96
97 const PxVec3 uXd = u.cross(childOffset);
98 motionMatrix[ind] = Cm::UnAlignedSpatialVector(u, uXd);
99 }
100
101 break;
102 }
104 {
105 PX_ASSERT(dof == 0);
106 break;
107 }
108 default:
109 break;
110 }
111 }
112
113 PX_CUDA_CALLABLE PX_FORCE_INLINE PxU8 computeJointDofs(ArticulationJointCore* joint) const
114 {
115 PxU8 tDof = 0;
116
117 for (PxU32 i = 0; i < DY_MAX_DOF; ++i)
118 {
119 if (joint->motion[i] != PxArticulationMotion::eLOCKED)
120 {
121 tDof++;
122 }
123 }
124
125 return tDof;
126 }
127
128 PX_CUDA_CALLABLE PX_FORCE_INLINE void computeJointAxis(const ArticulationJointCore* joint, Cm::UnAlignedSpatialVector* jointAxis)
129 {
130 for (PxU32 i = 0; i < dof; ++i)
131 {
132 PxU32 ind = joint->dofIds[i];
133
134 Cm::UnAlignedSpatialVector axis = Cm::UnAlignedSpatialVector::Zero();
135 //axis is in the local space of joint
136 axis[ind] = 1.f;
137
138 jointAxis[i] = axis;
139 }
140 }
141
142 PX_FORCE_INLINE PxU32 computeJointDof(ArticulationJointCore* joint, const bool forceRecompute,
144 {
145 if (joint->jointDirtyFlag & ArticulationJointCoreDirtyFlag::eMOTION || forceRecompute)
146 {
147
148 dof = 0;
149 limitMask = 0;
150
151 //KS - no need to zero memory here.
152 //PxMemZero(jointAxis, sizeof(jointAxis));
153
154 for (PxU8 i = 0; i < DY_MAX_DOF; ++i)
155 {
156 if (joint->motion[i] != PxArticulationMotion::eLOCKED)
157 {
158 Cm::UnAlignedSpatialVector axis = Cm::UnAlignedSpatialVector::Zero();
159 //axis is in the local space of joint
160 axis[i] = 1.f;
161
162 jointAxis[dof] = axis;
163
164 joint->invDofIds[i] = dof;
165 joint->dofIds[dof] = i;
166
167 if (joint->motion[i] == PxArticulationMotion::eLIMITED)
168 limitMask |= 1 << dof;
169
170 dof++;
171 }
172 }
173 }
174
175 return dof;
176
177 }
178
179 PxU32 jointOffset; //4
180 //degree of freedom
181 PxU8 dof; //1
182 PxU8 dofInternalConstraintMask; //1
183 PxU8 limitMask; //1
184
185 };
186
187
188
190 {
191 PxReal targetJointVelocity[3]; //12
192 PxReal targetJointPosition[3]; //24
193 PxReal armature[3]; //36
194
195
197 {
198 for (PxU32 i = 0; i < 3; ++i)
199 {
200 targetJointPosition[i] = 0.f;
201 targetJointVelocity[i] = 0.f;
202 armature[i] = 0.f;
203 }
204 }
205
206
207
208 PX_CUDA_CALLABLE PX_FORCE_INLINE void setJointVelocityDrive(ArticulationJointCore* joint, const PxU32 dof)
209 {
210 if (joint->jointDirtyFlag & ArticulationJointCoreDirtyFlag::eTARGETVELOCITY)
211 {
212 for (PxU32 i = 0; i < dof; ++i)
213 {
214 PxU32 ind = joint->dofIds[i];
215
216 targetJointVelocity[i] = joint->targetV[ind];
217 }
218
219 joint->jointDirtyFlag &= ~ArticulationJointCoreDirtyFlag::eTARGETVELOCITY;
220 }
221 }
222
223 PX_CUDA_CALLABLE PX_FORCE_INLINE void setJointPoseDrive(ArticulationJointCore* joint, const PxU32 dof)
224 {
225 if (joint->jointDirtyFlag & ArticulationJointCoreDirtyFlag::eTARGETPOSE)
226 {
227 for (PxU32 i = 0; i < dof; ++i)
228 {
229 PxU32 ind = joint->dofIds[i];
230
231 targetJointPosition[i] = joint->targetP[ind];
232 }
233
234 joint->jointDirtyFlag &= ~ArticulationJointCoreDirtyFlag::eTARGETPOSE;
235 }
236 }
237
238 PX_CUDA_CALLABLE PX_FORCE_INLINE void setArmature(ArticulationJointCore* joint, const PxU32 dof)
239 {
240 if (joint->jointDirtyFlag & ArticulationJointCoreDirtyFlag::eARMATURE)
241 {
242
243 for (PxU32 i = 0; i < dof; ++i)
244 {
245 PxU32 ind = joint->dofIds[i];
246
247 armature[i] = joint->armature[ind];
248 }
249
250 joint->jointDirtyFlag &= ~ArticulationJointCoreDirtyFlag::eARMATURE;
251 }
252 }
253
254 };
255
256 }//namespace Dy
257}
258
259#endif
Definition DyFeatherstoneArticulationJointData.h:50
3 Element vector class.
Definition PxVec3.h:50
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 cross(const PxVec3 &v) const
cross product
Definition PxVec3.h:284
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Definition CmSpatialVector.h:310
Definition DyArticulationCore.h:62
Definition DyArticulationJointCore.h:44
Definition DyFeatherstoneArticulationJointData.h:190
@ eREVOLUTE_UNWRAPPED
Single rotational DOF, e.g. an elbow joint or a rotational motor, position not wrapped.
Definition PxSolverDefs.h:285
@ ePRISMATIC
Single linear DOF, e.g. cart on a rail.
Definition PxSolverDefs.h:283
@ eREVOLUTE
Single rotational DOF, e.g. an elbow joint or a rotational motor, position wrapped at 2pi radians.
Definition PxSolverDefs.h:284
@ eFIX
All joint axes, i.e. degrees of freedom (DOFs) locked.
Definition PxSolverDefs.h:282
@ eSPHERICAL
Ball and socket joint with two or three DOFs.
Definition PxSolverDefs.h:286
@ eLIMITED
Limited DOF - set limits of joint DOF together with this flag, see PxArticulationJointReducedCoordina...
Definition PxSolverDefs.h:270
@ eLOCKED
Locked axis, i.e. degree of freedom (DOF)
Definition PxSolverDefs.h:269