RavEngine
Loading...
Searching...
No Matches
Base.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
31#include "vehicle2/PxVehicleAPI.h"
32
33namespace snippetvehicle2
34{
35
36using namespace physx;
37using namespace physx::vehicle2;
38
40{
41 PxVehicleAxleDescription axleDescription;
42 PxVehicleFrame frame;
43 PxVehicleScale scale;
44 PxVehicleSuspensionStateCalculationParams suspensionStateCalculationParams;
45
46 //Command response
47 PxVehicleBrakeCommandResponseParams brakeResponseParams[2];
48 PxVehicleSteerCommandResponseParams steerResponseParams;
49 PxVehicleAckermannParams ackermannParams[1];
50
51 //Suspension
52 PxVehicleSuspensionParams suspensionParams[PxVehicleLimits::eMAX_NB_WHEELS];
53 PxVehicleSuspensionComplianceParams suspensionComplianceParams[PxVehicleLimits::eMAX_NB_WHEELS];
54 PxVehicleSuspensionForceParams suspensionForceParams[PxVehicleLimits::eMAX_NB_WHEELS];
55
56 //Tires
57 PxVehicleTireForceParams tireForceParams[PxVehicleLimits::eMAX_NB_WHEELS];
58
59 //Wheels
60 PxVehicleWheelParams wheelParams[PxVehicleLimits::eMAX_NB_WHEELS];
61
62 //Rigid body
63 PxVehicleRigidBodyParams rigidBodyParams;
64
65 BaseVehicleParams transformAndScale(
66 const PxVehicleFrame& srcFrame, const PxVehicleFrame& trgFrame, const PxVehicleScale& srcScale, const PxVehicleScale& trgScale) const;
67
68 PX_FORCE_INLINE bool isValid() const
69 {
70 if (!axleDescription.isValid())
71 return false;
72 if (!frame.isValid())
73 return true;
74 if (!scale.isValid())
75 return false;
76 if (!suspensionStateCalculationParams.isValid())
77 return false;
78
79 if (!brakeResponseParams[0].isValid(axleDescription))
80 return false;
81 if (!brakeResponseParams[1].isValid(axleDescription))
82 return false;
83 if (!steerResponseParams.isValid(axleDescription))
84 return false;
85 if (!ackermannParams[0].isValid(axleDescription))
86 return false;
87
88 for (PxU32 i = 0; i < axleDescription.nbWheels; i++)
89 {
90 const PxU32 wheelId = axleDescription.wheelIdsInAxleOrder[i];
91
92 if (!suspensionParams[wheelId].isValid())
93 return false;
94 if (!suspensionComplianceParams[wheelId].isValid())
95 return false;
96 if (!suspensionForceParams[wheelId].isValid())
97 return false;
98
99 if (!tireForceParams[wheelId].isValid())
100 return false;
101
102 if (!wheelParams[wheelId].isValid())
103 return false;
104 }
105
106 if (!rigidBodyParams.isValid())
107 return false;
108
109 return true;
110 }
111};
112
114{
115 //Command responses
116 PxReal brakeCommandResponseStates[PxVehicleLimits::eMAX_NB_WHEELS];
117 PxReal steerCommandResponseStates[PxVehicleLimits::eMAX_NB_WHEELS];
118 PxVehicleWheelActuationState actuationStates[PxVehicleLimits::eMAX_NB_WHEELS];
119
120 //Road geometry
121 PxVehicleRoadGeometryState roadGeomStates[PxVehicleLimits::eMAX_NB_WHEELS];
122
123 //Suspensions
124 PxVehicleSuspensionState suspensionStates[PxVehicleLimits::eMAX_NB_WHEELS];
125 PxVehicleSuspensionComplianceState suspensionComplianceStates[PxVehicleLimits::eMAX_NB_WHEELS];
126 PxVehicleSuspensionForce suspensionForces[PxVehicleLimits::eMAX_NB_WHEELS];
127
128 //Tires
129 PxVehicleTireGripState tireGripStates[PxVehicleLimits::eMAX_NB_WHEELS];
130 PxVehicleTireDirectionState tireDirectionStates[PxVehicleLimits::eMAX_NB_WHEELS];
131 PxVehicleTireSpeedState tireSpeedStates[PxVehicleLimits::eMAX_NB_WHEELS];
132 PxVehicleTireSlipState tireSlipStates[PxVehicleLimits::eMAX_NB_WHEELS];
133 PxVehicleTireCamberAngleState tireCamberAngleStates[PxVehicleLimits::eMAX_NB_WHEELS];
134 PxVehicleTireStickyState tireStickyStates[PxVehicleLimits::eMAX_NB_WHEELS];
135 PxVehicleTireForce tireForces[PxVehicleLimits::eMAX_NB_WHEELS];
136
137 //Wheels
138 PxVehicleWheelRigidBody1dState wheelRigidBody1dStates[PxVehicleLimits::eMAX_NB_WHEELS];
139 PxVehicleWheelLocalPose wheelLocalPoses[PxVehicleLimits::eMAX_NB_WHEELS];
140
141 //Rigid body
142 PxVehicleRigidBodyState rigidBodyState;
143
144 PX_FORCE_INLINE void setToDefault()
145 {
146 for (unsigned int i = 0; i < PxVehicleLimits::eMAX_NB_WHEELS; i++)
147 {
148 brakeCommandResponseStates[i] = 0.0;
149 steerCommandResponseStates[i] = 0.0f;
150
151 actuationStates[i].setToDefault();
152
153 roadGeomStates[i].setToDefault();
154
155 suspensionStates[i].setToDefault();
156 suspensionComplianceStates[i].setToDefault();
157 suspensionForces[i].setToDefault();
158
159 tireGripStates[i].setToDefault();
160 tireDirectionStates[i].setToDefault();
161 tireSpeedStates[i].setToDefault();
162 tireSlipStates[i].setToDefault();
163 tireCamberAngleStates[i].setToDefault();
164 tireStickyStates[i].setToDefault();
165 tireForces[i].setToDefault();
166
167 wheelRigidBody1dStates[i].setToDefault();
168 wheelLocalPoses[i].setToDefault();
169 }
170
171 rigidBodyState.setToDefault();
172 }
173};
174
175
176//
177//The PhysX Vehicle SDK was designed to offer flexibility on how to combine data and logic
178//to implement a vehicle. For the purpose of the snippets, different vehicle types are
179//represented using a class hierarchy to share base functionality and data. The vehicle
180//classes implement the component interfaces directly such that no separate component
181//objects are needed. If the goal was to focus more on modularity, each component
182//could be defined as its own class but those classes would need to reference all the
183//data necessary to run the component logic.
184//This specific class deals with the mechanical base of a vehicle (suspension, tire,
185//wheel, vehicle body etc.).
186//
192{
193public:
194 bool initialize();
195 virtual void destroy() {}
196
197 //To be implemented by specific vehicle types that are built on top of this class.
198 //The specific vehicle type defines what components to run and in what order.
199 virtual void initComponentSequence(bool addPhysXBeginEndComponents) = 0;
200
201 //Run a simulation step
202 void step(const PxReal dt, const PxVehicleSimulationContext& context);
203
205 const PxVehicleAxleDescription*& axleDescription,
206 const PxVehicleRigidBodyParams*& rigidBodyParams,
209 const PxVehicleAntiRollTorque*& antiRollTorque,
210 PxVehicleRigidBodyState*& rigidBodyState)
211 {
212 axleDescription = &mBaseParams.axleDescription;
213 rigidBodyParams = &mBaseParams.rigidBodyParams;
214 suspensionForces.setData(mBaseState.suspensionForces);
215 tireForces.setData(mBaseState.tireForces);
216 antiRollTorque = NULL;
217 rigidBodyState = &mBaseState.rigidBodyState;
218 }
219
221 const PxVehicleAxleDescription*& axleDescription,
222 const PxVehicleRigidBodyParams*& rigidBodyParams,
223 const PxVehicleSuspensionStateCalculationParams*& suspensionStateCalculationParams,
224 PxVehicleArrayData<const PxReal>& steerResponseStates,
225 const PxVehicleRigidBodyState*& rigidBodyState,
235 PxVehicleAntiRollTorque*& antiRollTorque)
236 {
237 axleDescription = &mBaseParams.axleDescription;
238 rigidBodyParams = &mBaseParams.rigidBodyParams;
239 suspensionStateCalculationParams = &mBaseParams.suspensionStateCalculationParams;
240 steerResponseStates.setData(mBaseState.steerCommandResponseStates);
241 rigidBodyState = &mBaseState.rigidBodyState;
242 wheelParams.setData(mBaseParams.wheelParams);
243 suspensionParams.setData(mBaseParams.suspensionParams);
244 suspensionComplianceParams.setData(mBaseParams.suspensionComplianceParams);
245 suspensionForceParams.setData(mBaseParams.suspensionForceParams);
246 antiRollForceParams.setEmpty();
247 wheelRoadGeomStates.setData(mBaseState.roadGeomStates);
248 suspensionStates.setData(mBaseState.suspensionStates);
249 suspensionComplianceStates.setData(mBaseState.suspensionComplianceStates);
250 suspensionForces.setData(mBaseState.suspensionForces);
251 antiRollTorque = NULL;
252 }
253
254 virtual void getDataForTireComponent(
255 const PxVehicleAxleDescription*& axleDescription,
256 PxVehicleArrayData<const PxReal>& steerResponseStates,
257 const PxVehicleRigidBodyState*& rigidBodyState,
274 {
275 axleDescription = &mBaseParams.axleDescription;
276 steerResponseStates.setData(mBaseState.steerCommandResponseStates);
277 rigidBodyState = &mBaseState.rigidBodyState;
278 actuationStates.setData(mBaseState.actuationStates);
279 wheelParams.setData(mBaseParams.wheelParams);
280 suspensionParams.setData(mBaseParams.suspensionParams);
281 tireForceParams.setData(mBaseParams.tireForceParams);
282 roadGeomStates.setData(mBaseState.roadGeomStates);
283 suspensionStates.setData(mBaseState.suspensionStates);
284 suspensionComplianceStates.setData(mBaseState.suspensionComplianceStates);
285 suspensionForces.setData(mBaseState.suspensionForces);
286 wheelRigidBody1DStates.setData(mBaseState.wheelRigidBody1dStates);
287 tireGripStates.setData(mBaseState.tireGripStates);
288 tireDirectionStates.setData(mBaseState.tireDirectionStates);
289 tireSpeedStates.setData(mBaseState.tireSpeedStates);
290 tireSlipStates.setData(mBaseState.tireSlipStates);
291 tireCamberAngleStates.setData(mBaseState.tireCamberAngleStates);
292 tireStickyStates.setData(mBaseState.tireStickyStates);
293 tireForces.setData(mBaseState.tireForces);
294 }
295
296 virtual void getDataForWheelComponent(
297 const PxVehicleAxleDescription*& axleDescription,
298 PxVehicleArrayData<const PxReal>& steerResponseStates,
307 {
308 axleDescription = &mBaseParams.axleDescription;
309 steerResponseStates.setData(mBaseState.steerCommandResponseStates);
310 wheelParams.setData(mBaseParams.wheelParams);
311 suspensionParams.setData(mBaseParams.suspensionParams);
312 actuationStates.setData(mBaseState.actuationStates);
313 suspensionStates.setData(mBaseState.suspensionStates);
314 suspensionComplianceStates.setData(mBaseState.suspensionComplianceStates);
315 tireSpeedStates.setData(mBaseState.tireSpeedStates);
316 wheelRigidBody1dStates.setData(mBaseState.wheelRigidBody1dStates);
317 wheelLocalPoses.setData(mBaseState.wheelLocalPoses);
318 }
319
320
321 //Parameters and statess of the vehicle's mechanical base.
322 BaseVehicleParams mBaseParams;
323 BaseVehicleState mBaseState;
324
325 //The sequence of components that will simulate the vehicle.
326 //To be assembled by specific vehicle types that are built
327 //on top of this class
328 PxVehicleComponentSequence mComponentSequence;
329
330 //A sub-group of components can be simulated with multiple substeps
331 //to improve simulation fidelity without running the full sequence
332 //at a lower timestep.
333 PxU8 mComponentSequenceSubstepGroupHandle;
334};
335
336}//namespace snippetvehicle2
Definition base.h:1940
Forward integrate the momentum and pose of the vehicle's rigid body after applying forces and torques...
Definition PxVehicleRigidBodyComponents.h:53
Definition PxVehicleSuspensionComponents.h:59
Definition PxVehicleTireComponents.h:57
Definition PxVehicleWheelComponents.h:54
Definition Base.h:192
virtual void getDataForRigidBodyComponent(const PxVehicleAxleDescription *&axleDescription, const PxVehicleRigidBodyParams *&rigidBodyParams, PxVehicleArrayData< const PxVehicleSuspensionForce > &suspensionForces, PxVehicleArrayData< const PxVehicleTireForce > &tireForces, const PxVehicleAntiRollTorque *&antiRollTorque, PxVehicleRigidBodyState *&rigidBodyState)
Retrieve pointers to the parameter and state data required to update the dynamic state of a rigid bod...
Definition Base.h:204
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)
Retrieve pointers to the parameter and state data required to compute the suspension state and the fo...
Definition Base.h:220
#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
A description of a single axle that is to be affected by Ackermann steer correction.
Definition PxVehicleSteeringParams.h:86
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 void setData(T *data)
Set the data as an array of structs.
Definition PxVehicleParams.h:261
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
Distribute a brake response to the wheels of a vehicle.
Definition PxVehicleBrakingParams.h:56
Definition PxVehicleComponentSequence.h:57
Definition PxVehicleParams.h:174
The properties of the rigid body.
Definition PxVehicleRigidBodyParams.h:50
Definition PxVehicleRigidBodyStates.h:47
Definition PxVehicleRoadGeometryState.h:46
Definition PxVehicleParams.h:224
Definition PxVehicleParams.h:672
Definition PxVehicleParams.h:369
PX_FORCE_INLINE void setEmpty()
Set as empty.
Definition PxVehicleParams.h:397
Distribute a steer response to the wheels of a vehicle.
Definition PxVehicleSteeringParams.h:58
Compliance describes how toe and camber angle and force application points are affected by suspension...
Definition PxVehicleSuspensionParams.h:155
The effect of suspension compliance on toe and camber angle and on the tire and suspension force appl...
Definition PxVehicleSuspensionStates.h:97
Suspension force is computed by converting suspenson state to suspension force under the assumption o...
Definition PxVehicleSuspensionParams.h:236
The force and torque for a single suspension to apply to the vehicle's rigid body.
Definition PxVehicleSuspensionStates.h:132
Definition PxVehicleSuspensionParams.h:51
Definition PxVehicleSuspensionParams.h:113
Definition PxVehicleSuspensionStates.h:53
Camber angle of the tire relative to the ground plane.
Definition PxVehicleTireStates.h:118
PxVehicleTireDirectionState stores the world frame lateral and longtidinal axes of the tire after pro...
Definition PxVehicleTireStates.h:52
Definition PxVehicleTireParams.h:49
The longitudinal/lateral forces/torques that develop on the tire.
Definition PxVehicleTireStates.h:148
The load and friction experienced by a tire.
Definition PxVehicleTireStates.h:95
The lateral and longitudinal tire slips.
Definition PxVehicleTireStates.h:82
PxVehicleTireSpeedState stores the components of the instantaneous velocity of the rigid body at the ...
Definition PxVehicleTireStates.h:68
Prolonged low speeds in the lateral and longitudinal directions may be handled with "sticky" velocity...
Definition PxVehicleTireStates.h:134
It is useful to know if a brake or drive torque is to be applied to a wheel.
Definition PxVehicleWheelStates.h:50
Definition PxVehicleWheelStates.h:94
Definition PxVehicleWheelParams.h:47
Definition PxVehicleWheelStates.h:61