RavEngine
Loading...
Searching...
No Matches
PxVehicleSuspensionComponents.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#pragma once
30
35#include "vehicle2/PxVehicleParams.h"
36#include "vehicle2/PxVehicleComponent.h"
37
38#include "vehicle2/commands/PxVehicleCommandStates.h"
39#include "vehicle2/commands/PxVehicleCommandHelpers.h"
40#include "vehicle2/rigidBody/PxVehicleRigidBodyParams.h"
41#include "vehicle2/roadGeometry/PxVehicleRoadGeometryState.h"
42#include "vehicle2/wheel/PxVehicleWheelParams.h"
43
44#include "PxVehicleSuspensionParams.h"
45#include "PxVehicleSuspensionStates.h"
46#include "PxVehicleSuspensionFunctions.h"
47
48#include "common/PxProfileZone.h"
49
50#if !PX_DOXYGEN
51namespace physx
52{
53namespace vehicle2
54{
55#endif
56
57
59{
60public:
61
64
100 const PxVehicleAxleDescription*& axleDescription,
101 const PxVehicleRigidBodyParams*& rigidBodyParams,
102 const PxVehicleSuspensionStateCalculationParams*& suspensionStateCalculationParams,
103 PxVehicleArrayData<const PxReal>& steerResponseStates,
104 const PxVehicleRigidBodyState*& rigidBodyState,
114 PxVehicleAntiRollTorque*& antiRollTorque) = 0;
115
124 virtual bool update(const PxReal dt, const PxVehicleSimulationContext& context)
125 {
126 PX_PROFILE_ZONE("PxVehicleSuspensionComponent::update", 0);
127
128 const PxVehicleAxleDescription* axleDescription;
129 const PxVehicleRigidBodyParams* rigidBodyParams;
130 const PxVehicleSuspensionStateCalculationParams* suspensionStateCalculationParams;
131 PxVehicleArrayData<const PxReal> steerResponseStates;
132 const PxVehicleRigidBodyState* rigidBodyState;
142 PxVehicleAntiRollTorque* antiRollTorque;
143
144 getDataForSuspensionComponent(axleDescription, rigidBodyParams, suspensionStateCalculationParams,
145 steerResponseStates, rigidBodyState,
146 wheelParams, suspensionParams,
147 suspensionComplianceParams, suspensionForceParams, antiRollForceParams,
148 wheelRoadGeomStates, suspensionStates, suspensionComplianceStates,
149 suspensionForces, antiRollTorque);
150
151 for (PxU32 i = 0; i < axleDescription->nbWheels; i++)
152 {
153 const PxU32 wheelId = axleDescription->wheelIdsInAxleOrder[i];
154
155 //Update the suspension state (jounce, jounce speed)
156 PxVehicleSuspensionStateUpdate(
157 wheelParams[wheelId], suspensionParams[wheelId], *suspensionStateCalculationParams,
158 suspensionForceParams[wheelId].stiffness, suspensionForceParams[wheelId].damping,
159 steerResponseStates[wheelId], wheelRoadGeomStates[wheelId],
160 *rigidBodyState,
161 dt, context.frame, context.gravity,
162 suspensionStates[wheelId]);
163
164 //Update the compliance from the suspension state.
165 PxVehicleSuspensionComplianceUpdate(
166 suspensionParams[wheelId], suspensionComplianceParams[wheelId],
167 suspensionStates[wheelId],
168 suspensionComplianceStates[wheelId]);
169
170 //Compute the suspension force from the suspension and compliance states.
171 PxVehicleSuspensionForceUpdate(
172 suspensionParams[wheelId], suspensionForceParams[wheelId],
173 wheelRoadGeomStates[wheelId], suspensionStates[wheelId],
174 suspensionComplianceStates[wheelId], *rigidBodyState,
175 context.gravity, rigidBodyParams->mass,
176 suspensionForces[wheelId]);
177 }
178
179 if (antiRollForceParams.size>0 && antiRollTorque)
180 {
181 PxVehicleAntiRollForceUpdate(
182 suspensionParams, antiRollForceParams,
183 suspensionStates.getConst(), suspensionComplianceStates.getConst(), *rigidBodyState,
184 *antiRollTorque);
185 }
186
187 return true;
188 }
189};
190
195{
196public:
197
200
234 const PxVehicleAxleDescription*& axleDescription,
235 const PxVehicleSuspensionStateCalculationParams*& suspensionStateCalculationParams,
236 PxVehicleArrayData<const PxReal>& steerResponseStates,
237 const PxVehicleRigidBodyState*& rigidBodyState,
247 PxVehicleAntiRollTorque*& antiRollTorque) = 0;
248
258 virtual bool update(const PxReal dt, const PxVehicleSimulationContext& context)
259 {
260 PX_PROFILE_ZONE("PxVehicleLegacySuspensionComponent::update", 0);
261
262 const PxVehicleAxleDescription* axleDescription;
263 const PxVehicleSuspensionStateCalculationParams* suspensionStateCalculationParams;
264 PxVehicleArrayData<const PxReal> steerResponseStates;
265 const PxVehicleRigidBodyState* rigidBodyState;
275 PxVehicleAntiRollTorque* antiRollTorque;
276
277 getDataForLegacySuspensionComponent(axleDescription, suspensionStateCalculationParams,
278 steerResponseStates, rigidBodyState, wheelParams,
279 suspensionParams, suspensionComplianceParams,
280 suspensionForceParams, antiRollForceParams,
281 wheelRoadGeomStates, suspensionStates, suspensionComplianceStates,
282 suspensionForces, antiRollTorque);
283
284 for (PxU32 i = 0; i < axleDescription->nbWheels; i++)
285 {
286 const PxU32 wheelId = axleDescription->wheelIdsInAxleOrder[i];
287
288 //Update the suspension state (jounce, jounce speed)
289 PxVehicleSuspensionStateUpdate(
290 wheelParams[wheelId], suspensionParams[wheelId], *suspensionStateCalculationParams,
291 suspensionForceParams[wheelId].stiffness, suspensionForceParams[wheelId].damping,
292 steerResponseStates[wheelId], wheelRoadGeomStates[wheelId], *rigidBodyState,
293 dt, context.frame, context.gravity,
294 suspensionStates[wheelId]);
295
296 //Update the compliance from the suspension state.
297 PxVehicleSuspensionComplianceUpdate(
298 suspensionParams[wheelId], suspensionComplianceParams[wheelId],
299 suspensionStates[wheelId],
300 suspensionComplianceStates[wheelId]);
301
302 //Compute the suspension force from the suspension and compliance states.
303 PxVehicleSuspensionLegacyForceUpdate(
304 suspensionParams[wheelId], suspensionForceParams[wheelId],
305 wheelRoadGeomStates[wheelId], suspensionStates[wheelId],
306 suspensionComplianceStates[wheelId], *rigidBodyState,
307 context.gravity,
308 suspensionForces[wheelId]);
309 }
310
311 if (antiRollForceParams.size>0 && antiRollTorque)
312 {
313 PxVehicleAntiRollForceUpdate(
314 suspensionParams, antiRollForceParams,
315 suspensionStates.getConst(), suspensionComplianceStates.getConst(), *rigidBodyState,
316 *antiRollTorque);
317 }
318
319 return true;
320 }
321};
322
323#if !PX_DOXYGEN
324} // namespace vehicle2
325} // namespace physx
326#endif
327
Definition base.h:1940
Definition PxVehicleComponent.h:45
Definition PxVehicleSuspensionComponents.h:195
virtual void getDataForLegacySuspensionComponent(const PxVehicleAxleDescription *&axleDescription, const PxVehicleSuspensionStateCalculationParams *&suspensionStateCalculationParams, PxVehicleArrayData< const PxReal > &steerResponseStates, const PxVehicleRigidBodyState *&rigidBodyState, PxVehicleArrayData< const PxVehicleWheelParams > &wheelParams, PxVehicleArrayData< const PxVehicleSuspensionParams > &suspensionParams, PxVehicleArrayData< const PxVehicleSuspensionComplianceParams > &suspensionComplianceParams, PxVehicleArrayData< const PxVehicleSuspensionForceLegacyParams > &suspensionForceParams, PxVehicleSizedArrayData< const PxVehicleAntiRollForceParams > &antiRollForceParams, PxVehicleArrayData< const PxVehicleRoadGeometryState > &wheelRoadGeomStates, PxVehicleArrayData< PxVehicleSuspensionState > &suspensionStates, PxVehicleArrayData< PxVehicleSuspensionComplianceState > &suspensionComplianceStates, PxVehicleArrayData< PxVehicleSuspensionForce > &suspensionForces, PxVehicleAntiRollTorque *&antiRollTorque)=0
Retrieve pointers to the parameter and state data required to compute the suspension state and the fo...
virtual bool update(const PxReal dt, const PxVehicleSimulationContext &context)
Update the suspension state and suspension compliance state and use those updated states to compute s...
Definition PxVehicleSuspensionComponents.h:258
Definition PxVehicleSuspensionComponents.h:59
virtual void getDataForSuspensionComponent(const PxVehicleAxleDescription *&axleDescription, const PxVehicleRigidBodyParams *&rigidBodyParams, const PxVehicleSuspensionStateCalculationParams *&suspensionStateCalculationParams, PxVehicleArrayData< const PxReal > &steerResponseStates, const PxVehicleRigidBodyState *&rigidBodyState, PxVehicleArrayData< const PxVehicleWheelParams > &wheelParams, PxVehicleArrayData< const PxVehicleSuspensionParams > &suspensionParams, PxVehicleArrayData< const PxVehicleSuspensionComplianceParams > &suspensionComplianceParams, PxVehicleArrayData< const PxVehicleSuspensionForceParams > &suspensionForceParams, PxVehicleSizedArrayData< const PxVehicleAntiRollForceParams > &antiRollForceParams, PxVehicleArrayData< const PxVehicleRoadGeometryState > &wheelRoadGeomStates, PxVehicleArrayData< PxVehicleSuspensionState > &suspensionStates, PxVehicleArrayData< PxVehicleSuspensionComplianceState > &suspensionComplianceStates, PxVehicleArrayData< PxVehicleSuspensionForce > &suspensionForces, PxVehicleAntiRollTorque *&antiRollTorque)=0
Retrieve pointers to the parameter and state data required to compute the suspension state and the fo...
virtual bool update(const PxReal dt, const PxVehicleSimulationContext &context)
Update the suspension state and suspension compliance state and use those updated states to compute s...
Definition PxVehicleSuspensionComponents.h:124
#define PX_DEPRECATED
Definition PxPreprocessor.h:418
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
The anti-roll torque of all anti-roll bars accumulates in a single torque to apply to the vehicle's r...
Definition PxVehicleSuspensionStates.h:168
Helper struct to pass array type data to vehice components and functions.
Definition PxVehicleParams.h:249
PX_FORCE_INLINE const PxVehicleArrayData< const T > & getConst() const
Get a reference to the array but read only.
Definition PxVehicleParams.h:353
Definition PxVehicleParams.h:53
PxU32 wheelIdsInAxleOrder[PxVehicleLimits::eMAX_NB_WHEELS]
The list of all wheel ids on the vehicle.
Definition PxVehicleParams.h:149
PxU32 nbWheels
The number of wheels on the vehicle.
Definition PxVehicleParams.h:150
The properties of the rigid body.
Definition PxVehicleRigidBodyParams.h:50
PxReal mass
The mass of the rigid body.
Definition PxVehicleRigidBodyParams.h:57
Definition PxVehicleRigidBodyStates.h:47
Definition PxVehicleParams.h:672
Definition PxVehicleParams.h:369
Definition PxVehicleSuspensionParams.h:113