RavEngine
Loading...
Searching...
No Matches
PxVehiclePvdComponents.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/PxVehicleComponent.h"
36#include "vehicle2/PxVehicleParams.h"
37#include "PxVehiclePvdFunctions.h"
38
39#if !PX_DOXYGEN
40namespace physx
41{
42namespace vehicle2
43{
44#endif
45
46#define VEHICLE_FLOAT_ARRAY_DATA(b) PxVehicleArrayData<PxReal> b; b.setEmpty();
47#define VEHICLE_ARRAY_DATA(a, b) PxVehicleArrayData<const a> b; b.setEmpty();
48#define VEHICLE_SIZED_ARRAY_DATA(a, b) PxVehicleSizedArrayData<const a> b; b.setEmpty();
49
51{
52public:
53
54 PxVehiclePVDComponent() : PxVehicleComponent() , firstTime(true) {}
55 virtual ~PxVehiclePVDComponent() {}
56
57 virtual void getDataForPVDComponent(
58 const PxVehicleAxleDescription*& axleDescription,
59 const PxVehicleRigidBodyParams*& rbodyParams, const PxVehicleRigidBodyState*& rbodyState,
60 const PxVehicleSuspensionStateCalculationParams*& suspStateCalcParams,
62 const PxVehicleSteerCommandResponseParams*& steerResponseParams,
63 PxVehicleArrayData<PxReal>& brakeResponseStates,
64 PxVehicleArrayData<PxReal>& steerResponseStates,
85 const PxVehicleAntiRollTorque*& antiRollTorque,
86 const PxVehicleCommandState*& commandState,
87 const PxVehicleDirectDriveThrottleCommandResponseParams*& directDriveThrottleResponseParams,
88 const PxVehicleDirectDriveTransmissionCommandState*& directDriveTransmissionState,
89 PxVehicleArrayData<PxReal>& directDrivethrottleResponseState,
90 const PxVehicleClutchCommandResponseParams*& clutchResponseParams,
91 const PxVehicleClutchParams*& clutchParams,
92 const PxVehicleEngineParams*& engineParams,
93 const PxVehicleGearboxParams*& gearboxParams,
94 const PxVehicleAutoboxParams*& autoboxParams,
95 const PxVehicleMultiWheelDriveDifferentialParams*& multiWheelDiffParams,
96 const PxVehicleFourWheelDriveDifferentialParams*& fourWheelDiffParams,
97 const PxVehicleEngineDriveTransmissionCommandState*& engineDriveTransmissionState,
98 const PxVehicleClutchCommandResponseState*& clutchResponseState,
99 const PxVehicleEngineDriveThrottleCommandResponseState*& engineDriveThrottleResponseState,
100 const PxVehicleEngineState*& engineState,
101 const PxVehicleGearboxState*& gearboxState,
102 const PxVehicleAutoboxState*& autoboxState,
103 const PxVehicleDifferentialState*& diffState,
104 const PxVehicleClutchSlipState*& clutchSlipState,
107 const PxVehiclePhysXActor*& physxActor,
108 const PxVehiclePhysXRoadGeometryQueryParams*& physxRoadGeomQryParams,
111 PxVehiclePvdObjectHandles*& objectHandles) = 0;
112
113 virtual bool update(const PxReal dt, const PxVehicleSimulationContext& context)
114 {
115 PX_UNUSED(dt);
116 PX_UNUSED(context);
117
118 if(!context.pvdContext.attributeHandles || !context.pvdContext.writer)
119 return true;
120
121 const PxVehicleAxleDescription* axleDesc = NULL;
122 const PxVehicleRigidBodyParams* rbodyParams = NULL;
123 const PxVehicleRigidBodyState* rbodyState = NULL;
124 const PxVehicleSuspensionStateCalculationParams* suspStateCalcParams = NULL;
125 VEHICLE_SIZED_ARRAY_DATA(PxVehicleBrakeCommandResponseParams, brakeResponseParams);
126 const PxVehicleSteerCommandResponseParams* steerResponseParams = NULL;
127 VEHICLE_FLOAT_ARRAY_DATA(brakeResponseStates);
128 VEHICLE_FLOAT_ARRAY_DATA(steerResponseStates);
129 VEHICLE_ARRAY_DATA(PxVehicleWheelParams, wheelParams);
130 VEHICLE_ARRAY_DATA(PxVehicleWheelActuationState, wheelActuationStates);
131 VEHICLE_ARRAY_DATA(PxVehicleWheelRigidBody1dState, wheelRigidBody1dStates);
132 VEHICLE_ARRAY_DATA(PxVehicleWheelLocalPose, wheelLocalPoses);
133 VEHICLE_ARRAY_DATA(PxVehicleRoadGeometryState, roadGeomStates);
134 VEHICLE_ARRAY_DATA(PxVehicleSuspensionParams, suspParams);
135 VEHICLE_ARRAY_DATA(PxVehicleSuspensionComplianceParams, suspComplianceParams);
136 VEHICLE_ARRAY_DATA(PxVehicleSuspensionForceParams, suspForceParams);
137 VEHICLE_ARRAY_DATA(PxVehicleSuspensionState, suspStates);
138 VEHICLE_ARRAY_DATA(PxVehicleSuspensionComplianceState, suspComplianceStates);
139 VEHICLE_ARRAY_DATA(PxVehicleSuspensionForce, suspForces);
140 VEHICLE_ARRAY_DATA(PxVehicleTireForceParams, tireForceParams);
141 VEHICLE_ARRAY_DATA(PxVehicleTireDirectionState, tireDirectionStates);
142 VEHICLE_ARRAY_DATA(PxVehicleTireSpeedState, tireSpeedStates);
143 VEHICLE_ARRAY_DATA(PxVehicleTireSlipState, tireSlipStates);
144 VEHICLE_ARRAY_DATA(PxVehicleTireStickyState, tireStickyStates);
145 VEHICLE_ARRAY_DATA(PxVehicleTireGripState, tireGripStates);
146 VEHICLE_ARRAY_DATA(PxVehicleTireCamberAngleState, tireCamberStates);
147 VEHICLE_ARRAY_DATA(PxVehicleTireForce, tireForces);
148 VEHICLE_SIZED_ARRAY_DATA(PxVehicleAntiRollForceParams, antiRollParams);
149 const PxVehicleAntiRollTorque* antiRollTorque = NULL;
150 const PxVehicleCommandState* commandState = NULL;
151 const PxVehicleDirectDriveThrottleCommandResponseParams* directDriveThrottleResponseParams = NULL;
152 const PxVehicleDirectDriveTransmissionCommandState* directDriveTransmissionState = NULL;
153 VEHICLE_FLOAT_ARRAY_DATA(directDrivethrottleResponseState);
154 const PxVehicleClutchCommandResponseParams* clutchResponseParams = NULL;
155 const PxVehicleClutchParams* clutchParams = NULL;
156 const PxVehicleEngineParams* engineParams = NULL;
157 const PxVehicleGearboxParams* gearboxParams = NULL;
158 const PxVehicleAutoboxParams* autoboxParams = NULL;
159 const PxVehicleMultiWheelDriveDifferentialParams* multiWheelDiffParams = NULL;
160 const PxVehicleFourWheelDriveDifferentialParams* fourWheelDiffParams = NULL;
161 const PxVehicleEngineDriveTransmissionCommandState* engineDriveTransmissionCommandState = NULL;
162 const PxVehicleClutchCommandResponseState* clutchResponseState = NULL;
163 const PxVehicleEngineDriveThrottleCommandResponseState* throttleResponseState = NULL;
164 const PxVehicleEngineState* engineState = NULL;
165 const PxVehicleGearboxState* gearboxState = NULL;
166 const PxVehicleAutoboxState* autoboxState = NULL;
167 const PxVehicleDifferentialState* diffState = NULL;
168 const PxVehicleClutchSlipState* clutchSlipState = NULL;
169 VEHICLE_ARRAY_DATA(PxVehiclePhysXSuspensionLimitConstraintParams, physxConstraintParams);
170 VEHICLE_ARRAY_DATA(PxVehiclePhysXMaterialFrictionParams, physxMaterialFrictionParams);
171 const PxVehiclePhysXActor* physxActor = NULL;
172 const PxVehiclePhysXRoadGeometryQueryParams* physxRoadGeomQryParams = NULL;
173 VEHICLE_ARRAY_DATA(PxVehiclePhysXRoadGeometryQueryState, physxRoadGeomStates);
174 VEHICLE_ARRAY_DATA(PxVehiclePhysXConstraintState, physxConstraintStates);
175 PxVehiclePvdObjectHandles* omniPvdObjectHandles = NULL;
176
177 getDataForPVDComponent(
178 axleDesc,
179 rbodyParams, rbodyState,
180 suspStateCalcParams,
181 brakeResponseParams, steerResponseParams,
182 brakeResponseStates, steerResponseStates,
183 wheelParams,
184 wheelActuationStates, wheelRigidBody1dStates, wheelLocalPoses,
185 roadGeomStates,
186 suspParams, suspComplianceParams, suspForceParams,
187 suspStates, suspComplianceStates,
188 suspForces,
189 tireForceParams,
190 tireDirectionStates, tireSpeedStates, tireSlipStates, tireStickyStates, tireGripStates, tireCamberStates,
191 tireForces,
192 antiRollParams, antiRollTorque,
193 commandState,
194 directDriveThrottleResponseParams, directDriveTransmissionState, directDrivethrottleResponseState,
195 clutchResponseParams, clutchParams, engineParams, gearboxParams, autoboxParams, multiWheelDiffParams, fourWheelDiffParams,
196 engineDriveTransmissionCommandState,
197 clutchResponseState, throttleResponseState, engineState, gearboxState, autoboxState, diffState, clutchSlipState,
198 physxConstraintParams, physxMaterialFrictionParams,
199 physxActor, physxRoadGeomQryParams, physxRoadGeomStates, physxConstraintStates,
200 omniPvdObjectHandles);
201
202 if(!omniPvdObjectHandles)
203 return true;
204
205 if(firstTime)
206 {
207 PxVehiclePvdRigidBodyRegister(
208 rbodyParams, rbodyState,
209 *context.pvdContext.attributeHandles, omniPvdObjectHandles, context.pvdContext.writer);
210
211 PxVehiclePvdSuspensionStateCalculationParamsRegister(
212 suspStateCalcParams,
213 *context.pvdContext.attributeHandles, omniPvdObjectHandles, context.pvdContext.writer);
214
215 PxVehiclePvdCommandResponseRegister(
216 brakeResponseParams, steerResponseParams,
217 brakeResponseStates, steerResponseStates,
218 *context.pvdContext.attributeHandles, omniPvdObjectHandles, context.pvdContext.writer);
219
220 PxVehiclePvdWheelAttachmentsRegister(
221 *axleDesc,
222 wheelParams, wheelActuationStates, wheelRigidBody1dStates, wheelLocalPoses,
223 roadGeomStates,
224 suspParams, suspComplianceParams, suspForceParams, suspStates, suspComplianceStates,
225 suspForces,
226 tireForceParams,
227 tireDirectionStates, tireSpeedStates, tireSlipStates, tireStickyStates, tireGripStates, tireCamberStates,
228 tireForces,
229 *context.pvdContext.attributeHandles, omniPvdObjectHandles, context.pvdContext.writer);
230
231 PxVehiclePvdAntiRollsRegister(
232 antiRollParams, antiRollTorque,
233 *context.pvdContext.attributeHandles, omniPvdObjectHandles, context.pvdContext.writer);
234
235 PxVehiclePvdDirectDrivetrainRegister(
236 commandState, directDriveTransmissionState,
237 directDriveThrottleResponseParams,
238 directDrivethrottleResponseState,
239 *context.pvdContext.attributeHandles, omniPvdObjectHandles, context.pvdContext.writer);
240
241 PxVehiclePvdEngineDrivetrainRegister(
242 commandState, engineDriveTransmissionCommandState,
243 clutchResponseParams, clutchParams, engineParams, gearboxParams, autoboxParams, multiWheelDiffParams, fourWheelDiffParams,
244 clutchResponseState, throttleResponseState, engineState, gearboxState, autoboxState, diffState, clutchSlipState,
245 *context.pvdContext.attributeHandles, omniPvdObjectHandles, context.pvdContext.writer);
246
247 PxVehiclePvdPhysXWheelAttachmentRegister(
248 *axleDesc,
249 physxConstraintParams, physxMaterialFrictionParams,
250 physxActor, physxRoadGeomQryParams, physxRoadGeomStates, physxConstraintStates,
251 *context.pvdContext.attributeHandles, omniPvdObjectHandles, context.pvdContext.writer);
252
253 PxVehiclePvdPhysXRigidActorRegister(
254 physxActor,
255 *context.pvdContext.attributeHandles, omniPvdObjectHandles, context.pvdContext.writer);
256
257 firstTime = false;
258 }
259
260 PxVehiclePvdRigidBodyWrite(
261 rbodyParams, rbodyState,
262 *context.pvdContext.attributeHandles, *omniPvdObjectHandles, context.pvdContext.writer);
263
264 PxVehiclePvdSuspensionStateCalculationParamsWrite(
265 suspStateCalcParams,
266 *context.pvdContext.attributeHandles, *omniPvdObjectHandles, context.pvdContext.writer);
267
268 PxVehiclePvdCommandResponseWrite(
269 *axleDesc, brakeResponseParams, steerResponseParams, brakeResponseStates, steerResponseStates,
270 *context.pvdContext.attributeHandles, *omniPvdObjectHandles, context.pvdContext.writer);
271
272 PxVehiclePvdWheelAttachmentsWrite(
273 *axleDesc,
274 wheelParams, wheelActuationStates, wheelRigidBody1dStates, wheelLocalPoses,
275 roadGeomStates,
276 suspParams, suspComplianceParams, suspForceParams, suspStates, suspComplianceStates,
277 suspForces,
278 tireForceParams,
279 tireDirectionStates, tireSpeedStates, tireSlipStates, tireStickyStates, tireGripStates, tireCamberStates,
280 tireForces,
281 *context.pvdContext.attributeHandles, *omniPvdObjectHandles, context.pvdContext.writer);
282
283 PxVehiclePvdAntiRollsWrite(
284 antiRollParams, antiRollTorque,
285 *context.pvdContext.attributeHandles, *omniPvdObjectHandles, context.pvdContext.writer);
286
287 PxVehiclePvdDirectDrivetrainWrite(
288 *axleDesc,
289 commandState, directDriveTransmissionState,
290 directDriveThrottleResponseParams,
291 directDrivethrottleResponseState,
292 *context.pvdContext.attributeHandles, *omniPvdObjectHandles, context.pvdContext.writer);
293
294 PxVehiclePvdEngineDrivetrainWrite(
295 commandState, engineDriveTransmissionCommandState,
296 clutchResponseParams, clutchParams, engineParams, gearboxParams, autoboxParams, multiWheelDiffParams, fourWheelDiffParams,
297 clutchResponseState, throttleResponseState, engineState, gearboxState, autoboxState, diffState, clutchSlipState,
298 *context.pvdContext.attributeHandles, *omniPvdObjectHandles, context.pvdContext.writer);
299
300 PxVehiclePvdPhysXWheelAttachmentWrite(
301 *axleDesc,
302 physxConstraintParams, physxMaterialFrictionParams,
303 physxActor, physxRoadGeomQryParams, physxRoadGeomStates, physxConstraintStates,
304 *context.pvdContext.attributeHandles, *omniPvdObjectHandles, context.pvdContext.writer);
305
306 PxVehiclePvdPhysXRigidActorWrite(
307 physxActor,
308 *context.pvdContext.attributeHandles, *omniPvdObjectHandles, context.pvdContext.writer);
309
310 return true;
311 }
312
313private:
314
315 bool firstTime;
316};
317
318#if !PX_DOXYGEN
319} // namespace vehicle2
320} // namespace physx
321#endif
322
Definition base.h:1940
Definition PxVehicleComponent.h:45
Definition PxVehiclePvdComponents.h:51
virtual bool update(const PxReal dt, const PxVehicleSimulationContext &context)
Update function for a vehicle component.
Definition PxVehiclePvdComponents.h:113
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
The purpose of the anti-roll bar is to generate a torque to apply to the vehicle's rigid body that wi...
Definition PxVehicleSuspensionParams.h:347
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
Definition PxVehicleDrivetrainParams.h:404
Definition PxVehicleDrivetrainStates.h:122
Definition PxVehicleParams.h:53
Distribute a brake response to the wheels of a vehicle.
Definition PxVehicleBrakingParams.h:56
Specifies the maximum clutch strength that occurs when the clutch pedal is fully disengaged and the c...
Definition PxVehicleDrivetrainParams.h:84
Definition PxVehicleDrivetrainStates.h:46
The clutch connects two plates together. One plate rotates with the speed of the engine....
Definition PxVehicleDrivetrainParams.h:141
The clutch is modelled as two spinning plates with one connected to the wheels through the gearing an...
Definition PxVehicleDrivetrainStates.h:266
A description of the state of commands that are applied to the vehicle.
Definition PxVehicleCommandStates.h:53
Definition PxVehicleDrivetrainStates.h:143
Distribute a throttle response to the wheels of a direct drive vehicle.
Definition PxVehicleDrivetrainParams.h:57
A description of the state of transmission-related commands that are applied to a vehicle with direct...
Definition PxVehicleCommandStates.h:69
A description of the state of transmission-related commands that are applied to a vehicle with engine...
Definition PxVehicleCommandStates.h:92
Definition PxVehicleDrivetrainParams.h:192
Definition PxVehicleDrivetrainStates.h:67
PxVehicleFourWheelDriveDifferentialParams specifies the wheels that are to receive drive torque from ...
Definition PxVehicleDrivetrainParams.h:672
Definition PxVehicleDrivetrainParams.h:320
Definition PxVehicleDrivetrainStates.h:85
PxVehicleMultiWheelDriveDifferentialParams specifies the wheels that are to receive drive torque from...
Definition PxVehicleDrivetrainParams.h:600
A description of the PhysX actor and shapes that represent the vehicle in an associated PxScene.
Definition PxVehiclePhysXActorStates.h:55
PxVehiclePhysXConstraintState is a data structure used to write constraint data to the internal state...
Definition PxVehiclePhysXConstraintStates.h:76
A mappping between PxMaterial instance and friction for multiple PxMaterial intances.
Definition PxVehiclePhysXRoadGeometryParams.h:142
A description of type of PhysX scene query and the filter data to apply to the query.
Definition PxVehiclePhysXRoadGeometryParams.h:70
Definition PxVehiclePhysXRoadGeometryState.h:51
A description of the PhysX models employed to resolve suspension limit constraints.
Definition PxVehiclePhysXConstraintParams.h:52
Definition VhPvdObjectHandles.h:49
The properties of the rigid body.
Definition PxVehicleRigidBodyParams.h:50
Definition PxVehicleRigidBodyStates.h:47
Definition PxVehicleRoadGeometryState.h:46
Definition PxVehicleParams.h:672
Definition PxVehicleParams.h:369
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